@Test public void testExtractExpressionRanges() { assertEquals(29, Query.extractExpressionRanges("${hello:equals( $${goodbye} )}").get(0).getEnd()); List<Range> ranges = Query.extractExpressionRanges("hello"); assertTrue(ranges.isEmpty()); ranges = Query.extractExpressionRanges("${hello"); assertTrue(ranges.isEmpty()); ranges = Query.extractExpressionRanges("hello}"); assertTrue(ranges.isEmpty()); ranges = Query.extractExpressionRanges("$${hello"); assertTrue(ranges.isEmpty()); ranges = Query.extractExpressionRanges("$he{ll}o"); assertTrue(ranges.isEmpty()); ranges = Query.extractExpressionRanges("${hello}"); assertEquals(1, ranges.size()); Range range = ranges.get(0); assertEquals(0, range.getStart()); assertEquals(7, range.getEnd()); ranges = Query.extractExpressionRanges("${hello:equals( ${goodbye} )}"); assertEquals(1, ranges.size()); range = ranges.get(0); assertEquals(0, range.getStart()); assertEquals(28, range.getEnd()); ranges = Query.extractExpressionRanges("${hello:equals( $${goodbye} )}"); assertEquals(1, ranges.size()); range = ranges.get(0); assertEquals(0, range.getStart()); assertEquals(29, range.getEnd()); ranges = Query.extractExpressionRanges("${hello:equals( $${goodbye} )} or just hi, ${bob:or(${jerry})}"); assertEquals(2, ranges.size()); range = ranges.get(0); assertEquals(0, range.getStart()); assertEquals(29, range.getEnd()); range = ranges.get(1); assertEquals(43, range.getStart()); assertEquals(61, range.getEnd()); ranges = Query.extractExpressionRanges("${hello:equals( ${goodbye} )} or just hi, ${bob}, are you ${bob.age:toNumber()} yet? $$$${bob}"); assertEquals(3, ranges.size()); range = ranges.get(0); assertEquals(0, range.getStart()); assertEquals(28, range.getEnd()); range = ranges.get(1); assertEquals(42, range.getStart()); assertEquals(47, range.getEnd()); range = ranges.get(2); assertEquals(58, range.getStart()); assertEquals(78, range.getEnd()); ranges = Query.extractExpressionRanges("${x:matches( '.{4}' )}"); assertEquals(1, ranges.size()); range = ranges.get(0); assertEquals(0, range.getStart()); assertEquals(21, range.getEnd()); }
public static List<Range> extractExpressionRanges(final String value) throws AttributeExpressionLanguageParsingException { final List<Range> ranges = new ArrayList<>(); char lastChar = 0; int embeddedCount = 0; int expressionStart = -1; boolean oddDollarCount = false; int backslashCount = 0; charLoop: for (int i = 0; i < value.length(); i++) { final char c = value.charAt(i); if (expressionStart > -1 && (c == '\'' || c == '"') && (lastChar != '\\' || backslashCount % 2 == 0)) { final int endQuoteIndex = findEndQuoteChar(value, i); if (endQuoteIndex < 0) { break charLoop; } i = endQuoteIndex; continue; } if (c == '{') { if (oddDollarCount && lastChar == '$') { if (embeddedCount == 0) { expressionStart = i - 1; } } if (expressionStart > -1) { embeddedCount++; } } else if (c == '}') { if (embeddedCount <= 0) { continue; } if (--embeddedCount == 0) { if (expressionStart > -1) { final Range range = new Range(expressionStart, i); ranges.add(range); } expressionStart = -1; } } else if (c == '$') { oddDollarCount = !oddDollarCount; } else if (c == '\\') { backslashCount++; } else { oddDollarCount = false; } lastChar = c; } return ranges; }
Query { public static List<Range> extractExpressionRanges(final String value) throws AttributeExpressionLanguageParsingException { final List<Range> ranges = new ArrayList<>(); char lastChar = 0; int embeddedCount = 0; int expressionStart = -1; boolean oddDollarCount = false; int backslashCount = 0; charLoop: for (int i = 0; i < value.length(); i++) { final char c = value.charAt(i); if (expressionStart > -1 && (c == '\'' || c == '"') && (lastChar != '\\' || backslashCount % 2 == 0)) { final int endQuoteIndex = findEndQuoteChar(value, i); if (endQuoteIndex < 0) { break charLoop; } i = endQuoteIndex; continue; } if (c == '{') { if (oddDollarCount && lastChar == '$') { if (embeddedCount == 0) { expressionStart = i - 1; } } if (expressionStart > -1) { embeddedCount++; } } else if (c == '}') { if (embeddedCount <= 0) { continue; } if (--embeddedCount == 0) { if (expressionStart > -1) { final Range range = new Range(expressionStart, i); ranges.add(range); } expressionStart = -1; } } else if (c == '$') { oddDollarCount = !oddDollarCount; } else if (c == '\\') { backslashCount++; } else { oddDollarCount = false; } lastChar = c; } return ranges; } }
Query { public static List<Range> extractExpressionRanges(final String value) throws AttributeExpressionLanguageParsingException { final List<Range> ranges = new ArrayList<>(); char lastChar = 0; int embeddedCount = 0; int expressionStart = -1; boolean oddDollarCount = false; int backslashCount = 0; charLoop: for (int i = 0; i < value.length(); i++) { final char c = value.charAt(i); if (expressionStart > -1 && (c == '\'' || c == '"') && (lastChar != '\\' || backslashCount % 2 == 0)) { final int endQuoteIndex = findEndQuoteChar(value, i); if (endQuoteIndex < 0) { break charLoop; } i = endQuoteIndex; continue; } if (c == '{') { if (oddDollarCount && lastChar == '$') { if (embeddedCount == 0) { expressionStart = i - 1; } } if (expressionStart > -1) { embeddedCount++; } } else if (c == '}') { if (embeddedCount <= 0) { continue; } if (--embeddedCount == 0) { if (expressionStart > -1) { final Range range = new Range(expressionStart, i); ranges.add(range); } expressionStart = -1; } } else if (c == '$') { oddDollarCount = !oddDollarCount; } else if (c == '\\') { backslashCount++; } else { oddDollarCount = false; } lastChar = c; } return ranges; } private  Query(final String query, final Tree tree, final Evaluator<?> evaluator); }
Query { public static List<Range> extractExpressionRanges(final String value) throws AttributeExpressionLanguageParsingException { final List<Range> ranges = new ArrayList<>(); char lastChar = 0; int embeddedCount = 0; int expressionStart = -1; boolean oddDollarCount = false; int backslashCount = 0; charLoop: for (int i = 0; i < value.length(); i++) { final char c = value.charAt(i); if (expressionStart > -1 && (c == '\'' || c == '"') && (lastChar != '\\' || backslashCount % 2 == 0)) { final int endQuoteIndex = findEndQuoteChar(value, i); if (endQuoteIndex < 0) { break charLoop; } i = endQuoteIndex; continue; } if (c == '{') { if (oddDollarCount && lastChar == '$') { if (embeddedCount == 0) { expressionStart = i - 1; } } if (expressionStart > -1) { embeddedCount++; } } else if (c == '}') { if (embeddedCount <= 0) { continue; } if (--embeddedCount == 0) { if (expressionStart > -1) { final Range range = new Range(expressionStart, i); ranges.add(range); } expressionStart = -1; } } else if (c == '$') { oddDollarCount = !oddDollarCount; } else if (c == '\\') { backslashCount++; } else { oddDollarCount = false; } lastChar = c; } return ranges; } private  Query(final String query, final Tree tree, final Evaluator<?> evaluator); static boolean isValidExpression(final String value); static ResultType getResultType(final String value); static List<ResultType> extractResultTypes(final String value); static List<String> extractExpressions(final String value); static List<Range> extractExpressionRanges(final String value); static void validateExpression(final String value, final boolean allowSurroundingCharacters); static String unescape(final String value); static Query fromTree(final Tree tree, final String text); static Tree compileTree(final String query); static PreparedQuery prepare(final String query); static Query compile(final String query); ResultType getResultType(); @Override String toString(); }
Query { public static List<Range> extractExpressionRanges(final String value) throws AttributeExpressionLanguageParsingException { final List<Range> ranges = new ArrayList<>(); char lastChar = 0; int embeddedCount = 0; int expressionStart = -1; boolean oddDollarCount = false; int backslashCount = 0; charLoop: for (int i = 0; i < value.length(); i++) { final char c = value.charAt(i); if (expressionStart > -1 && (c == '\'' || c == '"') && (lastChar != '\\' || backslashCount % 2 == 0)) { final int endQuoteIndex = findEndQuoteChar(value, i); if (endQuoteIndex < 0) { break charLoop; } i = endQuoteIndex; continue; } if (c == '{') { if (oddDollarCount && lastChar == '$') { if (embeddedCount == 0) { expressionStart = i - 1; } } if (expressionStart > -1) { embeddedCount++; } } else if (c == '}') { if (embeddedCount <= 0) { continue; } if (--embeddedCount == 0) { if (expressionStart > -1) { final Range range = new Range(expressionStart, i); ranges.add(range); } expressionStart = -1; } } else if (c == '$') { oddDollarCount = !oddDollarCount; } else if (c == '\\') { backslashCount++; } else { oddDollarCount = false; } lastChar = c; } return ranges; } private  Query(final String query, final Tree tree, final Evaluator<?> evaluator); static boolean isValidExpression(final String value); static ResultType getResultType(final String value); static List<ResultType> extractResultTypes(final String value); static List<String> extractExpressions(final String value); static List<Range> extractExpressionRanges(final String value); static void validateExpression(final String value, final boolean allowSurroundingCharacters); static String unescape(final String value); static Query fromTree(final Tree tree, final String text); static Tree compileTree(final String query); static PreparedQuery prepare(final String query); static Query compile(final String query); ResultType getResultType(); @Override String toString();  }