@@ -1063,7 +1063,7 @@ public static class IntWrapper implements Serializable {
10631063 }
10641064
10651065 /**
1066- * Parses this UTF8String to long.
1066+ * Parses this UTF8String(trimmed if needed) to long.
10671067 *
10681068 * Note that, in this method we accumulate the result in negative format, and convert it to
10691069 * positive format at the end, if this string is not started with '-'. This is because min value
@@ -1077,20 +1077,17 @@ public static class IntWrapper implements Serializable {
10771077 * @return true if the parsing was successful else false
10781078 */
10791079 public boolean toLong (LongWrapper toLongResult ) {
1080- if (this .numBytes == 0 ) return false ;
10811080 int offset = 0 ;
1082- while (offset < this .numBytes && getByte (offset ) = = ' ' ) offset ++;
1081+ while (offset < this .numBytes && getByte (offset ) < = ' ' ) offset ++;
10831082 if (offset == this .numBytes ) return false ;
10841083
10851084 int end = this .numBytes - 1 ;
1086- while (end > offset && getByte (end ) == ' ' ) end --;
1087-
1088- int numBytes = end - offset + 1 ;
1085+ while (end > offset && getByte (end ) <= ' ' ) end --;
10891086
10901087 byte b = getByte (offset );
10911088 final boolean negative = b == '-' ;
10921089 if (negative || b == '+' ) {
1093- if (numBytes == 1 ) {
1090+ if (end - offset == 0 ) {
10941091 return false ;
10951092 }
10961093 offset ++;
@@ -1156,7 +1153,7 @@ public boolean toLong(LongWrapper toLongResult) {
11561153 }
11571154
11581155 /**
1159- * Parses this UTF8String to int.
1156+ * Parses this UTF8String(trimmed if needed) to int.
11601157 *
11611158 * Note that, in this method we accumulate the result in negative format, and convert it to
11621159 * positive format at the end, if this string is not started with '-'. This is because min value
@@ -1173,20 +1170,17 @@ public boolean toLong(LongWrapper toLongResult) {
11731170 * @return true if the parsing was successful else false
11741171 */
11751172 public boolean toInt (IntWrapper intWrapper ) {
1176- if (this .numBytes == 0 ) return false ;
11771173 int offset = 0 ;
1178- while (offset < this .numBytes && getByte (offset ) = = ' ' ) offset ++;
1174+ while (offset < this .numBytes && getByte (offset ) < = ' ' ) offset ++;
11791175 if (offset == this .numBytes ) return false ;
11801176
11811177 int end = this .numBytes - 1 ;
1182- while (end > offset && getByte (end ) == ' ' ) end --;
1183-
1184- int numBytes = end - offset + 1 ;
1178+ while (end > offset && getByte (end ) <= ' ' ) end --;
11851179
11861180 byte b = getByte (offset );
11871181 final boolean negative = b == '-' ;
11881182 if (negative || b == '+' ) {
1189- if (numBytes == 1 ) {
1183+ if (end - offset == 0 ) {
11901184 return false ;
11911185 }
11921186 offset ++;
0 commit comments