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

Method call

src/main/java/org/dynjs/runtime/builtins/ParseInt.java:31–114  ·  view source on GitHub ↗
(ExecutionContext context, Object self, Object... arguments)

Source from the content-addressed store, hash-verified

29 }
30
31 @Override
32 public Object call(ExecutionContext context, Object self, Object... arguments) {
33 String inputString = Types.toString(context, arguments[0]);
34
35 int len = inputString.length();
36 int firstNonWhitespace = -1;
37
38 for (int i = 0; i < len; ++i) {
39 char c = inputString.charAt(i);
40 if (Types.isWhitespace(c)) {
41 // nothing
42 } else {
43 firstNonWhitespace = i;
44 break;
45 }
46 }
47
48 String s = null;
49 int sign = 1;
50
51 if (firstNonWhitespace < 0) {
52 s = "";
53 } else {
54 s = inputString.substring(firstNonWhitespace);
55 char c = s.charAt(0);
56 if (c == '-') {
57 sign = -1;
58 }
59 if (c == '-' || c == '+') {
60 s = s.substring(1);
61 }
62 }
63
64
65 long r = Types.toInt32(context, arguments[1]);
66
67 boolean stripPrefix = true;
68
69 if (r != 0) {
70 if (r < 2 || r > 36) {
71 return Double.NaN;
72 }
73 if (r != 16) {
74 stripPrefix = false;
75 }
76 } else {
77 r = 10;
78 }
79
80 if (stripPrefix) {
81 if (s.startsWith("0X") || s.startsWith("0x")) {
82 s = s.substring(2);
83 r = 16;
84 }
85 }
86
87 len = s.length();
88 int firstInvalidDigit = -1;

Callers

nothing calls this directly

Calls 5

toStringMethod · 0.95
isWhitespaceMethod · 0.95
toInt32Method · 0.95
isRadixDigitMethod · 0.95
lengthMethod · 0.80

Tested by

no test coverage detected