webmcp
view framework/env/parse/currency.lua @ 23:3a6fe8663b26
Code cleanup and documentation added; Year in copyright notice changed to 2009-2010
Details:
- Changed quoting style in auth.openid.xrds_document{...}
- Fixed documentation for auth.openid.initiate{...}
- Added documentation for mondelefant
- Code-cleanup in mondelefant:
-- removed unneccessary lines "rows = PQntuples(res); cols = PQnfields(res);"
-- avoided extra copy of first argument (self) in mondelefant_conn_query
-- no rawget in meta-method "__index" of database result lists and objects
-- removed unreachable "return 0;" in meta-method "__newindex" of database result lists and objects
- Year in copyright notice changed to 2009-2010
- Version string changed to "1.1.1"
Details:
- Changed quoting style in auth.openid.xrds_document{...}
- Fixed documentation for auth.openid.initiate{...}
- Added documentation for mondelefant
- Code-cleanup in mondelefant:
-- removed unneccessary lines "rows = PQntuples(res); cols = PQnfields(res);"
-- avoided extra copy of first argument (self) in mondelefant_conn_query
-- no rawget in meta-method "__index" of database result lists and objects
-- removed unreachable "return 0;" in meta-method "__newindex" of database result lists and objects
- Year in copyright notice changed to 2009-2010
- Version string changed to "1.1.1"
| author | jbe |
|---|---|
| date | Fri Jun 04 19:00:34 2010 +0200 (2010-06-04) |
| parents | 9fdfb27f8e67 |
| children |
line source
1 local function extract_numbers(str)
2 local result = {}
3 for char in string.gmatch(str, "[0-9]") do
4 result[#result+1] = char
5 end
6 return table.concat(result)
7 end
9 function parse.currency(str, dest_type, options)
10 local str = parse._pre_fold(str)
11 local dest_type = dest_type or atom.number
12 local options = options or {}
13 local currency_decimal_point = locale.get("currency_decimal_point")
14 local decimal_point = locale.get("decimal_point") or "."
15 local pos1, pos2
16 if currency_decimal_point then
17 pos1, pos2 = string.find(str, currency_decimal_point, 1, true)
18 end
19 if not pos1 then
20 pos1, pos2 = string.find(str, decimal_point, 1, true)
21 end
22 if pos1 then
23 local p1 = extract_numbers(string.sub(str, 1, pos1 - 1))
24 local p2 = extract_numbers(string.sub(str, pos2 + 1, #str))
25 return parse.decimal(p1 .. decimal_point .. p2, dest_type, options)
26 else
27 return parse.decimal(extract_numbers(str), dest_type, options)
28 end
29 end
