static public String [ ] parseNameTokens ( String stringValue ) { if ( stringValue == null ) { return null ; } ArrayList < String > list = new ArrayList < String > ( 5 ) ; int length = stringValue . length ( ) ; boolean inSpace = true ; int start = 0 ; for ( int i = 0 ; i < length ; i ++ ) { char ch = stringValue . charAt ( i ) ; // We're in whitespace; if we've just departed // a run of non-whitespace, append a string. // Now, why do we use the supposedly deprecated "Character.isSpace()" // function instead of "isWhitespace"? We're following XML rules // here for the meaning of whitespace, which specifically // EXCLUDES general Unicode spaces. if ( Character . isWhitespace ( ch ) ) { if ( ! inSpace ) { list . add ( stringValue . substring ( start , i ) ) ; inSpace = true ; } } // We're out of whitespace; if we've just departed // a run of whitespace, start keeping track of this string else { if ( inSpace ) { start = i ; inSpace = false ; } } } if ( ! inSpace ) { list . add ( stringValue . substring ( start ) ) ; } if ( list . isEmpty ( ) ) { return null ; } return list . toArray ( new String [ list . size ( ) ] ) ; }
Parses a whitespace separated series of name tokens .