# HG changeset patch # User František Kučera # Date 1410038838 -7200 # Node ID 03c1c831cfcb346acab8cc545b0d58f286847a51 # Parent 8146ad99fc67881a3422a8be6935bbdca571d154 in-ini: support sub-keys: key[subkey_1]=value_1 key[subkey_2]=value_2 diff -r 8146ad99fc67 -r 03c1c831cfcb 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 22:04:11 2014 +0200 +++ b/java/alt2xml-in-ini/src/cz/frantovo/alt2xml/in/ini/Reader.java Sat Sep 06 23:27:18 2014 +0200 @@ -31,6 +31,7 @@ import java.util.regex.Pattern; import org.xml.sax.InputSource; import org.xml.sax.SAXException; +import org.xml.sax.helpers.AttributesImpl; /** * @@ -149,23 +150,30 @@ }, ENTRY( - "\\s*(?[^=\\s]+)\\s*=\\s*\"(?[^']+)\"\\s*((;|#)\\s*(?.*)){0,1}", // quoted value → include spaces + might have comment - "\\s*(?[^=\\s]+)\\s*=\\s*'(?[^']+)'\\s*((;|#)\\s*(?.*)){0,1}", // apostrophed value → include spaces + might have comment - "\\s*(?[^=\\s]+)\\s*=\\s*(?.+)" // unquoted value → strip spaces + no comments + "\\s*(?[^=\\s\\]]+)(\\[(?[^\\]]+)\\]){0,1}\\s*=\\s*\"(?[^']+)\"\\s*((;|#)\\s*(?.*)){0,1}", // quoted value → include spaces + might have comment + "\\s*(?[^=\\s\\]]+)(\\[(?[^\\]]+)\\]){0,1}\\s*=\\s*'(?[^']+)'\\s*((;|#)\\s*(?.*)){0,1}", // apostrophed value → include spaces + might have comment + "\\s*(?[^=\\s\\]]+)(\\[(?[^\\]]+)\\]){0,1}\\s*=\\s*(?.+)" // unquoted value → strip spaces + no comments ) { @Override public void processLine(LineContext lc, FileContext fc) throws SAXException { String key = encodeXmlName(lc.matcher.group("key"), fc.lineNumber); String value = lc.matcher.group("value"); - if (lc.matcher.groupCount() > 2) { + if (lc.matcher.groupCount() > 4) { String comment = lc.matcher.group("comment"); // TODO: comment → LexicalHandler log.log(Level.FINER, "Line {0}: comment for entry „{1}“ is: {2}", new Object[]{fc.lineNumber, key, comment}); } + AttributesImpl attributes = null; + String subkey = lc.matcher.group("subkey"); + if (subkey != null) { + attributes = new AttributesImpl(); + attributes.addAttribute(null, "sub", "sub", "xs:string", subkey); + } + fc.contentHandler.indentation(fc.lastSection == null ? 1 : 2); - fc.contentHandler.textElement(value, null, null, key, null); + fc.contentHandler.textElement(value, null, null, key, attributes); fc.contentHandler.lineBreak(); }