Skip to content

Commit

Permalink
Implement trim_list function
Browse files Browse the repository at this point in the history
Also ensure all list functions always return lists, not sets
  • Loading branch information
Famlam authored and frodrigo committed Sep 14, 2024
1 parent aca1632 commit 7768231
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion mapcss/mapcss_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,12 @@ def trim(string):
if string is not None:
return str_value(string.strip())

#trim_list(list_name)
# remove leading and trailing whitespace from a list of strings, will remove entries that are empty afterwards [since r15591]
def trim_list(l):
if l is not None and isinstance(l, list):
return list(filter(None, map(lambda s: s.strip(), l)))

#JOSM_search("...")
# true, if JOSM search applies to the object
def JOSM_search(string):
Expand Down Expand Up @@ -630,7 +636,7 @@ def to_double(string):
#uniq_list()
# returns a list of strings that only have unique values from a list of strings [since r15353]
def uniq_list(l):
return set(l)
return list(set(l))

# siunit_length(str)
# convert length units to meter (fault tolerant, ignoring white space)
Expand Down
9 changes: 9 additions & 0 deletions plugins/tests/test_mapcss_parsing_evaluation.validator.mapcss
Original file line number Diff line number Diff line change
Expand Up @@ -639,3 +639,12 @@ node[x][inside("FR")][outside("FX")] {
-osmoseAssertMatchWithContext:list("node x=1", "inside=FR-GF");
-osmoseAssertNoMatchWithContext:list("node x=1", "inside=FR-02");
}


node[x][join_list("-", trim_list(split(";", tag("x")))) = "a-b-c"] {
throwWarning: "test";
assertMatch: "node x=a;b;c";
assertMatch: "node x=;a;;b;;c;";
assertMatch: "node x=\"a; b; ; c\"";
assertNoMatch: "node x=a;b;0;c";
}

0 comments on commit 7768231

Please sign in to comment.