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

Method parseName

vm/JavaAPI/src/java/lang/StringToReal.java:211–233  ·  view source on GitHub ↗
(String name, boolean isDouble)

Source from the content-addressed store, hash-verified

209
210 // Parses "+Nan", "NaN", "-Nan", "+Infinity", "Infinity", and "-Infinity", case-insensitively.
211 private static float parseName(String name, boolean isDouble) {
212 // Explicit sign?
213 boolean negative = false;
214 int i = 0;
215 int length = name.length();
216 char firstChar = name.charAt(i);
217 if (firstChar == '-') {
218 negative = true;
219 ++i;
220 --length;
221 } else if (firstChar == '+') {
222 ++i;
223 --length;
224 }
225
226 if (length == 8 && name.regionMatches(false, i, "Infinity", 0, 8)) {
227 return negative ? Float.NEGATIVE_INFINITY : Float.POSITIVE_INFINITY;
228 }
229 if (length == 3 && name.regionMatches(false, i, "NaN", 0, 3)) {
230 return Float.NaN;
231 }
232 throw invalidReal(name, isDouble);
233 }
234
235 /**
236 * Returns the closest double value to the real number in the string.

Callers 2

parseDoubleMethod · 0.95
parseFloatMethod · 0.95

Calls 4

invalidRealMethod · 0.95
lengthMethod · 0.65
charAtMethod · 0.65
regionMatchesMethod · 0.45

Tested by

no test coverage detected