jbe/bsw@0: local function extract_numbers(str) jbe/bsw@0: local result = {} jbe/bsw@0: for char in string.gmatch(str, "[0-9]") do jbe/bsw@0: result[#result+1] = char jbe/bsw@0: end jbe/bsw@0: return table.concat(result) jbe/bsw@0: end jbe/bsw@0: jbe/bsw@0: function parse.currency(str, dest_type, options) jbe/bsw@0: local str = parse._pre_fold(str) jbe/bsw@0: local dest_type = dest_type or atom.number jbe/bsw@0: local options = options or {} jbe/bsw@0: local currency_decimal_point = locale.get("currency_decimal_point") jbe/bsw@0: local decimal_point = locale.get("decimal_point") or "." jbe/bsw@0: local pos1, pos2 jbe/bsw@0: if currency_decimal_point then jbe/bsw@0: pos1, pos2 = string.find(str, currency_decimal_point, 1, true) jbe/bsw@0: end jbe/bsw@0: if not pos1 then jbe/bsw@0: pos1, pos2 = string.find(str, decimal_point, 1, true) jbe/bsw@0: end jbe/bsw@0: if pos1 then jbe/bsw@0: local p1 = extract_numbers(string.sub(str, 1, pos1 - 1)) jbe/bsw@0: local p2 = extract_numbers(string.sub(str, pos2 + 1, #str)) jbe/bsw@0: return parse.decimal(p1 .. decimal_point .. p2, dest_type, options) jbe/bsw@0: else jbe/bsw@0: return parse.decimal(extract_numbers(str), dest_type, options) jbe/bsw@0: end jbe/bsw@0: end