MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / parse

Method parse

vm/JavaAPI/src/java/lang/Integer.java:152–176  ·  view source on GitHub ↗
(String string, int offset, int radix, boolean negative)

Source from the content-addressed store, hash-verified

150 }
151
152 private static int parse(String string, int offset, int radix, boolean negative) throws NumberFormatException {
153 int max = Integer.MIN_VALUE / radix;
154 int result = 0, length = string.length();
155 while (offset < length) {
156 int digit = Character.digit(string.charAt(offset++), radix);
157 if (digit == -1) {
158 throw invalidInt(string);
159 }
160 if (max > result) {
161 throw invalidInt(string);
162 }
163 int next = result * radix - digit;
164 if (next > result) {
165 throw invalidInt(string);
166 }
167 result = next;
168 }
169 if (!negative) {
170 result = -result;
171 if (result < 0) {
172 throw invalidInt(string);
173 }
174 }
175 return result;
176 }
177
178 private static NumberFormatException invalidInt(String s) {
179 throw new NumberFormatException("Invalid int");

Callers 1

parseIntMethod · 0.95

Calls 4

digitMethod · 0.95
invalidIntMethod · 0.95
lengthMethod · 0.65
charAtMethod · 0.65

Tested by

no test coverage detected