static Iterator < String > splitHelperName ( String name , Segment segment ) { boolean stringLiteral = false ; boolean arrayLiteral = false ; boolean space = false ; List < String > parts = new ArrayList <> ( ) ; StringBuilder buffer = new StringBuilder ( ) ; for ( int i = 0 ; i < name . length ( ) ; i ++ ) { if ( name . charAt ( i ) == ' ' ) { if ( ! space ) { if ( ! stringLiteral && ! arrayLiteral ) { if ( buffer . length ( ) > 0 ) { parts . add ( buffer . toString ( ) ) ; buffer = new StringBuilder ( ) ; } space = true ; } else { buffer . append ( name . charAt ( i ) ) ; } } } else { if ( ! arrayLiteral && Strings . isStringLiteralSeparator ( name . charAt ( i ) ) ) { stringLiteral = ! stringLiteral ; } else if ( ! stringLiteral && Strings . isListLiteralStart ( name . charAt ( i ) ) ) { arrayLiteral = true ; } else if ( ! stringLiteral && Strings . isListLiteralEnd ( name . charAt ( i ) ) ) { arrayLiteral = false ; } space = false ; buffer . append ( name . charAt ( i ) ) ; } } if ( buffer . length ( ) > 0 ) { if ( stringLiteral || arrayLiteral ) { throw new MustacheException ( MustacheProblem . COMPILE_HELPER_VALIDATION_FAILURE , "Unterminated string or array literal detected: %s" , segment ) ; } parts . add ( buffer . toString ( ) ) ; } return parts . iterator ( ) ; }
Extracts parts from an input string . This implementation is quite naive and should be possibly rewritten . Note that we can t use a simple splitter because of string literals may contain whitespace chars .