in-ini: regex clean-up
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sat, 06 Sep 2014 20:07:02 +0200
changeset 841a09966c072c
parent 83 06e866769478
child 85 4f7028b5f2fe
in-ini: regex clean-up
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:56:08 2014 +0200
     1.2 +++ b/java/alt2xml-in-ini/src/cz/frantovo/alt2xml/in/ini/Reader.java	Sat Sep 06 20:07:02 2014 +0200
     1.3 @@ -128,24 +128,19 @@
     1.4  
     1.5  				},
     1.6  		ENTRY(
     1.7 -				"\\s*(?<key>[^=\\s]+)\\s*=\\s*\"(?<value>[^\"]+)\"", // quoted value → include spaces
     1.8 -				"\\s*(?<key>[^=\\s]+)\\s*=\\s*\"(?<value>[^\"]+)\"\\s*(;|#)*\\s*(?<comment>.*)", // quoted value → include spaces | with comment
     1.9 -				"\\s*(?<key>[^=\\s]+)\\s*=\\s*'(?<value>[^']+)'", // apostrophed value → include spaces
    1.10 -				"\\s*(?<key>[^=\\s]+)\\s*=\\s*'(?<value>[^']+)'\\s*((;|#)\\s*(?<comment>.*)){0,1}", // apostrophed value → include spaces | with comment
    1.11 -				"\\s*(?<key>[^=\\s]+)\\s*=\\s*(?<value>.+)" // unquoted value → strip spaces
    1.12 +				"\\s*(?<key>[^=\\s]+)\\s*=\\s*\"(?<value>[^']+)\"\\s*((;|#)\\s*(?<comment>.*)){0,1}", // quoted value → include spaces + might have comment
    1.13 +				"\\s*(?<key>[^=\\s]+)\\s*=\\s*'(?<value>[^']+)'\\s*((;|#)\\s*(?<comment>.*)){0,1}", // apostrophed value → include spaces + might have comment
    1.14 +				"\\s*(?<key>[^=\\s]+)\\s*=\\s*(?<value>.+)" // unquoted value → strip spaces + no comments
    1.15  		) {
    1.16  					@Override
    1.17  					public void processLine(LineContext lc, FileContext fc) throws SAXException {
    1.18  						String key = lc.matcher.group("key");
    1.19  						String value = lc.matcher.group("value");
    1.20  
    1.21 -						try {
    1.22 +						if (lc.matcher.groupCount() > 2) {
    1.23  							String comment = lc.matcher.group("comment");
    1.24  							// TODO: comment → LexicalHandler
    1.25 -							log.log(Level.WARNING, "Comment for entry „{0}“ is: {1}", new Object[]{key, comment});
    1.26 -
    1.27 -						} catch (IllegalArgumentException e) {
    1.28 -							log.log(Level.WARNING, "Entry „{0}“ has no comment", key);
    1.29 +							log.log(Level.FINER, "Comment for entry „{0}“ is: {1}", new Object[]{key, comment});
    1.30  
    1.31  						}
    1.32