private List<String> splitInternal(final String input,
			final boolean splitOnWhitespace, final char separator,
			final String separatorSet, final int maxSegments) {
		if (input == null) {
			return null;
		}
		try {
			final List<String> segments = new ArrayList<String>();
			StringBuilder buffer = new StringBuilder();

			for (int index = 0; index < input.length(); index++) {
				final char c = input.charAt(index);
				boolean separatedByWhitespace = false;
				if (splitOnWhitespace) {
					for (; index < input.length()
							&& Character.isWhitespace(input.charAt(index)); index++) {
						separatedByWhitespace = true;
					}
					if (separatedByWhitespace) {
						index--;
					}
				}

				final boolean separates = separatedByWhitespace
						|| (separatorSet != null ? separatorSet.indexOf(c) != -1
								: c == separator);
				// in case we are not already in the last segment and there is
				// an
				// unsecaped, unquoted separator, this segment is now done
				if (segments.size() != maxSegments - 1 && separates
						&& !isEscaped()) {
					finish(segments, buffer);
					buffer = new StringBuilder();
				} else {
					append(buffer, c);
				}
			}
			if (!splitOnWhitespace || buffer.length() != 0) {
				finish(segments, buffer);
			}
			return segments;
		} finally {
			escaped = false;
			quoted = false;
		}
	}
private List < String > splitInternal ( final String input , final boolean splitOnWhitespace , final char separator , final String separatorSet , final int maxSegments ) { if ( input == null ) { return null ; } try { final List < String > segments = new ArrayList < String > ( ) ; StringBuilder buffer = new StringBuilder ( ) ; for ( int index = 0 ; index < input . length ( ) ; index ++ ) { final char c = input . charAt ( index ) ; boolean separatedByWhitespace = false ; if ( splitOnWhitespace ) { for ( ; index < input . length ( ) && Character . isWhitespace ( input . charAt ( index ) ) ; index ++ ) { separatedByWhitespace = true ; } if ( separatedByWhitespace ) { index -- ; } } final boolean separates = separatedByWhitespace || ( separatorSet != null ? separatorSet . indexOf ( c ) != - 1 : c == separator ) ; if ( segments . size ( ) != maxSegments - 1 && separates && ! isEscaped ( ) ) { finish ( segments , buffer ) ; buffer = new StringBuilder ( ) ; } else { append ( buffer , c ) ; } } if ( ! splitOnWhitespace || buffer . length ( ) != 0 ) { finish ( segments , buffer ) ; } return segments ; } finally { escaped = false ; quoted = false ; } }
use