Fix #4290. You can now format custom thousands separators and decimal separators in IfcCSV.

This commit is contained in:
Dion Moult
2024-04-10 17:32:39 +10:00
parent 0a04b88a52
commit de744dddda
4 changed files with 21 additions and 3 deletions
@@ -129,9 +129,10 @@ get_element_grammar = lark.Lark(
format_grammar = lark.Lark(
"""start: function
function: round | format_length | lower | upper | title | concat | substr | ESCAPED_STRING | NUMBER
function: round | number | format_length | lower | upper | title | concat | substr | ESCAPED_STRING | NUMBER
round: "round(" function "," NUMBER ")"
number: "number(" function ["," ESCAPED_STRING ["," ESCAPED_STRING]] ")"
format_length: metric_length | imperial_length
metric_length: "metric_length(" function "," NUMBER "," NUMBER ")"
imperial_length: "imperial_length(" function "," NUMBER ["," ESCAPED_STRING "," ESCAPED_STRING] ")"
@@ -212,6 +213,15 @@ class FormatTransformer(lark.Transformer):
return str(int(result))
return str(result)
def number(self, args):
if isinstance(args[0], str):
args[0] = float(args[0]) if "." in args[0] else int(args[0])
if len(args) >= 3 and args[2]:
return "{:,}".format(args[0]).replace(".", "*").replace(",", args[2]).replace("*", args[1])
elif len(args) >= 2 and args[1]:
return "{}".format(args[0]).replace(".", args[1])
return "{:,}".format(args[0])
def format_length(self, args):
return args[0]