Folks, I added some more tweaks to the PartFilter class, beside being able to use negative numbers to take a part from the tail of the value list, it is now possible to use the "<" or ">" operator (in addition to ":") in order to return a concatenation of all the parts before or after a certain part. The default behavior is not changed and this come at the expense of just 2 logical "IF" more when no operators are specified. Attached the class.
Example, if the value is "Aa#Bb#Cc#Dd#Ee"
part:#:1 returns Aa
part:#:-1 returns Ee
part:#:-2 returns Dd
part:#>1 returns Bb#Cc#Dd#Ee#
part:#<5 returns Aa#Bb#Cc#Dd#
part:#<-1 returns Aa#Bb#Cc#Dd#
This can be expecially useful in some circumstances to overcome the
limitation that does not allow to use expressions within expressions, i.e.:
{set foo:bar='${name|part: :1}}' } // take the first word in name
{set name='${name|subst:${foo:bar}}' } // remove it - this would not work
wont' work but now:
{set name='${name|part: >1}}' } // returns all the words after the first one
will do the job. Some more elaborated things like:
// Via Wolfgang Amadeus Mozart -> Mozart, Via Wolfgang Amadeus
{set new:name='${name|part: :-1}}, ${name|part: <-1}}' }
// a_word [Dd]e [Ee]l anything-> a_word, anything [Dd]e [Ee]l
// Calle De el Gato Loco-> Gato Loco, Calle De el
highway=* & name ~ '.*\s[Dd]e [Ee]l .*' {set new:name='${name|part: >3}},
${name|part: <4}}' }
On Wed, Aug 7, 2013 at 1:06 AM, Enrico Liboni <[email protected]> wrote:
> It might be useful to be able to get the last part of a value list but the
> current implementation of PartFilter does not allow this, i.e. you can get
> the 1st, 2nd, 3rd and so on but you can't get the last, the one before the
> last and so on.
>
> The change is trivial, in doFilter replace:
>
> if (temp.length >= partnumber)
> return temp[partnumber-1].trim();
> with:
> if (temp.length >= Math.abs(partnumber) ) {
> if (partnumber > 0) {
> return temp[partnumber-1].trim();
> } else {
> return temp[temp.length+partnumber].trim();
> }
> }
>
> attached the new class which I compiled, plugged in r2661 and works as
> expected.
>
> This could be useful for example, emh..., when adding a rule like:
>
> highway=* { set street:name='${name|part: :-1}, ${name}'}
> street:name=* {set name='${street:name}'}
>
> so that the most meaningful part of a street name in some countries
> appears at the beginning of the name thus facilitating the address search ;)
>
> Let me know if you believe this is useful and if you prefer a patch.
>
> Enrico
>
>
>
PartFilter.java
Description: Binary data
_______________________________________________ mkgmap-dev mailing list [email protected] http://lists.mkgmap.org.uk/mailman/listinfo/mkgmap-dev
