MCPcopy Create free account
hub / github.com/Effect-TS/effect / parseDoubleQuoted

Function parseDoubleQuoted

packages/effect/src/encoding/Yaml.ts:466–516  ·  view source on GitHub ↗
(input: string)

Source from the content-addressed store, hash-verified

464}
465
466const parseDoubleQuoted = (input: string): string => {
467 if (!input.endsWith("\"") || input.length < 2) {
468 throw new SyntaxError("Unterminated double-quoted YAML string")
469 }
470 let output = ""
471 for (let index = 1; index < input.length - 1; index++) {
472 const character = input[index]
473 if (character !== "\\") {
474 output += character
475 continue
476 }
477 const escape = input[++index]
478 const escapes: Record<string, string> = {
479 "0": "\0",
480 a: "\x07",
481 b: "\b",
482 t: "\t",
483 n: "\n",
484 v: "\v",
485 f: "\f",
486 r: "\r",
487 e: "\x1b",
488 // YAML 1.2.2 §5.7: a backslash followed by a literal tab also escapes a tab.
489 "\t": "\t",
490 " ": " ",
491 "\"": "\"",
492 "/": "/",
493 "\\": "\\",
494 N: "\u0085",
495 _: "\u00a0",
496 L: "\u2028",
497 P: "\u2029"
498 }
499 if (hasOwn.call(escapes, escape)) {
500 output += escapes[escape]
501 continue
502 }
503 if (escape === "x" || escape === "u" || escape === "U") {
504 const length = escape === "x" ? 2 : escape === "u" ? 4 : 8
505 const hex = input.slice(index + 1, index + 1 + length)
506 if (!new RegExp(`^[0-9A-Fa-f]{${length}}$`).test(hex)) {
507 throw new SyntaxError("Invalid unicode escape in YAML string")
508 }
509 output += String.fromCodePoint(Number.parseInt(hex, 16))
510 index += length
511 continue
512 }
513 throw new SyntaxError(`Invalid YAML escape '\\${escape}'`)
514 }
515 return output
516}
517
518const parseScalar = (input: string): unknown => {
519 const value = trimWhite(input)

Callers 1

parseScalarFunction · 0.85

Calls 2

sliceMethod · 0.80
callMethod · 0.45

Tested by

no test coverage detected