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

Function doubleQuote

packages/effect/src/encoding/Yaml.ts:1657–1685  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

1655 code < 0x100 ? `\\x${code.toString(16).padStart(2, "0")}` : `\\u${code.toString(16).padStart(4, "0")}`
1656
1657const doubleQuote = (text: string): string => {
1658 let output = ""
1659 let start = 0
1660 for (let index = 0; index < text.length; index++) {
1661 const code = text.charCodeAt(index)
1662 let escape: string | undefined
1663 if (code === 0x22 || code === 0x5c || code < 0x20 || (code >= 0x7f && code <= 0x9f) || code >= 0x2028) {
1664 if (code >= 0xd800 && code <= 0xdfff) {
1665 // A surrogate pair is copied as is; a lone surrogate is escaped.
1666 const next = text.charCodeAt(index + 1)
1667 if (code <= 0xdbff && next >= 0xdc00 && next <= 0xdfff) {
1668 index++
1669 continue
1670 }
1671 escape = escapeCode(code)
1672 } else if (code === 0x2028 || code === 0x2029 || code === 0xfeff || code === 0xfffe || code === 0xffff) {
1673 escape = code === 0x2028 ? "\\L" : code === 0x2029 ? "\\P" : escapeCode(code)
1674 } else if (code < 0x2028) {
1675 const character = text[index]
1676 escape = hasOwn.call(doubleQuoteEscapes, character) ? doubleQuoteEscapes[character] : escapeCode(code)
1677 }
1678 }
1679 if (escape !== undefined) {
1680 output += text.slice(start, index) + escape
1681 start = index + 1
1682 }
1683 }
1684 return `"${output}${text.slice(start)}"`
1685}
1686
1687class PrintError extends Error {}
1688

Callers 2

printSingleLineFunction · 0.85
printKeyFunction · 0.85

Calls 3

escapeCodeFunction · 0.85
sliceMethod · 0.80
callMethod · 0.45

Tested by

no test coverage detected