MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / fx_parseInt

Function fx_parseInt

xs/sources/xsNumber.c:127–207  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

125}
126
127void fx_parseInt(txMachine* the)
128{
129 txInteger aRadix, aDigit;
130 txNumber aSign, aResult;
131 txString s, r;
132 char c;
133
134 if (mxArgc < 1) {
135 mxResult->value.number = C_NAN;
136 mxResult->kind = XS_NUMBER_KIND;
137 return;
138 }
139 fxToString(the, mxArgv(0));
140 if (mxArgc > 1) {
141 aRadix = fxToInteger(the, mxArgv(1));
142 if (aRadix) {
143 if ((aRadix < 2) || (36 < aRadix)) {
144 mxResult->kind = XS_NUMBER_KIND;
145 mxResult->value.number = C_NAN;
146 return;
147 }
148 }
149 }
150 else
151 aRadix = 0;
152 s = fxSkipSpaces(mxArgv(0)->value.string);
153 c = *s;
154 aSign = 1;
155 if (c == '+')
156 s++;
157 else if (c == '-') {
158 s++;
159 aSign = -1;
160 }
161 if ((*s == '0') && ((*(s + 1) == 'x') || (*(s + 1) == 'X'))) {
162 if ((aRadix == 0) || (aRadix == 16)) {
163 aRadix = 16;
164 s += 2;
165 }
166 }
167 /*if (*s == '0') {
168 if ((aRadix == 0) || (aRadix == 8)) {
169 aRadix = 8;
170 }
171 }*/
172 if (aRadix == 0)
173 aRadix = 10;
174 aResult = 0;
175 r = s;
176 while ((c = *s)) {
177 if (('0' <= c) && (c <= '9'))
178 aDigit = c - '0';
179 else if (('a' <= c) && (c <= 'z'))
180 aDigit = 10 + c - 'a';
181 else if (('A' <= c) && (c <= 'Z'))
182 aDigit = 10 + c - 'A';
183 else
184 break;

Callers

nothing calls this directly

Calls 3

fxToStringFunction · 0.85
fxToIntegerFunction · 0.85
fxSkipSpacesFunction · 0.85

Tested by

no test coverage detected