Hi all,
I've written a new filter function called trim.
It returns the first part of a value up to the first occurance of a
separator.
If the separator is not found it just returns the value.
Example:
maybe you have a values like this
destination=München;Landsberg;Augsburg;Ammersee
destination=Kaufbeuren;Neugablonz;Mauerstetten;Pforzen
and you want just the first part "München", or "Kaufbeuren"
'${destination|trim:;}'
will do the trick.
with
destination=München/Landsberg/Augsburg/Ammersee
destination=Kaufbeuren/Neugablonz/Mauerstetten/Pforzen
use
'${destination|trim:/}'
Find attached the new TrimFilter.java a diff for ValueBuilder.java
Ciao,
Franco
/*
* Copyright 2009 Toby Speight
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
package uk.me.parabola.mkgmap.osmstyle.actions;
import uk.me.parabola.mkgmap.reader.osm.Element;
/**
* Get first part of a value.up to separator
*
* @author Franco Bez
*/
public class TrimFilter extends ValueFilter {
private final String to;
public TrimFilter(String arg) {
to = arg;
}
public String doFilter(String value, Element el) {
if (value == null) return null;
if (to == null)
return value.trim();
String[] temp = value.split(to);
if (temp.length >= 1)
return temp[0].trim();
return value.trim();
}
}
--- /trunk/src/uk/me/parabola/mkgmap/osmstyle/actions/ValueBuilder.java 2013-04-19 22:39:12.590710850 +0200
+++ /home/franco/ValueBuilder.java 2013-04-19 21:53:48.185201244 +0200
@@ -183,6 +183,8 @@
item.addFilter(new NotEqualFilter(arg));
} else if (cmd.equals("substring")) {
item.addFilter(new SubstringFilter(arg));
+ } else if (cmd.equals("trim")) {
+ item.addFilter(new TrimFilter(arg));
}
}
_______________________________________________
mkgmap-dev mailing list
[email protected]
http://lists.mkgmap.org.uk/mailman/listinfo/mkgmap-dev