Changeset 6737 in josm


Ignore:
Timestamp:
2014-01-19T18:06:39+01:00 (11 years ago)
Author:
simon04
Message:

fix #8071 - MapCSS: skip null values in concat(), provide join(separator, value1, ..., valueN)

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java

    r6677 r6737  
    240240        /**
    241241         * Assembles the strings to one.
     242         * @see Utils#join
    242243         */
    243244        @NullableArguments
    244245        public static String concat(Object... args) {
    245             StringBuilder res = new StringBuilder();
    246             for (Object f : args) {
    247                 res.append(String.valueOf(f));
    248             }
    249             return res.toString();
     246            return Utils.join("", Arrays.asList(args));
     247        }
     248
     249        /**
     250         * Assembles the strings to one, where the first entry is used as separator.
     251         * @see Utils#join
     252         */
     253        @NullableArguments
     254        public static String join(String... args) {
     255            return Utils.join(args[0], Arrays.asList(args).subList(1, args.length));
    250256        }
    251257
  • trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParserTest.groovy

    r6736 r6737  
    199199        assert mc.getCascade(Environment.DEFAULT_LAYER).get("width") == 15
    200200    }
     201
     202    @Test
     203    public void testTicket80711() throws Exception {
     204        def sheet = new MapCSSStyleSource("")
     205        getParser("*[rcn_ref], *[name] {text: concat(tag(rcn_ref), \" \", tag(name)); }").sheet(sheet)
     206        def mc = new MultiCascade()
     207        sheet.apply(mc, TestUtils.createPrimitive("way name=Foo"), 20, null, false)
     208        assert mc.getCascade(Environment.DEFAULT_LAYER).get("text") == " Foo"
     209        sheet.apply(mc, TestUtils.createPrimitive("way rcn_ref=15"), 20, null, false)
     210        assert mc.getCascade(Environment.DEFAULT_LAYER).get("text") == "15 "
     211        sheet.apply(mc, TestUtils.createPrimitive("way rcn_ref=15 name=Foo"), 20, null, false)
     212        assert mc.getCascade(Environment.DEFAULT_LAYER).get("text") == "15 Foo"
     213
     214        sheet = new MapCSSStyleSource("")
     215        getParser("*[rcn_ref], *[name] {text: join(\" - \", tag(rcn_ref), tag(ref), tag(name)); }").sheet(sheet)
     216        sheet.apply(mc, TestUtils.createPrimitive("way rcn_ref=15 ref=1.5 name=Foo"), 20, null, false)
     217        assert mc.getCascade(Environment.DEFAULT_LAYER).get("text") == "15 - 1.5 - Foo"
     218    }
    201219}
Note: See TracChangeset for help on using the changeset viewer.