Skip to content

Commit 7edd2e3

Browse files
Famlamfrodrigo
authored andcommitted
Implement numerical to_* functions for mapcss
Neglecting the precision, since Python doesn't really differentiate between short/int/long or float/double. Note that JOSM throws an exception rather than None (null) when conversion is impossible.
1 parent 19fb532 commit 7edd2e3

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

mapcss/mapcss_lib.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,18 +585,43 @@ def tag_regex(tags, regex):
585585

586586
#to_short(str)
587587
# returns the string argument as a short [since r16110]
588+
def to_short(string):
589+
try:
590+
return int(string)
591+
except:
592+
return None
588593

589594
#to_int(str)
590595
# returns the string argument as a int [since r16110]
596+
def to_int(string):
597+
try:
598+
return int(string)
599+
except:
600+
return None
591601

592602
#to_long(str)
593603
# returns the string argument as a long [since r16110]
604+
def to_long(string):
605+
try:
606+
return int(string)
607+
except:
608+
return None
594609

595610
#to_float(str)
596611
# returns the string argument as a float [since r16110]
612+
def to_float(string):
613+
try:
614+
return float(string)
615+
except:
616+
return None
597617

598618
#to_double(str)
599619
# returns the string argument as a double [since r16110]
620+
def to_double(string):
621+
try:
622+
return float(string)
623+
except:
624+
return None
600625

601626
#uniq(str1, str2, str3, ...)
602627
# returns a list of strings that only have unique values from an array of strings [since r15323]

0 commit comments

Comments
 (0)