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

Function fx_parseURLPercentEncode

modules/data/url/url.c:1330–1392  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1328}
1329
1330void fx_parseURLPercentEncode(txMachine* the, txInteger c, txStringStream* dst, const char* set)
1331{
1332 txSize length;
1333 txString string;
1334 if (c < 0x80) {
1335 if (c_read8(set + c))
1336 length = 3;
1337 else
1338 length = 1;
1339 }
1340 else if (c < 0x800) {
1341 length = 6;
1342 }
1343 else if (c < 0x10000) {
1344 length = 9;
1345 }
1346 else {
1347 length = 12;
1348 }
1349 if (dst->offset + length >= dst->size) {
1350 txSize size = fxAddChunkSizes(the, dst->offset, length + 1);
1351 txString string = fxRenewChunk(the, dst->slot->value.string, size);
1352 if (!string) {
1353 string = (txString)fxNewChunk(the, size);
1354 c_memcpy(string, dst->slot->value.string, dst->offset);
1355 }
1356 dst->slot->value.string = string;
1357 dst->size = size;
1358 }
1359 string = dst->slot->value.string + dst->offset;
1360 if (length == 1)
1361 *string++ = (char)c;
1362 else if (length == 3) {
1363 *string++ = '%';
1364 string = fxStringifyHexEscape(string, c);
1365 }
1366 else if (length == 6) {
1367 *string++ = '%';
1368 string = fxStringifyHexEscape(string, 0xC0 | (c >> 6));
1369 *string++ = '%';
1370 string = fxStringifyHexEscape(string, 0x80 | (c & 0x3F));
1371 }
1372 else if (length == 9) {
1373 *string++ = '%';
1374 string = fxStringifyHexEscape(string, 0xE0 | (c >> 12));
1375 *string++ = '%';
1376 string = fxStringifyHexEscape(string, 0x80 | ((c >> 6) & 0x3F));
1377 *string++ = '%';
1378 string = fxStringifyHexEscape(string, 0x80 | (c & 0x3F));
1379 }
1380 else {
1381 *string++ = '%';
1382 string = fxStringifyHexEscape(string, 0xF0 | (c >> 18));
1383 *string++ = '%';
1384 string = fxStringifyHexEscape(string, 0x80 | ((c >> 12) & 0x3F));
1385 *string++ = '%';
1386 string = fxStringifyHexEscape(string, 0x80 | ((c >> 6) & 0x3F));
1387 *string++ = '%';

Callers 2

fx_parseURLFunction · 0.85

Calls 3

fxRenewChunkFunction · 0.85
fxNewChunkFunction · 0.85
fxStringifyHexEscapeFunction · 0.85

Tested by

no test coverage detected