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

Function fx_parseURLHostIPv6

modules/data/url/url.c:1046–1207  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1044}
1045
1046txBoolean fx_parseURLHostIPv6(txMachine* the, txStringStream* src, txInteger from, txInteger to, txStringStream* dst)
1047{
1048 txU2 pieces[8];
1049 txInteger pieceIndex = 0;
1050 txInteger compress = -1;
1051 txU2 value;
1052 txInteger length;
1053 txInteger numbersSeen;
1054 txString p = src->slot->value.string + from;
1055 txString q = src->slot->value.string + to;
1056 c_memset(pieces, 0, sizeof(pieces));
1057 if (p[0] == ':') {
1058 if (p[1] != ':')
1059 return 0;
1060 p += 2;
1061 pieceIndex++;
1062 compress = pieceIndex;
1063 }
1064 while (p < q) {
1065 if (pieceIndex == 8)
1066 return 0;
1067 if (*p == ':') {
1068 if (compress != -1)
1069 return 0;
1070 p++;
1071 pieceIndex++;
1072 compress = pieceIndex;
1073 continue;
1074 }
1075 value = 0;
1076 length = 0;
1077 while ((p < q) && (length < 4)) {
1078 if (('0' <= *p) && (*p <= '9'))
1079 value = (value * 16) + (*p - '0');
1080 else if (('a' <= *p) && (*p <= 'f'))
1081 value = (value * 16) + (10 + *p - 'a');
1082 else if (('A' <= *p) && (*p <= 'F'))
1083 value = (value * 16) + (10 + *p - 'A');
1084 else
1085 break;
1086 length++;
1087 p++;
1088 }
1089 if (*p == '.') {
1090 if (length == 0)
1091 return 0;
1092 p -= length;
1093 if (pieceIndex > 6)
1094 return 0;
1095 numbersSeen = 0;
1096 while (p < q) {
1097 txInteger ipv4Piece = -1;
1098 if (numbersSeen > 0) {
1099 if ((*p == '.') && (numbersSeen < 4))
1100 p++;
1101 else
1102 return 0;
1103 }

Callers 1

fx_parseURLHostFunction · 0.85

Calls 1

fx_parseURLEncodeFunction · 0.85

Tested by

no test coverage detected