# HG changeset patch # User František Kučera # Date 1410023452 -7200 # Node ID a4335757acf1a39bba028053c1a6a473c9bc7613 # Parent c5816dd82cbb69a42b920ee54531ce5526488e8e in-ini: quoted/apostrophed values → include spaces (unquoted → strip spaces) diff -r c5816dd82cbb -r a4335757acf1 java/alt2xml-in-ini/src/cz/frantovo/alt2xml/in/ini/Reader.java --- a/java/alt2xml-in-ini/src/cz/frantovo/alt2xml/in/ini/Reader.java Sat Sep 06 18:53:33 2014 +0200 +++ b/java/alt2xml-in-ini/src/cz/frantovo/alt2xml/in/ini/Reader.java Sat Sep 06 19:10:52 2014 +0200 @@ -22,6 +22,8 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Matcher; @@ -98,11 +100,9 @@ private static class LineContext { - private final String line; private final Matcher matcher; - public LineContext(String line, Matcher matcher) { - this.line = line; + public LineContext(Matcher matcher) { this.matcher = matcher; } } @@ -110,7 +110,6 @@ private enum LINE_TYPE { COMMENT("\\s*(;|#)\\s*(.*)") { - @Override public void processLine(LineContext lc, FileContext fc) throws SAXException { log.log(Level.FINER, "Comment: {0}", lc.matcher.group(2)); @@ -118,7 +117,6 @@ }, SECTION("\\s*\\[\\s*([^\\s\\]]+)\\s*\\]\\s*") { - @Override public void processLine(LineContext lc, FileContext fc) throws SAXException { String name = lc.matcher.group(1); @@ -128,8 +126,11 @@ } }, - ENTRY("\\s*([^=\\s]+)\\s*=\\s*(.+)") { - + ENTRY( + "\\s*([^=\\s]+)\\s*=\\s*\"([^\"]+)\"", // quoted value → include spaces + "\\s*([^=\\s]+)\\s*=\\s*'([^']+)'", // apostrophed value → include spaces + "\\s*([^=\\s]+)\\s*=\\s*(.+)" // unquoted value → strip spaces + ) { @Override public void processLine(LineContext lc, FileContext fc) throws SAXException { String key = lc.matcher.group(1); @@ -143,20 +144,23 @@ },; - private LINE_TYPE(String pattern) { - this.pattern = Pattern.compile(pattern); + private LINE_TYPE(String... patterns) { + for (String pattern : patterns) { + this.patterns.add(Pattern.compile(pattern)); + } } - private final Pattern pattern; + private final List patterns = new ArrayList<>(); protected boolean processLine(String currentLine, FileContext fileContext) throws SAXException { - Matcher m = pattern.matcher(currentLine); - if (m.matches()) { - processLine(new LineContext(currentLine, m), fileContext); - return true; - } else { - return false; + for (Pattern pattern : patterns) { + Matcher m = pattern.matcher(currentLine); + if (m.matches()) { + processLine(new LineContext(m), fileContext); + return true; + } } + return false; } public abstract void processLine(LineContext lc, FileContext fc) throws SAXException;