private String parseValue()

in src/main/java/org/apache/commons/configuration2/INIConfiguration.java [796:859]


    private String parseValue(final String val, final BufferedReader reader) throws IOException {
        final StringBuilder propertyValue = new StringBuilder();
        boolean lineContinues;
        String value = val.trim();

        do {
            final boolean quoted = value.startsWith("\"") || value.startsWith("'");
            boolean stop = false;
            boolean escape = false;

            final char quote = quoted ? value.charAt(0) : 0;

            int i = quoted ? 1 : 0;

            final StringBuilder result = new StringBuilder();
            char lastChar = 0;
            while (i < value.length() && !stop) {
                final char c = value.charAt(i);

                if (quoted) {
                    if ('\\' == c && !escape) {
                        escape = true;
                    } else if (!escape && quote == c) {
                        stop = true;
                    } else {
                        if (escape && quote == c) {
                            escape = false;
                        } else if (escape) {
                            escape = false;
                            result.append('\\');
                        }
                        result.append(c);
                    }
                } else if (isCommentChar(c) && Character.isWhitespace(lastChar)) {
                    stop = true;
                } else {
                    result.append(c);
                }

                i++;
                lastChar = c;
            }

            String v = result.toString();
            if (!quoted) {
                v = v.trim();
                lineContinues = lineContinues(v);
                if (lineContinues) {
                    // remove trailing "\"
                    v = v.substring(0, v.length() - 1).trim();
                }
            } else {
                lineContinues = lineContinues(value, i);
            }
            propertyValue.append(v);

            if (lineContinues) {
                propertyValue.append(LINE_SEPARATOR);
                value = reader.readLine();
            }
        } while (lineContinues && value != null);

        return propertyValue.toString();
    }