webmcp
view framework/env/parse/currency.lua @ 2:72860d232f32
Version 1.0.2
Fixed bug with explicit garbage collection (requests > 256kB caused an error)
Views prefixed with an underscore can't be called externally
ui.paginate now displays the last page, if the selected page number is too high.
Fixed bug with explicit garbage collection (requests > 256kB caused an error)
Views prefixed with an underscore can't be called externally
ui.paginate now displays the last page, if the selected page number is too high.
| author | jbe/bsw | 
|---|---|
| date | Thu Dec 10 12:00:00 2009 +0100 (2009-12-10) | 
| 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
