Search in sources :

Example 1 with ConcatCharSequence

use of com.questdb.std.str.ConcatCharSequence in project questdb by bluestreak01.

the class ReplaceStrFunction method compileReplacePattern.

private void compileReplacePattern(VirtualColumn arg) throws ParserException {
    CharSequence pattern = arg.getFlyweightStr(null);
    if (pattern == null) {
        throw QueryError.$(arg.getPosition(), "null pattern?");
    }
    int pos = arg.getPosition();
    int start = 0;
    int index = -1;
    int dollar = -2;
    int dollarCount = 0;
    ConcatCharSequence concat = new ConcatCharSequence();
    boolean collectIndex = false;
    int n = pattern.length();
    for (int i = 0; i < n; i++) {
        char c = pattern.charAt(i);
        switch(c) {
            case '$':
                if (i == dollar + 1) {
                    throw QueryError.$(pos + i, "missing index");
                }
                if (i > start) {
                    concat.add(new FlyweightCharSequence().of(pattern, start, i - start));
                }
                collectIndex = true;
                index = 0;
                dollar = i;
                dollarCount++;
                break;
            default:
                if (collectIndex) {
                    int k = c - '0';
                    if (k > -1 && k < 10) {
                        index = index * 10 + k;
                    } else {
                        if (i == dollar + 1) {
                            throw QueryError.$(pos + i, "missing index");
                        }
                        concat.add(new GroupCharSequence(index));
                        start = i;
                        collectIndex = false;
                        index = -1;
                    }
                }
                break;
        }
    }
    if (collectIndex) {
        if (n == dollar + 1) {
            throw QueryError.$(pos + n, "missing index");
        }
        concat.add(new GroupCharSequence(index));
    } else if (start < n) {
        concat.add(new FlyweightCharSequence().of(pattern, start, n - start));
    }
    if (trivial = (dollarCount == 0)) {
        left = new FlyweightCharSequence();
        right = new FlyweightCharSequence();
        concat.surroundWith(left, right);
    }
    this.replacePattern = concat;
}
Also used : FlyweightCharSequence(com.questdb.std.str.FlyweightCharSequence) AbstractCharSequence(com.questdb.std.str.AbstractCharSequence) ConcatCharSequence(com.questdb.std.str.ConcatCharSequence) FlyweightCharSequence(com.questdb.std.str.FlyweightCharSequence) ConcatCharSequence(com.questdb.std.str.ConcatCharSequence)

Aggregations

AbstractCharSequence (com.questdb.std.str.AbstractCharSequence)1 ConcatCharSequence (com.questdb.std.str.ConcatCharSequence)1 FlyweightCharSequence (com.questdb.std.str.FlyweightCharSequence)1