MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / decodeBasicString

Function decodeBasicString

src/installer/targets/toml.ts:494–515  ·  view source on GitHub ↗

The value of a TOML basic string's body, or null for an invalid escape.

(raw: string)

Source from the content-addressed store, hash-verified

492
493/** The value of a TOML basic string's body, or null for an invalid escape. */
494function decodeBasicString(raw: string): string | null {
495 let out = '';
496 for (let i = 0; i < raw.length; i++) {
497 if (raw[i] !== '\\') {
498 out += raw[i];
499 continue;
500 }
501 const esc = raw[++i] ?? '';
502 if (esc in SIMPLE_ESCAPES) {
503 out += SIMPLE_ESCAPES[esc];
504 continue;
505 }
506 const width = esc === 'x' ? 2 : esc === 'u' ? 4 : esc === 'U' ? 8 : 0;
507 const hex = raw.slice(i + 1, i + 1 + width);
508 if (width === 0 || hex.length !== width || !/^[0-9A-Fa-f]+$/.test(hex)) return null;
509 const codePoint = parseInt(hex, 16);
510 if (codePoint > 0x10ffff || (codePoint >= 0xd800 && codePoint <= 0xdfff)) return null;
511 out += String.fromCodePoint(codePoint);
512 i += width;
513 }
514 return out;
515}
516
517type MultilineStringDelimiter = '"""' | "'''";
518

Callers 1

parseKeyPartFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected