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

Function escapeAttribute

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

Source from the content-addressed store, hash-verified

2480}
2481
2482const escapeAttribute = (s: string): string => {
2483 const first = s.search(attributeSpecials)
2484 if (first === -1) return s
2485 let out = ""
2486 let last = 0
2487 for (let i = first; i < s.length; i++) {
2488 const c = s.charCodeAt(i)
2489 const escaped = c === AMPERSAND ?
2490 "&amp;" :
2491 c === LT ?
2492 "&lt;" :
2493 c === DQUOTE ?
2494 "&quot;" :
2495 c === TAB ?
2496 "&#9;" :
2497 c === LF ?
2498 "&#10;" :
2499 c === CR ?
2500 "&#13;" :
2501 undefined
2502 if (escaped !== undefined) {
2503 out += s.slice(last, i) + escaped
2504 last = i + 1
2505 }
2506 }
2507 return out + s.slice(last)
2508}
2509
2510const checkChars = (what: string, s: string): void => {
2511 const invalid = searchInvalid(s)

Callers 1

writeMethod · 0.70

Calls 2

searchMethod · 0.80
sliceMethod · 0.80

Tested by

no test coverage detected