| 125 | } |
| 126 | |
| 127 | void 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; |
nothing calls this directly
no test coverage detected