in-ini: comments
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sun, 07 Sep 2014 00:01:49 +0200
changeset 95c03497563ce3
parent 94 f5b287fa69b6
child 96 9ca02f0f6751
in-ini: 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 23:44:26 2014 +0200
     1.2 +++ b/java/alt2xml-in-ini/src/cz/frantovo/alt2xml/in/ini/Reader.java	Sun Sep 07 00:01:49 2014 +0200
     1.3 @@ -34,6 +34,30 @@
     1.4  import org.xml.sax.helpers.AttributesImpl;
     1.5  
     1.6  /**
     1.7 + * Reads INI files with sections and entries.
     1.8 + * Example:
     1.9 + * <pre>; this is comment
    1.10 + *random=value outside of any groups
    1.11 + *
    1.12 + *[some_section]
    1.13 + *
    1.14 + *; simple entry:
    1.15 + *key=value
    1.16 + *
    1.17 + *; entry starting/ending with whitespace
    1.18 + *white="  spaces everywhere  " ; might have comment
    1.19 + *alternative='  spaces everywhere  ' ; same
    1.20 + *
    1.21 + *; entries with subkeys:
    1.22 + *key[subkey_a]=value
    1.23 + *key[subkey_b]=value
    1.24 + *
    1.25 + *# alternative way to comment
    1.26 + *
    1.27 + *[another secion]
    1.28 + *yes=there might be spaces in names
    1.29 + *because=they are encoded before putting into XML element names
    1.30 + * </pre>
    1.31   *
    1.32   * @author Ing. František Kučera (frantovo.cz)
    1.33   */
    1.34 @@ -139,7 +163,7 @@
    1.35  					}
    1.36  
    1.37  				},
    1.38 -		SECTION("\\s*\\[\\s*(?<name>[^\\]\\]]+)\\s*\\]\\s*") {
    1.39 +		SECTION("\\s*\\[\\s*(?<name>[^\\]]+)\\s*\\]\\s*") {
    1.40  					@Override
    1.41  					public void processLine(LineContext lc, FileContext fc) throws SAXException {
    1.42  						String name = encodeXmlName(lc.matcher.group("name"), fc.lineNumber);
    1.43 @@ -180,6 +204,9 @@
    1.44  
    1.45  				},;
    1.46  
    1.47 +		/**
    1.48 +		 * @param patterns regular expression (or expressions) that describes this line type
    1.49 +		 */
    1.50  		private LINE_TYPE(String... patterns) {
    1.51  			for (String pattern : patterns) {
    1.52  				this.patterns.add(Pattern.compile(pattern));
    1.53 @@ -188,6 +215,13 @@
    1.54  
    1.55  		private final List<Pattern> patterns = new ArrayList<>();
    1.56  
    1.57 +		/**
    1.58 +		 *
    1.59 +		 * @param currentLine input line to be parsed
    1.60 +		 * @param fc
    1.61 +		 * @return whether line matches and was thus processed
    1.62 +		 * @throws SAXException
    1.63 +		 */
    1.64  		protected boolean processLine(String currentLine, FileContext fc) throws SAXException {
    1.65  			for (Pattern pattern : patterns) {
    1.66  				Matcher m = pattern.matcher(currentLine);
    1.67 @@ -202,5 +236,4 @@
    1.68  
    1.69  		public abstract void processLine(LineContext lc, FileContext fc) throws SAXException;
    1.70  	}
    1.71 -
    1.72  }