|Hi all,

thanks for the feedback.

I've chosen to rename the filter to "part"
As this is what it does, it returns only a part of the value.

I gave it 2 optional arguments, a separator and a partnumber

the separator defaults to semicolon, the partnumber to 1

so ${destination|part} will return the first part of a list separated by
semicolons, "München;Augsburg" will become "München".

and $(ref|part:-:5} will return "B12" on "A96-E143-A30-B17-B12-A45"

a patched binary is here:
http://files.mkgmap.org.uk/download/111/mkgmap.jar

attached is the PartFilter.java and the diff for ValueBuilder.java and
rule-filters.txt



|
diff -u -r trunk/src/uk/me/parabola/mkgmap/osmstyle/actions/ValueBuilder.java franco/src/uk/me/parabola/mkgmap/osmstyle/actions/ValueBuilder.java
--- trunk/src/uk/me/parabola/mkgmap/osmstyle/actions/ValueBuilder.java	2013-04-20 16:01:44.057720271 +0200
+++ franco/src/uk/me/parabola/mkgmap/osmstyle/actions/ValueBuilder.java	2013-04-20 14:54:14.000000000 +0200
@@ -183,6 +183,8 @@
 			item.addFilter(new NotEqualFilter(arg));
 		} else if (cmd.equals("substring")) {
 			item.addFilter(new SubstringFilter(arg));
+		} else if (cmd.equals("part")) {
+			item.addFilter(new PartFilter(arg));
 		}
 	}
 
diff -u -r trunk/doc/styles/rules-filters.txt franco/doc/styles/rules-filters.txt
--- trunk/doc/styles/rules-filters.txt	2013-03-08 07:15:56.587162656 +0100
+++ franco/doc/styles/rules-filters.txt	2013-04-20 15:57:15.428388216 +0200
@@ -28,6 +28,27 @@
 
 `${name\|ref:A=>}`
 
+| part | `separator partnumber` |
+Retrieves a part of a value list.
+
+The value is cut into parts at every occurance of the +separator+ (default +;+)
+
+The the desired part of the value is returned (default +partnumber+ is +1+)
+
+Especially useful for tags like ref, exit_to and destination.
+
+`${name\|part}`
+
+returns "Munich" if name="Munich;Augsburg;Landsberg"
+
+`${name\|part:#}`
+
+returns "Munich" if name="Munich#Augsburg#Landsberg"
+
+`${name\|part:/:2}`
+
+returns "Augsburg" if name="Munich/Augsburg/Landsberg"
+
 | highway-symbol | `symbol max-num max-alpha` |
 Prepares the value as a highway reference such as "A21" "I-80" and so
 on.
/*
 * Copyright 2013 Franco Bez
 *
 *  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.imgfmt.ExitException;
import uk.me.parabola.mkgmap.reader.osm.Element;

/**
 * Get a part of a value.
 * value is split at a separator that defaults to semicolon ';'
 * by default the first part is returned
 * if the optional second parameter 'partnumber' is bigger 
 * than the number of parts in the value then null is returned
 *
 * @author Franco Bez
 */
public class PartFilter extends ValueFilter {
	private final String separator;
	private int partnumber;

	public PartFilter(String arg) {
		String[] temp = arg.split(":");
		partnumber = 1;
		try {
			switch (temp.length ) {
				case '2':
					partnumber = Integer.parseInt(temp[1]);
					// no break by intention
				case '1':
					separator = temp[0];
					break;
				default:
					separator = ";";
			}
		} catch (NumberFormatException e) {
			throw new ExitException("Not valid numbers in style part command: " + arg);
		}
	}

	public String doFilter(String value, Element el) {
		if (value == null) return null;
		String[] temp = value.split(separator);
		if (temp.length >= partnumber)
			return temp[partnumber-1].trim();
		return null;
	}
}
_______________________________________________
mkgmap-dev mailing list
[email protected]
http://lists.mkgmap.org.uk/mailman/listinfo/mkgmap-dev

Reply via email to