@ Override public List < String > splitIdIntoElements ( String id ) { Preconditions . checkNotNull ( id , "id argument" ) ; List < String > elements = Lists . newArrayList ( ) ; int startOfNextElement = 0 ; int numConsecutiveEscapeCharacters = 0 ; char [ ] idChars = id . toCharArray ( ) ; for ( int i = 0 ; i < idChars . length ; i ++ ) { // If we hit a separator, only treat it as such if it is preceded by an even number of escape characters if ( idChars [ i ] == SEPARATOR && numConsecutiveEscapeCharacters % 2 == 0 ) { maybeAddSanitizedElement ( new String ( idChars , startOfNextElement , i - startOfNextElement ) , elements ) ; startOfNextElement = i + 1 ; } if ( idChars [ i ] == ' ' ) { numConsecutiveEscapeCharacters ++ ; } else { numConsecutiveEscapeCharacters = 0 ; } } maybeAddSanitizedElement ( new String ( idChars , startOfNextElement , idChars . length - startOfNextElement ) , elements ) ; return elements ; }
Splits a resource id into a list of elements .