aboutsummaryrefslogtreecommitdiffstats
path: root/document/src/main/java/com/yahoo/document/select/simple/StringParser.java
blob: 9a16467a778dfbc02457bd1d9bff34da7bef9fd4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.document.select.simple;

import com.yahoo.document.select.rule.LiteralNode;

/**
 * @author baldersheim
 */
public class StringParser extends Parser {
    private LiteralNode value;
    public LiteralNode getValue() { return value; }
    public boolean parse(CharSequence s) {
        boolean retval = false;
        int pos = eatWhite(s);
        if (pos + 1 < s.length()) {
        if (s.charAt(pos++) == '"') {
            StringBuilder str = new StringBuilder();
            for(; (pos < s.length()) && (s.charAt(pos) != '"');pos++) {
                if ((pos < s.length()) && (s.charAt(pos) == '\\')) {
                    pos++;
                }
                str.append(s.charAt(pos));
            }
            if (s.charAt(pos) == '"') {
                pos++;
                retval = true;
                value = new LiteralNode(str.toString());
            }
        }

        setRemaining(s.subSequence(pos, s.length()));
    }
        return retval;
    }
}