MCPcopy Create free account
hub / github.com/dynjs/dynjs / call

Method call

src/main/java/org/dynjs/runtime/builtins/ParseFloat.java:14–93  ·  view source on GitHub ↗
(ExecutionContext context, Object self, Object... args)

Source from the content-addressed store, hash-verified

12 }
13
14 @Override
15 public Object call(ExecutionContext context, Object self, Object... args) {
16 String text = Types.toString(context, args[0]);
17
18 if (text.equals("")) {
19 return Double.NaN;
20 }
21
22 int len = text.length();
23 int firstNonWhitespace = 0;
24
25 for (int i = 0; i < len; ++i) {
26 char c = text.charAt(i);
27 if (Types.isWhitespace(c)) {
28 // nothing
29 } else {
30 firstNonWhitespace = i;
31 break;
32 }
33 }
34
35 if (text.substring(firstNonWhitespace).startsWith("Infinity") || text.substring(firstNonWhitespace).startsWith("+Infinity")) {
36 return Double.POSITIVE_INFINITY;
37 }
38
39 if (text.substring(firstNonWhitespace).startsWith("-Infinity")) {
40 return Double.NEGATIVE_INFINITY;
41 }
42
43 int digitSearchStart = firstNonWhitespace;
44 int lastDigit = firstNonWhitespace;
45
46 if ((text.charAt(firstNonWhitespace) == '-') || (text.charAt(firstNonWhitespace) == '+')) {
47 ++digitSearchStart;
48 }
49
50 boolean dotSeen = false;
51
52 for (int i = digitSearchStart; i < len; ++i) {
53 char c = text.charAt(i);
54 if (c >= '0' && c <= '9') {
55 lastDigit = i;
56 } else {
57 if (!dotSeen && c == '.') {
58 lastDigit = i;
59 dotSeen = true;
60 } else {
61 break;
62 }
63 }
64 }
65
66 if (text.length() > (lastDigit + 1)) {
67 digitSearchStart = lastDigit + 1;
68 if (text.charAt(digitSearchStart) == 'e' || text.charAt(digitSearchStart) == 'E') {
69 ++digitSearchStart;
70 if ((text.charAt(digitSearchStart) == '-') || (text.charAt(digitSearchStart) == '+')) {
71 ++digitSearchStart;

Callers

nothing calls this directly

Calls 3

toStringMethod · 0.95
isWhitespaceMethod · 0.95
lengthMethod · 0.80

Tested by

no test coverage detected