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

Function fxStringToBigInt

xs/sources/xsBigInt.c:753–825  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

751}
752
753txBigInt* fxStringToBigInt(txMachine* the, txSlot* slot, txFlag whole)
754{
755 txString s = slot->value.string;
756 txString p = fxSkipSpaces(s);
757 txSize offset, length;
758 txInteger sign = 0;
759 txBigInt bigint = {.sign=0, .size=0, .data=C_NULL };
760 char c = *p;
761 if (c == '0') {
762 char d = *(p + 1);
763 if (whole && ((d == 'B') || (d == 'b') || (d == 'O') || (d == 'o') || (d == 'X') || (d == 'x'))) {
764 p += 2;
765 offset = mxPtrDiff(p - s);
766 if ((d == 'B') || (d == 'b')) {
767 while (((c = *p)) && ('0' <= c) && (c <= '1'))
768 p++;
769 length = mxPtrDiff(p - s - offset);
770 p = fxSkipSpaces(p);
771 if ((length > 0) && (*p == 0)) {
772 bigint.data = fxNewChunk(the, fxBigIntMaximumB(length));
773 fxBigIntParseB(&bigint, slot->value.string + offset, length);
774 }
775 }
776 else if ((d == 'O') || (d == 'o')) {
777 while (((c = *p)) && ('0' <= c) && (c <= '7'))
778 p++;
779 length = mxPtrDiff(p - s - offset);
780 p = fxSkipSpaces(p);
781 if ((length > 0) && (*p == 0)) {
782 bigint.data = fxNewChunk(the, fxBigIntMaximumO(length));
783 fxBigIntParseO(&bigint, slot->value.string + offset, length);
784 }
785 }
786 else if ((d == 'X') || (d == 'x')) {
787 while (((c = *p)) && ((('0' <= c) && (c <= '9')) || (('a' <= c) && (c <= 'f')) || (('A' <= c) && (c <= 'F'))))
788 p++;
789 length = mxPtrDiff(p - s - offset);
790 p = fxSkipSpaces(p);
791 if ((length > 0) && (*p == 0)) {
792 bigint.data = fxNewChunk(the, fxBigIntMaximumX(length));
793 fxBigIntParseX(&bigint, slot->value.string + offset, length);
794 }
795 }
796 goto bail;
797 }
798 }
799 if (c == '-') {
800 sign = 1;
801 p++;
802 }
803 else if (c == '+') {
804 p++;
805 }
806 offset = mxPtrDiff(p - s);
807 while (((c = *p)) && ('0' <= c) && (c <= '9'))
808 p++;
809 length = mxPtrDiff(p - s - offset);
810 p = fxSkipSpaces(p);

Callers 2

fxBigIntCompareFunction · 0.85
fxToBigIntFunction · 0.85

Calls 10

fxSkipSpacesFunction · 0.85
fxNewChunkFunction · 0.85
fxBigIntMaximumBFunction · 0.85
fxBigIntParseBFunction · 0.85
fxBigIntMaximumOFunction · 0.85
fxBigIntParseOFunction · 0.85
fxBigIntMaximumXFunction · 0.85
fxBigIntParseXFunction · 0.85
fxBigIntMaximumFunction · 0.85
fxBigIntParseFunction · 0.85

Tested by

no test coverage detected