@Test public void splitThisEndsInSpace() { char[] letters = chars( "This is a string " ); char[][] splitted = CharScanner.splitExact( letters, ' ', 10 ); assertEquals( 4, splitted.length ); assertArrayEquals( chars( "This" ), splitted[ 0 ] ); assertArrayEquals( chars( "is" ), splitted[ 1 ] ); assertArrayEquals( chars( "a" ), splitted[ 2 ] ); assertArrayEquals( chars( "string" ), splitted[ 3 ] ); assertArrayEquals( new char[][]{ chars( "This" ), chars( "is" ), chars( "a" ), chars( "string" ) }, splitted ); }
public static char[][] splitExact( final char[] inputArray, final char split, final int resultsArrayLength ) { char[][] results = new char[ resultsArrayLength ][]; int resultIndex = 0; int startCurrentLineIndex = 0; int currentLineLength = 1; char c = '\u0000'; int index = 0; for (; index < inputArray.length; index++, currentLineLength++ ) { c = inputArray[ index ]; if ( c == split ) { results[ resultIndex ] = Chr.copy( inputArray, startCurrentLineIndex, currentLineLength - 1 ); startCurrentLineIndex = index + 1; currentLineLength = 0; resultIndex++; } } if ( c != split ) { results[ resultIndex ] = Chr.copy( inputArray, startCurrentLineIndex, currentLineLength - 1 ); resultIndex++; } int actualLength = resultIndex; if ( actualLength < resultsArrayLength ) { final int newSize = resultsArrayLength - actualLength; results = __shrink( results, newSize ); } return results; }
CharScanner { public static char[][] splitExact( final char[] inputArray, final char split, final int resultsArrayLength ) { char[][] results = new char[ resultsArrayLength ][]; int resultIndex = 0; int startCurrentLineIndex = 0; int currentLineLength = 1; char c = '\u0000'; int index = 0; for (; index < inputArray.length; index++, currentLineLength++ ) { c = inputArray[ index ]; if ( c == split ) { results[ resultIndex ] = Chr.copy( inputArray, startCurrentLineIndex, currentLineLength - 1 ); startCurrentLineIndex = index + 1; currentLineLength = 0; resultIndex++; } } if ( c != split ) { results[ resultIndex ] = Chr.copy( inputArray, startCurrentLineIndex, currentLineLength - 1 ); resultIndex++; } int actualLength = resultIndex; if ( actualLength < resultsArrayLength ) { final int newSize = resultsArrayLength - actualLength; results = __shrink( results, newSize ); } return results; } }
CharScanner { public static char[][] splitExact( final char[] inputArray, final char split, final int resultsArrayLength ) { char[][] results = new char[ resultsArrayLength ][]; int resultIndex = 0; int startCurrentLineIndex = 0; int currentLineLength = 1; char c = '\u0000'; int index = 0; for (; index < inputArray.length; index++, currentLineLength++ ) { c = inputArray[ index ]; if ( c == split ) { results[ resultIndex ] = Chr.copy( inputArray, startCurrentLineIndex, currentLineLength - 1 ); startCurrentLineIndex = index + 1; currentLineLength = 0; resultIndex++; } } if ( c != split ) { results[ resultIndex ] = Chr.copy( inputArray, startCurrentLineIndex, currentLineLength - 1 ); resultIndex++; } int actualLength = resultIndex; if ( actualLength < resultsArrayLength ) { final int newSize = resultsArrayLength - actualLength; results = __shrink( results, newSize ); } return results; }  }
CharScanner { public static char[][] splitExact( final char[] inputArray, final char split, final int resultsArrayLength ) { char[][] results = new char[ resultsArrayLength ][]; int resultIndex = 0; int startCurrentLineIndex = 0; int currentLineLength = 1; char c = '\u0000'; int index = 0; for (; index < inputArray.length; index++, currentLineLength++ ) { c = inputArray[ index ]; if ( c == split ) { results[ resultIndex ] = Chr.copy( inputArray, startCurrentLineIndex, currentLineLength - 1 ); startCurrentLineIndex = index + 1; currentLineLength = 0; resultIndex++; } } if ( c != split ) { results[ resultIndex ] = Chr.copy( inputArray, startCurrentLineIndex, currentLineLength - 1 ); resultIndex++; } int actualLength = resultIndex; if ( actualLength < resultsArrayLength ) { final int newSize = resultsArrayLength - actualLength; results = __shrink( results, newSize ); } return results; }  static boolean isDigit( int c ); static boolean isDecimalDigit( int c ); static boolean isDecimalChar( int currentChar ); static boolean hasDecimalChar( char[] chars, boolean negative ); static boolean isDigits( final char[] inputArray ); static char[][] splitExact( final char[] inputArray,
                                       final char split, final int resultsArrayLength ); static char[][] splitExact( final char[] inputArray,
                                       final int resultsArrayLength, char... delims ); static char[][] splitLines( final char[] inputArray); static char[][] split( final char[] inputArray,
                                  final char split ); static char[][] splitFrom( final char[] inputArray,
                                  final char split, int from ); static char[][] split( final char[] inputArray,
                                  final char split, final int limit ); static char[][] splitFromStartWithLimit( final char[] inputArray,
                                  final char split, final int start,
                                  final int limit ); static char[][] splitByChars( final char[] inputArray,
                                         final char... delims ); static char[][] splitByCharsFromToDelims( final char[] inputArray, int from, int to,
                                                     final char... delims ); static char[][] splitByCharsNoneEmpty( final char[] inputArray,
                                                  final char... delims ); static char[][] splitByCharsNoneEmpty( final char[] inputArray, int from, int to,
                                                  final char... delims ); static char[][] compact( char[][] array ); static boolean isLong( char[] digitChars ); static boolean isLong( char[] digitChars, int offset, int len
                                   ); static boolean isInteger( char[] digitChars ); static boolean isInteger( char[] digitChars, int offset, int len); static int parseInt( char[] digitChars ); static int parseInt(char[] digitChars, int offset, int to); static int parseIntFromToIgnoreDot( char[] digitChars, int offset, int to ); static long parseLongFromToIgnoreDot( char[] digitChars, int offset, int to ); static long parseLong(char[] digitChars, int offset, int to); static long parseLong( char[] digitChars ); static Number parseJsonNumber( char[] buffer ); static Number parseJsonNumber( char[] buffer, int from, int to ); static final boolean isNumberDigit(int c); static boolean isDelimiter( int c ); static Number parseJsonNumber( char[] buffer, int from, int max, int size[] ); static float parseFloat( char[] buffer, int from, int to ); static float parseFloat( char[] buffer ); static double parseDouble( char[] buffer ); static double parseDouble( char[] buffer, int from, int to ); static int skipWhiteSpace( char [] array); static int skipWhiteSpace( char [] array, int index ); static int skipWhiteSpace( char [] array, int index, final int length ); static char[] readNumber( char[] array, int idx ); static char[] readNumber( char[] array, int idx, final int len ); static int skipWhiteSpaceFast( char [] array ); static int skipWhiteSpaceFast( char [] array, int index ); static String errorDetails( String message, char[] array, int index, int ch ); static String debugCharDescription( int c ); static final boolean isDoubleQuote( int c ); static final boolean isEscape( int c ); static boolean hasEscapeChar(char []array, int index, int[] indexHolder); static int findEndQuote(final char[] array,  int index); static char[][] splitComma(char[] inputArray); static char[][] splitBySpace( char[] inputArray); static char[][] splitByChar(int splitChar, char[] inputArray); static int findChar(char c, char[] line); static int findWhiteSpace(char[] line); static int findWhiteSpace( int start, char[] line); static int findChar(char c, int startIndex, char[] line); static int findString(String matchString, int startIndex, char[] line); static int findString(String matchString, char[] line); static int findChars(char[] matchChars, char[] line); static boolean matchChars(char[] matchChars, int startIndex, char[] line); static int findChars(char[] matchChars, int startIndex, char[] line); static char[][] splitByPipe(char[] inputArray); }
CharScanner { public static char[][] splitExact( final char[] inputArray, final char split, final int resultsArrayLength ) { char[][] results = new char[ resultsArrayLength ][]; int resultIndex = 0; int startCurrentLineIndex = 0; int currentLineLength = 1; char c = '\u0000'; int index = 0; for (; index < inputArray.length; index++, currentLineLength++ ) { c = inputArray[ index ]; if ( c == split ) { results[ resultIndex ] = Chr.copy( inputArray, startCurrentLineIndex, currentLineLength - 1 ); startCurrentLineIndex = index + 1; currentLineLength = 0; resultIndex++; } } if ( c != split ) { results[ resultIndex ] = Chr.copy( inputArray, startCurrentLineIndex, currentLineLength - 1 ); resultIndex++; } int actualLength = resultIndex; if ( actualLength < resultsArrayLength ) { final int newSize = resultsArrayLength - actualLength; results = __shrink( results, newSize ); } return results; }  static boolean isDigit( int c ); static boolean isDecimalDigit( int c ); static boolean isDecimalChar( int currentChar ); static boolean hasDecimalChar( char[] chars, boolean negative ); static boolean isDigits( final char[] inputArray ); static char[][] splitExact( final char[] inputArray,
                                       final char split, final int resultsArrayLength ); static char[][] splitExact( final char[] inputArray,
                                       final int resultsArrayLength, char... delims ); static char[][] splitLines( final char[] inputArray); static char[][] split( final char[] inputArray,
                                  final char split ); static char[][] splitFrom( final char[] inputArray,
                                  final char split, int from ); static char[][] split( final char[] inputArray,
                                  final char split, final int limit ); static char[][] splitFromStartWithLimit( final char[] inputArray,
                                  final char split, final int start,
                                  final int limit ); static char[][] splitByChars( final char[] inputArray,
                                         final char... delims ); static char[][] splitByCharsFromToDelims( final char[] inputArray, int from, int to,
                                                     final char... delims ); static char[][] splitByCharsNoneEmpty( final char[] inputArray,
                                                  final char... delims ); static char[][] splitByCharsNoneEmpty( final char[] inputArray, int from, int to,
                                                  final char... delims ); static char[][] compact( char[][] array ); static boolean isLong( char[] digitChars ); static boolean isLong( char[] digitChars, int offset, int len
                                   ); static boolean isInteger( char[] digitChars ); static boolean isInteger( char[] digitChars, int offset, int len); static int parseInt( char[] digitChars ); static int parseInt(char[] digitChars, int offset, int to); static int parseIntFromToIgnoreDot( char[] digitChars, int offset, int to ); static long parseLongFromToIgnoreDot( char[] digitChars, int offset, int to ); static long parseLong(char[] digitChars, int offset, int to); static long parseLong( char[] digitChars ); static Number parseJsonNumber( char[] buffer ); static Number parseJsonNumber( char[] buffer, int from, int to ); static final boolean isNumberDigit(int c); static boolean isDelimiter( int c ); static Number parseJsonNumber( char[] buffer, int from, int max, int size[] ); static float parseFloat( char[] buffer, int from, int to ); static float parseFloat( char[] buffer ); static double parseDouble( char[] buffer ); static double parseDouble( char[] buffer, int from, int to ); static int skipWhiteSpace( char [] array); static int skipWhiteSpace( char [] array, int index ); static int skipWhiteSpace( char [] array, int index, final int length ); static char[] readNumber( char[] array, int idx ); static char[] readNumber( char[] array, int idx, final int len ); static int skipWhiteSpaceFast( char [] array ); static int skipWhiteSpaceFast( char [] array, int index ); static String errorDetails( String message, char[] array, int index, int ch ); static String debugCharDescription( int c ); static final boolean isDoubleQuote( int c ); static final boolean isEscape( int c ); static boolean hasEscapeChar(char []array, int index, int[] indexHolder); static int findEndQuote(final char[] array,  int index); static char[][] splitComma(char[] inputArray); static char[][] splitBySpace( char[] inputArray); static char[][] splitByChar(int splitChar, char[] inputArray); static int findChar(char c, char[] line); static int findWhiteSpace(char[] line); static int findWhiteSpace( int start, char[] line); static int findChar(char c, int startIndex, char[] line); static int findString(String matchString, int startIndex, char[] line); static int findString(String matchString, char[] line); static int findChars(char[] matchChars, char[] line); static boolean matchChars(char[] matchChars, int startIndex, char[] line); static int findChars(char[] matchChars, int startIndex, char[] line); static char[][] splitByPipe(char[] inputArray);  }