CharScanner { public static long parseLong(char[] digitChars, int offset, int to) { long num; boolean negative=false; char c = digitChars[ offset ]; if (c == '-') { offset++; negative=true; } c = digitChars[ offset ]; num = (c - '0'); offset++; long digit; for (; offset < to; offset++) { c = digitChars [offset]; digit = ( c - '0' ); num = ( num * 10 ) + digit; } return negative ? num * -1 : num; }  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 boolean isDigits( final char[] inputArray, int offset, int len); 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); static int NEWLINE; static int CARRIAGE_RETURN; }
@Test public void parseLongTest() { long value = CharScanner.parseLong( "-22".toCharArray() ); boolean ok = value == -22L || die( "" + value); value = CharScanner.parseInt( "22".toCharArray() ); ok = value == 22 || die( "" + value); }
@Test public void parseLongTest2() { String test = "" + (Long.MAX_VALUE / 2L); long value = CharScanner.parseLong( test.toCharArray() ); boolean ok = value == Long.parseLong( test )|| die( value, Long.parseLong( test )); }
@Test public void parseLongTest3() { String test = "" + (Long.MIN_VALUE / 2L); long value = CharScanner.parseLong( test.toCharArray() ); boolean ok = value == Long.parseLong( test )|| die( value, Long.parseLong( test )); }
@Test public void parseLongTest4() { String test = "" + (Long.MAX_VALUE ); long value = CharScanner.parseLong( test.toCharArray() ); boolean ok = value == Long.parseLong( test )|| die( value, Long.parseLong( test )); }
@Test public void parseLongTest5() { String test = "" + (Long.MIN_VALUE ); long value = CharScanner.parseLong( test.toCharArray() ); boolean ok = value == Long.parseLong( test )|| die( value, Long.parseLong( test )); }
@Test public void parseLongMax() { boolean ok = true; long l = 0; l = CharScanner.parseLong( ("" + Long.MAX_VALUE).toCharArray() ); ok &= l == Long.MAX_VALUE || die( "l", l, "MAX", Long.MAX_VALUE); }
@Test public void parseLongMin() { boolean ok = true; long l = 0; l = CharScanner.parseLong( ("" + Long.MIN_VALUE).toCharArray() ); ok &= l == Long.MIN_VALUE || die( "l", l, "MIN", Long.MIN_VALUE); }
@Test public void parseLong() { String str = "12345678910"; long l1 = CharScanner.parseLong(str.toCharArray(), 0, str.length()); boolean ok = l1 == 12345678910L || die("" + l1); str = "abc12345678910"; l1 = CharScanner.parseLong(str.toCharArray(), 3, str.length()); ok = l1 == 12345678910L || die("" + l1); str = "abcdefghijklmnopqrstuvwxyz12345678910"; l1 = CharScanner.parseLong(str.toCharArray(), 26, str.length()); ok = l1 == 12345678910L || die("" + l1); String str2 = "abcdefghijklmnopqrstuvwxyz12345678910mymilkshakemakestheboysintheyard"; l1 = CharScanner.parseLong(str2.toCharArray(), 26, str.length()); ok = l1 == 12345678910L || die("" + l1); }