jodd-props/src/main/java/jodd/props/PropsParser.java
public void parse(final String in) {
		ParseState state = ParseState.TEXT;
		ParseState stateOnEscape = null;

		boolean insideSection = false;
		String currentSection = null;
		String key = null;
		Operator operator = Operator.ASSIGN;
		final StringBuilder sb = new StringBuilder();

		final int len = in.length();
		int ndx = 0;
		while (ndx < len) {
			final char c = in.charAt(ndx);
			ndx++;

			if (state == ParseState.COMMENT) {
				// comment, skip to the end of the line
				if (c == '\r') {
					if ((ndx < len) && (in.charAt(ndx) == '\n')) {
						ndx++;
					}
					state = ParseState.TEXT;
				}
				else if (c == '\n') {
					state = ParseState.TEXT;
				}
			} else if (state == ParseState.ESCAPE) {
				state = stateOnEscape;  //ParseState.VALUE;
				switch (c) {
					case '\r':
						if ((ndx < len) && (in.charAt(ndx) == '\n')) {
							ndx++;
						}
					case '\n':
						// need to go 1 step back in order to escape
						// the current line ending in the follow-up state
						ndx--;
						state = ParseState.ESCAPE_NEWLINE;
						break;
					// encode UTF character
					case 'u':
						int value = 0;

						for (int i = 0; i < 4; i++) {
							final char hexChar = in.charAt(ndx++);
							if (CharUtil.isDigit(hexChar)) {
								value = (value << 4) + hexChar - '0';
							} else if (hexChar >= 'a' && hexChar <= 'f') {
								value = (value << 4) + 10 + hexChar - 'a';
							} else if (hexChar >= 'A' && hexChar <= 'F') {
								value = (value << 4) + 10 + hexChar - 'A';
							} else {
								throw new IllegalArgumentException("Malformed \\uXXXX encoding.");
							}
						}
						sb.append((char) value);
						break;
					case 't':
						sb.append('\t');
						break;
					case 'n':
						sb.append('\n');
						break;
					case 'r':
						sb.append('\r');
						break;
					case 'f':
						sb.append('\f');
						break;
					default:
						sb.append(c);
				}
			} else if (state == ParseState.TEXT) {
				switch (c) {
					case '\\':
						// escape char, take the next char as is
						stateOnEscape = state;
						state = ParseState.ESCAPE;
						break;

					// start section
					case '[':
						if (sb.length() > 0) {
							if (StringUtil.isNotBlank(sb)) {
								sb.append(c);
								// previous string is not blank, hence it's not the section
								break;
							}
						}
						sb.setLength(0);
						insideSection = true;
						break;

					// end section
					case ']':
						if (insideSection) {
							currentSection = sb.toString().trim();
							sb.setLength(0);
							insideSection = false;
							if (currentSection.length() == 0) {
								currentSection = null;
							}
						} else {
							sb.append(c);
						}
						break;

					case '#':
					case ';':
						state = ParseState.COMMENT;
						break;

					// copy operator
					case '<':
						if (ndx == len || in.charAt(ndx) != '=') {
							sb.append(c);
							break;
						}
						operator = Operator.COPY;
						//ndx++;
						continue;

					// assignment operator
					case '+':
						if (ndx == len || in.charAt(ndx) != '=') {
							sb.append(c);
							break;
						}
						operator = Operator.QUICK_APPEND;
						//ndx++;
						continue;
					case '=':
					case ':':
						if (key == null) {
							key = sb.toString().trim();
							sb.setLength(0);
						} else {
							sb.append(c);
						}
						state = ParseState.VALUE;
						break;

					case '\r':
					case '\n':
						add(currentSection, key, sb, true, operator);
						sb.setLength(0);
						key = null;
						operator = Operator.ASSIGN;
						break;

					case ' ':
					case '\t':
						// ignore whitespaces
						break;
					default:
						sb.append(c);
				}
			} else {
				switch (c) {
					case '\\':
						// escape char, take the next char as is
						stateOnEscape = state;
						state = ParseState.ESCAPE;
						break;

					case '\r':
						if ((ndx < len) && (in.charAt(ndx) == '\n')) {
							ndx++;
						}
					case '\n':
						if (state == ParseState.ESCAPE_NEWLINE) {
							sb.append(escapeNewLineValue);
							if (!ignorePrefixWhitespacesOnNewLine) {
								state = ParseState.VALUE;
							}
						} else {
							add(currentSection, key, sb, true, operator);
							sb.setLength(0);
							key = null;
							operator = Operator.ASSIGN;

							// end of value, continue to text
							state = ParseState.TEXT;
						}
						break;

					case ' ':
					case '\t':
						if (state == ParseState.ESCAPE_NEWLINE) {
							break;
						}
					default:
						sb.append(c);
						state = ParseState.VALUE;

						if (multilineValues) {
							if (sb.length() == 3) {

								// check for ''' beginning
								if (sb.toString().equals("'''")) {
									sb.setLength(0);
									int endIndex = in.indexOf("'''", ndx);
									if (endIndex == -1) {
										endIndex = in.length();
									}
									sb.append(in, ndx, endIndex);

									// append
									add(currentSection, key, sb, false, operator);
									sb.setLength(0);
									key = null;
									operator = Operator.ASSIGN;

									// end of value, continue to text
									state = ParseState.TEXT;
									ndx = endIndex + 3;
								}
							}
						}
				}
			}
		}

		if (key != null) {
			add(currentSection, key, sb, true, operator);
		}
	}
public void parse(final String in) {
		ParseState state = ParseState.TEXT;
		ParseState stateOnEscape = null;

		boolean insideSection = false;
		String currentSection = null;
		String key = null;
		Operator operator = Operator.ASSIGN;
		final StringBuilder sb = new StringBuilder();

		final int len = in.length();
		int ndx = 0;
		while (ndx < len) {
			final char c = in.charAt(ndx);
			ndx++;

			if (state == ParseState.COMMENT) {
				// comment, skip to the end of the line
				if (c == '\r') {
					if ((ndx < len) && (in.charAt(ndx) == '\n')) {
						ndx++;
					}
					state = ParseState.TEXT;
				}
				else if (c == '\n') {
					state = ParseState.TEXT;
				}
			} else if (state == ParseState.ESCAPE) {
				state = stateOnEscape;  //ParseState.VALUE;
				switch (c) {
					case '\r':
						if ((ndx < len) && (in.charAt(ndx) == '\n')) {
							ndx++;
						}
					case '\n':
						// need to go 1 step back in order to escape
						// the current line ending in the follow-up state
						ndx--;
						state = ParseState.ESCAPE_NEWLINE;
						break;
					// encode UTF character
					case 'u':
						int value = 0;

						for (int i = 0; i < 4; i++) {
							final char hexChar = in.charAt(ndx++);
							if (CharUtil.isDigit(hexChar)) {
								value = (value << 4) + hexChar - '0';
							} else if (hexChar >= 'a' && hexChar <= 'f') {
								value = (value << 4) + 10 + hexChar - 'a';
							} else if (hexChar >= 'A' && hexChar <= 'F') {
								value = (value << 4) + 10 + hexChar - 'A';
							} else {
								throw new IllegalArgumentException("Malformed \\uXXXX encoding.");
							}
						}
						sb.append((char) value);
						break;
					case 't':
						sb.append('\t');
						break;
					case 'n':
						sb.append('\n');
						break;
					case 'r':
						sb.append('\r');
						break;
					case 'f':
						sb.append('\f');
						break;
					default:
						sb.append(c);
				}
			} else if (state == ParseState.TEXT) {
				switch (c) {
					case '\\':
						// escape char, take the next char as is
						stateOnEscape = state;
						state = ParseState.ESCAPE;
						break;

					// start section
					case '[':
						if (sb.length() > 0) {
							if (StringUtil.isNotBlank(sb)) {
								sb.append(c);
								// previous string is not blank, hence it's not the section
								break;
							}
						}
						sb.setLength(0);
						insideSection = true;
						break;

					// end section
					case ']':
						if (insideSection) {
							currentSection = sb.toString().trim();
							sb.setLength(0);
							insideSection = false;
							if (currentSection.length() == 0) {
								currentSection = null;
							}
						} else {
							sb.append(c);
						}
						break;

					case '#':
					case ';':
						state = ParseState.COMMENT;
						break;

					// copy operator
					case '<':
						if (ndx == len || in.charAt(ndx) != '=') {
							sb.append(c);
							break;
						}
						operator = Operator.COPY;
						//ndx++;
						continue;

					// assignment operator
					case '+':
						if (ndx == len || in.charAt(ndx) != '=') {
							sb.append(c);
							break;
						}
						operator = Operator.QUICK_APPEND;
						//ndx++;
						continue;
					case '=':
					case ':':
						if (key == null) {
							key = sb.toString().trim();
							sb.setLength(0);
						} else {
							sb.append(c);
						}
						state = ParseState.VALUE;
						break;

					case '\r':
					case '\n':
						add(currentSection, key, sb, true, operator);
						sb.setLength(0);
						key = null;
						operator = Operator.ASSIGN;
						break;

					case ' ':
					case '\t':
						// ignore whitespaces
						break;
					default:
						sb.append(c);
				}
			} else {
				switch (c) {
					case '\\':
						// escape char, take the next char as is
						stateOnEscape = state;
						state = ParseState.ESCAPE;
						break;

					case '\r':
						if ((ndx < len) && (in.charAt(ndx) == '\n')) {
							ndx++;
						}
					case '\n':
						if (state == ParseState.ESCAPE_NEWLINE) {
							sb.append(escapeNewLineValue);
							if (!ignorePrefixWhitespacesOnNewLine) {
								state = ParseState.VALUE;
							}
						} else {
							add(currentSection, key, sb, true, operator);
							sb.setLength(0);
							key = null;
							operator = Operator.ASSIGN;

							// end of value, continue to text
							state = ParseState.TEXT;
						}
						break;

					case ' ':
					case '\t':
						if (state == ParseState.ESCAPE_NEWLINE) {
							break;
						}
					default:
						sb.append(c);
						state = ParseState.VALUE;

						if (multilineValues) {
							if (sb.length() == 3) {

								// check for ''' beginning
								if (sb.toString().equals("'''")) {
									sb.setLength(0);
									int endIndex = in.indexOf("'''", ndx);
									if (endIndex == -1) {
										endIndex = in.length();
									}
									sb.append(in, ndx, endIndex);

									// append
									add(currentSection, key, sb, false, operator);
									sb.setLength(0);
									key = null;
									operator = Operator.ASSIGN;

									// end of value, continue to text
									state = ParseState.TEXT;
									ndx = endIndex + 3;
								}
							}
						}
				}
			}
		}

		if (key != null) {
			add(currentSection, key, sb, true, operator);
		}
	}
public void parse ( final String in ) { ParseState state = ParseState . TEXT ; ParseState stateOnEscape = null ; boolean insideSection = false ; String currentSection = null ; String key = null ; Operator operator = Operator . ASSIGN ; final StringBuilder sb = new StringBuilder ( ) ; final int len = in . length ( ) ; int ndx = 0 ; while ( ndx < len ) { final char c = in . charAt ( ndx ) ; ndx ++ ; if ( state == ParseState . COMMENT ) { // comment, skip to the end of the line if ( c == ' ' ) { if ( ( ndx < len ) && ( in . charAt ( ndx ) == ' ' ) ) { ndx ++ ; } state = ParseState . TEXT ; } else if ( c == ' ' ) { state = ParseState . TEXT ; } } else if ( state == ParseState . ESCAPE ) { state = stateOnEscape ; //ParseState.VALUE; switch ( c ) { case ' ' : if ( ( ndx < len ) && ( in . charAt ( ndx ) == ' ' ) ) { ndx ++ ; } case ' ' : // need to go 1 step back in order to escape // the current line ending in the follow-up state ndx -- ; state = ParseState . ESCAPE_NEWLINE ; break ; // encode UTF character case ' ' : int value = 0 ; for ( int i = 0 ; i < 4 ; i ++ ) { final char hexChar = in . charAt ( ndx ++ ) ; if ( CharUtil . isDigit ( hexChar ) ) { value = ( value << 4 ) + hexChar - ' ' ; } else if ( hexChar >= ' ' && hexChar <= ' ' ) { value = ( value << 4 ) + 10 + hexChar - ' ' ; } else if ( hexChar >= ' ' && hexChar <= ' ' ) { value = ( value << 4 ) + 10 + hexChar - ' ' ; } else { throw new IllegalArgumentException ( "Malformed \\uXXXX encoding." ) ; } } sb . append ( ( char ) value ) ; break ; case ' ' : sb . append ( ' ' ) ; break ; case ' ' : sb . append ( ' ' ) ; break ; case ' ' : sb . append ( ' ' ) ; break ; case ' ' : sb . append ( ' ' ) ; break ; default : sb . append ( c ) ; } } else if ( state == ParseState . TEXT ) { switch ( c ) { case ' ' : // escape char, take the next char as is stateOnEscape = state ; state = ParseState . ESCAPE ; break ; // start section case ' ' : if ( sb . length ( ) > 0 ) { if ( StringUtil . isNotBlank ( sb ) ) { sb . append ( c ) ; // previous string is not blank, hence it's not the section break ; } } sb . setLength ( 0 ) ; insideSection = true ; break ; // end section case ' ' : if ( insideSection ) { currentSection = sb . toString ( ) . trim ( ) ; sb . setLength ( 0 ) ; insideSection = false ; if ( currentSection . length ( ) == 0 ) { currentSection = null ; } } else { sb . append ( c ) ; } break ; case ' ' : case ' ' : state = ParseState . COMMENT ; break ; // copy operator case ' ' : if ( ndx == len || in . charAt ( ndx ) != ' ' ) { sb . append ( c ) ; break ; } operator = Operator . COPY ; //ndx++; continue ; // assignment operator case ' ' : if ( ndx == len || in . charAt ( ndx ) != ' ' ) { sb . append ( c ) ; break ; } operator = Operator . QUICK_APPEND ; //ndx++; continue ; case ' ' : case ' ' : if ( key == null ) { key = sb . toString ( ) . trim ( ) ; sb . setLength ( 0 ) ; } else { sb . append ( c ) ; } state = ParseState . VALUE ; break ; case ' ' : case ' ' : add ( currentSection , key , sb , true , operator ) ; sb . setLength ( 0 ) ; key = null ; operator = Operator . ASSIGN ; break ; case ' ' : case ' ' : // ignore whitespaces break ; default : sb . append ( c ) ; } } else { switch ( c ) { case ' ' : // escape char, take the next char as is stateOnEscape = state ; state = ParseState . ESCAPE ; break ; case ' ' : if ( ( ndx < len ) && ( in . charAt ( ndx ) == ' ' ) ) { ndx ++ ; } case ' ' : if ( state == ParseState . ESCAPE_NEWLINE ) { sb . append ( escapeNewLineValue ) ; if ( ! ignorePrefixWhitespacesOnNewLine ) { state = ParseState . VALUE ; } } else { add ( currentSection , key , sb , true , operator ) ; sb . setLength ( 0 ) ; key = null ; operator = Operator . ASSIGN ; // end of value, continue to text state = ParseState . TEXT ; } break ; case ' ' : case ' ' : if ( state == ParseState . ESCAPE_NEWLINE ) { break ; } default : sb . append ( c ) ; state = ParseState . VALUE ; if ( multilineValues ) { if ( sb . length ( ) == 3 ) { // check for ''' beginning if ( sb . toString ( ) . equals ( "'''" ) ) { sb . setLength ( 0 ) ; int endIndex = in . indexOf ( "'''" , ndx ) ; if ( endIndex == - 1 ) { endIndex = in . length ( ) ; } sb . append ( in , ndx , endIndex ) ; // append add ( currentSection , key , sb , false , operator ) ; sb . setLength ( 0 ) ; key = null ; operator = Operator . ASSIGN ; // end of value, continue to text state = ParseState . TEXT ; ndx = endIndex + 3 ; } } } } } } if ( key != null ) { add ( currentSection , key , sb , true , operator ) ; } }
Loads properties.
Loads properties .