Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2015-05-09 20:42:09 +02:00
commit efd054225f

View file

@ -187,15 +187,63 @@ public class RouteDataObject {
} }
public static float parseLength(String v, float def) { public static float parseLength(String v, float def) {
// 14"10' not supported // Supported formats:
// 10 m
// 10m
// 14'10"
// 14.5'
// 15ft
// Even values with any more characters after these formats are rejected, e.g. (14'10"x) or (10 metres).
int i = Algorithms.findFirstNumberEndIndex(v); int i = Algorithms.findFirstNumberEndIndex(v);
if (i > 0) { if (i > 0) {
float f = Float.parseFloat(v.substring(0, i)); float f = Float.parseFloat(v.substring(0, i));
if (v.contains("\"") || v.contains("ft")) { if (i == v.Length()) {
// foot to meters // Value with no unit means meters. Done.
f *= 0.3048; return f;
} else {
if (v.charAt(i) == " ") {
i++;
}
if (v.charAt(i) == "m") {
// Meters, no conversion needed, done.
if (i == v.Length()) {
return f;
} else {
return def;
}
}
if (v.charAt(i) == "'") {
// Convert feet to meters.
f *= 0.3048;
i++;
} else if (v.charAt(i) == "f" && i < v.Length() && v.charAt(i+1) != "t") {
// 'ft' is a discouraged unit per the wiki, but we know what it means.
// Convert feet to meters.
f *= 0.3048;
// When 'ft' is used, no inches are expected.
if (i == v.Length()) {
return f;
} else {
return def;
}
}
if (i < v.Length()) {
String w = v.substring(i);
int j = Algorithms.findFirstNumberEndIndex(w);
if (j > 0 && w.charAt(0) == "\"") {
float g = Float.parseFloat(w.substring(0, j))
// Convert inches to meters.
f += g * 0.0254;
if (i + j == v.Length()) {
return f;
} else {
return def;
}
}
} else {
return f;
}
} }
return f;
} }
return def; return def;
} }
@ -372,4 +420,4 @@ public class RouteDataObject {
String rf = getRef(); String rf = getRef();
return MessageFormat.format("Road id {0} name {1} ref {2}", getId()+"", name == null ? "" : name, rf == null ? "" : rf); return MessageFormat.format("Road id {0} name {1} ref {2}", getId()+"", name == null ? "" : name, rf == null ? "" : rf);
} }
} }