in-ini: quoted/apostrophed values might have comments
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sat, 06 Sep 2014 19:36:22 +0200
changeset 82547f1246fe35
parent 81 a4335757acf1
child 83 06e866769478
in-ini: quoted/apostrophed values might have comments
java/alt2xml-in-ini/src/cz/frantovo/alt2xml/in/ini/Reader.java
     1.1 --- a/java/alt2xml-in-ini/src/cz/frantovo/alt2xml/in/ini/Reader.java	Sat Sep 06 19:10:52 2014 +0200
     1.2 +++ b/java/alt2xml-in-ini/src/cz/frantovo/alt2xml/in/ini/Reader.java	Sat Sep 06 19:36:22 2014 +0200
     1.3 @@ -112,6 +112,7 @@
     1.4  		COMMENT("\\s*(;|#)\\s*(.*)") {
     1.5  					@Override
     1.6  					public void processLine(LineContext lc, FileContext fc) throws SAXException {
     1.7 +						// TODO: comment → LexicalHandler
     1.8  						log.log(Level.FINER, "Comment: {0}", lc.matcher.group(2));
     1.9  					}
    1.10  
    1.11 @@ -128,7 +129,9 @@
    1.12  				},
    1.13  		ENTRY(
    1.14  				"\\s*([^=\\s]+)\\s*=\\s*\"([^\"]+)\"", // quoted value → include spaces
    1.15 -				"\\s*([^=\\s]+)\\s*=\\s*'([^']+)'", // apostrophed value → include spaces
    1.16 +				"\\s*([^=\\s]+)\\s*=\\s*\"([^\"]+)\"\\s*(;|#)*\\s*(.*)", // quoted value → include spaces | with comment
    1.17 +				"\\s*([^=\\s]+)\\s*=\\s*'([^']+)'", // apostrophed value → include spaces | with comment
    1.18 +				"\\s*([^=\\s]+)\\s*=\\s*'([^']+)'\\s*(;|#)*\\s*(.*)", // apostrophed value → include spaces
    1.19  				"\\s*([^=\\s]+)\\s*=\\s*(.+)" // unquoted value → strip spaces
    1.20  		) {
    1.21  					@Override
    1.22 @@ -136,6 +139,12 @@
    1.23  						String key = lc.matcher.group(1);
    1.24  						String value = lc.matcher.group(2);
    1.25  
    1.26 +						if (lc.matcher.groupCount() == 4) {
    1.27 +							String comment = lc.matcher.group(4);
    1.28 +							// TODO: comment → LexicalHandler
    1.29 +							log.log(Level.WARNING, "Comment for entry „{0}“ is: {1}", new Object[]{key, comment});
    1.30 +						}
    1.31 +
    1.32  						fc.contentHandler.indentation(2);
    1.33  						fc.contentHandler.textElement(value, null, null, key, null);
    1.34  						fc.contentHandler.lineBreak();
    1.35 @@ -156,6 +165,7 @@
    1.36  			for (Pattern pattern : patterns) {
    1.37  				Matcher m = pattern.matcher(currentLine);
    1.38  				if (m.matches()) {
    1.39 +					log.log(Level.FINEST, "Line „{0}“ matches pattern „{1}“", new Object[]{currentLine, pattern});
    1.40  					processLine(new LineContext(m), fileContext);
    1.41  					return true;
    1.42  				}