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

Function escapeText

packages/effect/src/encoding/Xml.ts:2466–2480  ·  view source on GitHub ↗
(s: string)

Source from the content-addressed store, hash-verified

2464// none; the rest is copied in runs between escapes. Invalid characters are
2465// kept, so that the writer can check them in the output.
2466const escapeText = (s: string): string => {
2467 const first = s.search(textSpecial)
2468 if (first === -1) return s
2469 let out = ""
2470 let last = 0
2471 for (let i = first; i < s.length; i++) {
2472 const c = s.charCodeAt(i)
2473 const escaped = c === AMPERSAND ? "&amp;" : c === LT ? "&lt;" : c === GT ? "&gt;" : c === CR ? "&#13;" : undefined
2474 if (escaped !== undefined) {
2475 out += s.slice(last, i) + escaped
2476 last = i + 1
2477 }
2478 }
2479 return out + s.slice(last)
2480}
2481
2482const escapeAttribute = (s: string): string => {
2483 const first = s.search(attributeSpecials)

Callers 1

writeMethod · 0.70

Calls 2

searchMethod · 0.80
sliceMethod · 0.80

Tested by

no test coverage detected