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

Method parse

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

Source from the content-addressed store, hash-verified

140 }
141
142 private static long parse(String string, int offset, int radix, boolean negative) {
143 long max = Long.MIN_VALUE / radix;
144 long result = 0, length = string.length();
145 while (offset < length) {
146 int digit = Character.digit(string.charAt(offset++), radix);
147 if (digit == -1) {
148 throw invalidLong(string);
149 }
150 if (max > result) {
151 throw invalidLong(string);
152 }
153 long next = result * radix - digit;
154 if (next > result) {
155 throw invalidLong(string);
156 }
157 result = next;
158 }
159 if (!negative) {
160 result = -result;
161 if (result < 0) {
162 throw invalidLong(string);
163 }
164 }
165 return result;
166 }
167
168 private static NumberFormatException invalidLong(String s) {
169 throw new NumberFormatException("Invalid long: \"" + s + "\"");

Callers 1

parseLongMethod · 0.95

Calls 4

digitMethod · 0.95
invalidLongMethod · 0.95
lengthMethod · 0.65
charAtMethod · 0.65

Tested by

no test coverage detected