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

Function fxStringToNumber

xs/sources/xsdtoa.c:6651–6712  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6649}
6650
6651txNumber fxStringToNumber(void* the, txString theString, txFlag whole)
6652{
6653 txNumber result = whole ? 0 : NAN;
6654 txString p = fxSkipSpaces(theString), q;
6655 char c = *p;
6656 if (c) {
6657 txU4 d = *(p + 1);
6658 if (whole && (c == '0') && ((d == 'B') || (d == 'b') || (d == 'O') || (d == 'o') || (d == 'X') || (d == 'x'))) {
6659 p += 2;
6660 q = p;
6661 if ((d == 'B') || (d == 'b')) {
6662 while ((c = *p)) {
6663 if (('0' <= c) && (c <= '1'))
6664 result = (result * 2) + (c - '0');
6665 else
6666 break;
6667 p++;
6668 }
6669 }
6670 else if ((d == 'O') || (d == 'o')) {
6671 while ((c = *p)) {
6672 if (('0' <= c) && (c <= '7'))
6673 result = (result * 8) + (c - '0');
6674 else
6675 break;
6676 p++;
6677 }
6678 }
6679 else if ((d == 'X') || (d == 'x')) {
6680 while ((c = *p)) {
6681 if (('0' <= c) && (c <= '9'))
6682 result = (result * 16) + (c - '0');
6683 else if (('a' <= c) && (c <= 'f'))
6684 result = (result * 16) + (10 + c - 'a');
6685 else if (('A' <= c) && (c <= 'F'))
6686 result = (result * 16) + (10 + c - 'A');
6687 else
6688 break;
6689 p++;
6690 }
6691 }
6692 if (p == q)
6693 result = NAN;
6694 else
6695 q = p;
6696 }
6697 else {
6698 ThInfo DTOA;
6699 fxDTOASetup(the, &DTOA);
6700 result = strtod2(p, &q, &DTOA);
6701 fxDTOACleanup(the, &DTOA);
6702 if ((p == q) && !whole)
6703 result = NAN;
6704 }
6705 if (whole) {
6706 p = fxSkipSpaces(q);
6707 if (*p)
6708 result = NAN;

Callers 10

xs_outline_SVGPath_nextFunction · 0.85
fxGetNextNumberEFunction · 0.85
fxToIntegerFunction · 0.85
fxToNumberFunction · 0.85
fxToUnsignedFunction · 0.85
fxIsCanonicalIndexFunction · 0.85
fx_parseFloatFunction · 0.85
fxParseJSONTokenFunction · 0.85
fxStringToIndexFunction · 0.85

Calls 3

fxSkipSpacesFunction · 0.85
fxDTOASetupFunction · 0.85
fxDTOACleanupFunction · 0.85

Tested by

no test coverage detected