@Test public void testSplitHelperName() { assertHelperNameParts("name foo.bar", "name", "foo.bar"); assertHelperNameParts("name hash1=\"DD-MM-yyyy HH:mm\"", "name", "hash1=\"DD-MM-yyyy HH:mm\""); assertHelperNameParts("name key='value'", "name", "key='value'"); assertHelperNameParts("name key=''value''", "name", "key=''value''"); assertHelperNameParts("key='value foo=' 'bar'", "key='value foo='", "'bar'"); assertHelperNameParts("'key'='value foo=' 'bar'", "'key'='value foo='", "'bar'"); assertHelperNameParts("foo='bar = \n baz' qux", "foo='bar = \n baz'", "qux"); assertHelperNameParts("[ 'foo', 'bar', qux] foo", "[ 'foo', 'bar', qux]", "foo"); assertHelperNameParts("1 20 ['', '1'] foo", "1", "20", "['', '1']", "foo"); assertHelperNameParts("'[1, 2]'", "'[1, 2]'"); assertHelperNameParts("'[1, '2', 'alpha']'", "'[1, '2', 'alpha']'"); assertHelperNameParts("foo=[1, '2']", "foo=[1, '2']"); assertHelperNameParts("if \"var eq 'value_without_space'\"", "if", "\"var eq 'value_without_space'\""); assertHelperNameParts("key='value\" foo=' 'bar'", "key='value\" foo='", "'bar'"); assertHelperNameParts("if \"var eq 'value with space'\"", "if", "\"var eq 'value with space'\""); MustacheExceptionAssert .expect(MustacheProblem.COMPILE_HELPER_VALIDATION_FAILURE) .check(() -> assertHelperNameParts("name key=''value'")) .check(() -> assertHelperNameParts("name key=value'")) .check(() -> assertHelperNameParts("name key='value foo")) .check(() -> assertHelperNameParts("name key=value' foo")) .check(() -> assertHelperNameParts("'name key=value")) .check(() -> assertHelperNameParts("key=\"value \" and\"")) .check(() -> assertHelperNameParts("foo='bar\"")); }
static Iterator<String> splitHelperName(String name, Segment segment) { Character stringLiteral = null; boolean arrayLiteral = false; boolean space = false; List<String> parts = new ArrayList<>(); StringBuilder buffer = new StringBuilder(); for (int i = 0; i < name.length(); i++) { char character = name.charAt(i); if (character == ' ') { if (!space) { if (stringLiteral == null && !arrayLiteral) { if (buffer.length() > 0) { parts.add(buffer.toString()); buffer = new StringBuilder(); } space = true; } else { buffer.append(character); } } } else { if (!arrayLiteral && Strings.isStringLiteralSeparator(character)) { if (stringLiteral != null) { if (character == stringLiteral.charValue()) { stringLiteral = null; } } else { stringLiteral = character; } } else if (stringLiteral == null && Strings.isListLiteralStart(character)) { arrayLiteral = true; } else if (stringLiteral == null && Strings.isListLiteralEnd(character)) { arrayLiteral = false; } space = false; buffer.append(character); } } if (buffer.length() > 0) { if (stringLiteral != null || arrayLiteral) { throw new MustacheException( MustacheProblem.COMPILE_HELPER_VALIDATION_FAILURE, "Unterminated string or array literal detected: %s", segment); } parts.add(buffer.toString()); } return parts.iterator(); }
HelperExecutionHandler { static Iterator<String> splitHelperName(String name, Segment segment) { Character stringLiteral = null; boolean arrayLiteral = false; boolean space = false; List<String> parts = new ArrayList<>(); StringBuilder buffer = new StringBuilder(); for (int i = 0; i < name.length(); i++) { char character = name.charAt(i); if (character == ' ') { if (!space) { if (stringLiteral == null && !arrayLiteral) { if (buffer.length() > 0) { parts.add(buffer.toString()); buffer = new StringBuilder(); } space = true; } else { buffer.append(character); } } } else { if (!arrayLiteral && Strings.isStringLiteralSeparator(character)) { if (stringLiteral != null) { if (character == stringLiteral.charValue()) { stringLiteral = null; } } else { stringLiteral = character; } } else if (stringLiteral == null && Strings.isListLiteralStart(character)) { arrayLiteral = true; } else if (stringLiteral == null && Strings.isListLiteralEnd(character)) { arrayLiteral = false; } space = false; buffer.append(character); } } if (buffer.length() > 0) { if (stringLiteral != null || arrayLiteral) { throw new MustacheException( MustacheProblem.COMPILE_HELPER_VALIDATION_FAILURE, "Unterminated string or array literal detected: %s", segment); } parts.add(buffer.toString()); } return parts.iterator(); } }
HelperExecutionHandler { static Iterator<String> splitHelperName(String name, Segment segment) { Character stringLiteral = null; boolean arrayLiteral = false; boolean space = false; List<String> parts = new ArrayList<>(); StringBuilder buffer = new StringBuilder(); for (int i = 0; i < name.length(); i++) { char character = name.charAt(i); if (character == ' ') { if (!space) { if (stringLiteral == null && !arrayLiteral) { if (buffer.length() > 0) { parts.add(buffer.toString()); buffer = new StringBuilder(); } space = true; } else { buffer.append(character); } } } else { if (!arrayLiteral && Strings.isStringLiteralSeparator(character)) { if (stringLiteral != null) { if (character == stringLiteral.charValue()) { stringLiteral = null; } } else { stringLiteral = character; } } else if (stringLiteral == null && Strings.isListLiteralStart(character)) { arrayLiteral = true; } else if (stringLiteral == null && Strings.isListLiteralEnd(character)) { arrayLiteral = false; } space = false; buffer.append(character); } } if (buffer.length() > 0) { if (stringLiteral != null || arrayLiteral) { throw new MustacheException( MustacheProblem.COMPILE_HELPER_VALIDATION_FAILURE, "Unterminated string or array literal detected: %s", segment); } parts.add(buffer.toString()); } return parts.iterator(); } private  HelperExecutionHandler(Helper helper,
            OptionsBuilder optionsBuilder); }
HelperExecutionHandler { static Iterator<String> splitHelperName(String name, Segment segment) { Character stringLiteral = null; boolean arrayLiteral = false; boolean space = false; List<String> parts = new ArrayList<>(); StringBuilder buffer = new StringBuilder(); for (int i = 0; i < name.length(); i++) { char character = name.charAt(i); if (character == ' ') { if (!space) { if (stringLiteral == null && !arrayLiteral) { if (buffer.length() > 0) { parts.add(buffer.toString()); buffer = new StringBuilder(); } space = true; } else { buffer.append(character); } } } else { if (!arrayLiteral && Strings.isStringLiteralSeparator(character)) { if (stringLiteral != null) { if (character == stringLiteral.charValue()) { stringLiteral = null; } } else { stringLiteral = character; } } else if (stringLiteral == null && Strings.isListLiteralStart(character)) { arrayLiteral = true; } else if (stringLiteral == null && Strings.isListLiteralEnd(character)) { arrayLiteral = false; } space = false; buffer.append(character); } } if (buffer.length() > 0) { if (stringLiteral != null || arrayLiteral) { throw new MustacheException( MustacheProblem.COMPILE_HELPER_VALIDATION_FAILURE, "Unterminated string or array literal detected: %s", segment); } parts.add(buffer.toString()); } return parts.iterator(); } private  HelperExecutionHandler(Helper helper,
            OptionsBuilder optionsBuilder);  }
HelperExecutionHandler { static Iterator<String> splitHelperName(String name, Segment segment) { Character stringLiteral = null; boolean arrayLiteral = false; boolean space = false; List<String> parts = new ArrayList<>(); StringBuilder buffer = new StringBuilder(); for (int i = 0; i < name.length(); i++) { char character = name.charAt(i); if (character == ' ') { if (!space) { if (stringLiteral == null && !arrayLiteral) { if (buffer.length() > 0) { parts.add(buffer.toString()); buffer = new StringBuilder(); } space = true; } else { buffer.append(character); } } } else { if (!arrayLiteral && Strings.isStringLiteralSeparator(character)) { if (stringLiteral != null) { if (character == stringLiteral.charValue()) { stringLiteral = null; } } else { stringLiteral = character; } } else if (stringLiteral == null && Strings.isListLiteralStart(character)) { arrayLiteral = true; } else if (stringLiteral == null && Strings.isListLiteralEnd(character)) { arrayLiteral = false; } space = false; buffer.append(character); } } if (buffer.length() > 0) { if (stringLiteral != null || arrayLiteral) { throw new MustacheException( MustacheProblem.COMPILE_HELPER_VALIDATION_FAILURE, "Unterminated string or array literal detected: %s", segment); } parts.add(buffer.toString()); } return parts.iterator(); } private  HelperExecutionHandler(Helper helper,
            OptionsBuilder optionsBuilder);   }