# HG changeset patch # User František Kučera <franta-hg@frantovo.cz> # Date 1410040909 -7200 # Node ID c03497563ce3cef6e07408988fc86ad6c4a24b12 # Parent f5b287fa69b6d60e3d2195a22b93b0d3f0197e1a in-ini: comments diff -r f5b287fa69b6 -r c03497563ce3 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 23:44:26 2014 +0200 +++ b/java/alt2xml-in-ini/src/cz/frantovo/alt2xml/in/ini/Reader.java Sun Sep 07 00:01:49 2014 +0200 @@ -34,6 +34,30 @@ import org.xml.sax.helpers.AttributesImpl; /** + * Reads INI files with sections and entries. + * Example: + * <pre>; this is comment + *random=value outside of any groups + * + *[some_section] + * + *; simple entry: + *key=value + * + *; entry starting/ending with whitespace + *white=" spaces everywhere " ; might have comment + *alternative=' spaces everywhere ' ; same + * + *; entries with subkeys: + *key[subkey_a]=value + *key[subkey_b]=value + * + *# alternative way to comment + * + *[another secion] + *yes=there might be spaces in names + *because=they are encoded before putting into XML element names + * </pre> * * @author Ing. František Kučera (frantovo.cz) */ @@ -139,7 +163,7 @@ } }, - SECTION("\\s*\\[\\s*(?<name>[^\\]\\]]+)\\s*\\]\\s*") { + SECTION("\\s*\\[\\s*(?<name>[^\\]]+)\\s*\\]\\s*") { @Override public void processLine(LineContext lc, FileContext fc) throws SAXException { String name = encodeXmlName(lc.matcher.group("name"), fc.lineNumber); @@ -180,6 +204,9 @@ },; + /** + * @param patterns regular expression (or expressions) that describes this line type + */ private LINE_TYPE(String... patterns) { for (String pattern : patterns) { this.patterns.add(Pattern.compile(pattern)); @@ -188,6 +215,13 @@ private final List<Pattern> patterns = new ArrayList<>(); + /** + * + * @param currentLine input line to be parsed + * @param fc + * @return whether line matches and was thus processed + * @throws SAXException + */ protected boolean processLine(String currentLine, FileContext fc) throws SAXException { for (Pattern pattern : patterns) { Matcher m = pattern.matcher(currentLine); @@ -202,5 +236,4 @@ public abstract void processLine(LineContext lc, FileContext fc) throws SAXException; } - }