public static String [ ] split ( FacesContext context , String value , char ... separators ) { if ( LangUtils . isValueBlank ( value ) ) { return null ; } List < String > tokens = new ArrayList <> ( 5 ) ; StringBuilder buffer = SharedStringBuilder . get ( context , SHARED_SPLIT_BUFFER_KEY ) ; int parenthesesCounter = 0 ; int length = value . length ( ) ; for ( int i = 0 ; i < length ; i ++ ) { char c = value . charAt ( i ) ; if ( c == ' ' ) { parenthesesCounter ++ ; } if ( c == ' ' ) { parenthesesCounter -- ; } if ( parenthesesCounter == 0 ) { boolean isSeparator = false ; for ( char separator : separators ) { if ( c == separator ) { isSeparator = true ; } } if ( isSeparator ) { // lets add token inside buffer to our tokens tokens . add ( buffer . toString ( ) ) ; // now we need to clear buffer buffer . delete ( 0 , buffer . length ( ) ) ; } else { buffer . append ( c ) ; } } else { buffer . append ( c ) ; } } // lets not forget about part after the separator tokens . add ( buffer . toString ( ) ) ; return tokens . toArray ( new String [ tokens . size ( ) ] ) ; }
Splits the given string by the given separator but ignoring separators inside parentheses .