use of uk.me.parabola.mkgmap.scan.TokenScanner in project mkgmap by openstreetmap.
the class OverlayReader method readOverlays.
public void readOverlays() {
TokenScanner ts = new TokenScanner(filename, reader);
while (!ts.isEndOfFile()) {
String line = ts.readLine();
// Remove comments before parsing
int commentstart = line.indexOf("#");
if (commentstart != -1)
line = line.substring(0, commentstart);
String[] fields = line.split(":", 2);
if (fields.length == 2) {
try {
overlays.put(Integer.decode(fields[0]), readReplacements(ts, fields[1]));
} catch (NumberFormatException e) {
throw new SyntaxException(ts, "Expecting a number");
}
}
}
}
use of uk.me.parabola.mkgmap.scan.TokenScanner in project mkgmap by openstreetmap.
the class PrefixSuffixFilter method readOptionFile.
/**
* @param r
* @param filename
*/
private void readOptionFile(Reader r, String filename) {
BufferedReader br = new BufferedReader(r);
TokenScanner ts = new TokenScanner(filename, br);
ts.setExtraWordChars(":");
while (!ts.isEndOfFile()) {
Token tok = ts.nextToken();
if (tok.isValue("#")) {
ts.skipLine();
continue;
}
String key = tok.getValue();
ts.skipSpace();
tok = ts.peekToken();
if (tok.getType() == TokType.SYMBOL) {
String punc = ts.nextValue();
String val;
if (punc.equals(":") || punc.equals("=")) {
val = ts.readLine();
} else {
ts.skipLine();
continue;
}
processOption(key, val);
} else if (key != null) {
throw new IllegalArgumentException("don't understand line with " + key);
} else {
ts.skipLine();
}
}
/**
* process lines starting with prefix1 or prefix2.
*/
for (String lang : languages) {
String prefix1 = options.getProperty("prefix1:" + lang, null);
if (prefix1 == null)
continue;
String prefix2 = options.getProperty("prefix2:" + lang, null);
List<String> p1 = prefix1 != null ? Arrays.asList(prefix1.split(",")) : Collections.emptyList();
List<String> p2 = prefix2 != null ? Arrays.asList(prefix2.split(",")) : Collections.emptyList();
langPrefixMap.put(lang, genPrefix(p1, p2));
}
}
Aggregations