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

Function fx_unescape

xs/sources/xsGlobal.c:413–482  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

411}
412
413void fx_unescape(txMachine* the)
414{
415 txString src;
416 txInteger length;
417 char c;
418 txInteger d;
419 txString dst;
420
421 if (mxArgc < 1) {
422 mxResult->value.string = mxUndefinedString.value.string;
423 mxResult->kind = mxUndefinedString.kind;
424 return;
425 }
426 src = fxToString(the, mxArgv(0));
427 length = 0;
428 while ((c = c_read8(src++))) {
429 if (c == '%') {
430 c = c_read8(src++);
431 if (c == 'u') {
432 if (fxParseUnicodeEscape(&src, &d, 0, '%'))
433 length += mxStringByteLength(d);
434 else
435 length += 2;
436 }
437 else {
438 src--;
439 if (fxParseHexEscape(&src, &d))
440 length += mxStringByteLength(d);
441 else
442 length += 1;
443 }
444 }
445 else
446 length += 1;
447 }
448 length += 1;
449 if (length == (src - mxArgv(0)->value.string)) {
450 mxResult->value.string = mxArgv(0)->value.string;
451 mxResult->kind = mxArgv(0)->kind;
452 return;
453 }
454 mxResult->value.string = fxNewChunk(the, length);
455 mxResult->kind = XS_STRING_KIND;
456 src = mxArgv(0)->value.string;
457 dst = mxResult->value.string;
458 while ((c = c_read8(src++))) {
459 if (c == '%') {
460 c = c_read8(src++);
461 d = 0;
462 if (c == 'u') {
463 if (fxParseUnicodeEscape(&src, &d, 0, '%'))
464 dst = mxStringByteEncode(dst, d);
465 else {
466 *dst++ = '%';
467 *dst++ = 'u';
468 }
469 }
470 else {

Callers

nothing calls this directly

Calls 4

fxToStringFunction · 0.85
fxParseUnicodeEscapeFunction · 0.85
fxParseHexEscapeFunction · 0.85
fxNewChunkFunction · 0.85

Tested by

no test coverage detected