Hi Felix
well the regex commands are a bit too difficult to understand for me. So
I would need some practical help..
So I have the following
a)Key="420 m"
b)Key="420m"
c)Key="420"
d)Key="420ft"
I want it to return number only in Key3, and number plus uni in Key2. I
assume if no unit is given in value, value is "m"
so I would like to end up with
a)Key2=420m and Key3=420
b)Key2=420m and Key3=420
c)Key2=420m and Key3=420
d)Key2=420ft and Key3=128.016
The only supported conversion is m=>ft, I think because our
contours are always in feet, so I am changing the
question to match so it can be tested. We can easily add
the reverse convertion.
The following will work with the given values:
Key=* {
set key2='${Key|subst:"[ \t]*~>" | subst:"(?<=[0-9]+)$~>m"}';
set key3='${Key|subst:"[a-zA-Z \t]+~>"}';
}
key2 ~ '.*m' { set key3='${key3|conv:"m=>ft"}'; }
In words this:
1. First remove all spaces and tabs and set key2
2. if a digit is at the end of key2, append a 'm'
3. remove all letters and spaces from original Key and set as key3
4. if key2 ends in 'm', then apply conversion meters to feet on key3
With the attached StyleTester file, I get the results:
WAY 1: Line 0x2, labels=[key2=420m key3=1378, null, null, null],
res=24-24 (1/1),(2/2),
WAY 2: Line 0x2, labels=[key2=420m key3=1378, null, null, null],
res=24-24 (1/1),(2/2),
WAY 3: Line 0x2, labels=[key2=420m key3=1378, null, null, null],
res=24-24 (1/1),(2/2),
WAY 4: Line 0x2, labels=[key2=420ft key3=420 , null, null, null],
res=24-24 (1/1),(2/2),
Using regular expressions will probably lead to more problems though.
It might fail on other strings we havn't considered for example.
Perhaps a units filter that takes two arguments: a default unit when
none is specified, and the target unit.
..Steve
WAY
Key=420 m
WAY 2
Key=420m
WAY 3
Key=420
WAY 4
Key=420ft
<<<lines>>>
Key=* {
set key2='${Key|subst:"[ \t]*~>" | subst:"(?<=[0-9]+)$~>m"}';
set key3='${Key|subst:"[a-z]+~>"}';
}
key2 ~ '.*m' { set key3='${key3|conv:"m=>ft"}'; }
Key=* [0x2]
<finalize>
Key=* {name 'key2=${key2} key3=${key3}'}
_______________________________________________
mkgmap-dev mailing list
[email protected]
http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev