public static long parsePositiveLong ( String str ) { long value = 0 ; final int length = str . length ( ) ; if ( length == 0 ) { throw new NumberFormatException ( str ) ; } long multiplier = 1 ; for ( int i = length - 1 ; i >= 0 ; -- i ) { char c = str . charAt ( i ) ; if ( c < ' ' || c > ' ' ) { throw new NumberFormatException ( str ) ; } long digit = c - ' ' ; value += digit * multiplier ; multiplier *= 10 ; } return value ; }
fast long parsing algorithm