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

Method reference

packages/effect/src/encoding/Xml.ts:1653–1683  ·  view source on GitHub ↗
(raw: string, amp: number, semicolon: number, offset: number)

Source from the content-addressed store, hash-verified

1651
1652 // Decodes the reference `raw[amp, semicolon]`
1653 private reference(raw: string, amp: number, semicolon: number, offset: number): string {
1654 const c = raw.charCodeAt(amp + 1)
1655 // The predefined entities, without slicing their names
1656 if (c === 97) {
1657 if (raw.startsWith("amp;", amp + 1)) return "&"
1658 if (raw.startsWith("apos;", amp + 1)) return "'"
1659 } else if (c === 108) {
1660 if (raw.startsWith("lt;", amp + 1)) return "<"
1661 } else if (c === 103) {
1662 if (raw.startsWith("gt;", amp + 1)) return ">"
1663 } else if (c === 113) {
1664 if (raw.startsWith("quot;", amp + 1)) return "\""
1665 }
1666 if (c === HASH) {
1667 const hex = raw.charCodeAt(amp + 2) === LOWER_X
1668 const digits = raw.slice(amp + (hex ? 3 : 2), semicolon)
1669 const code = (hex ? hexDigits : decimalDigits).test(digits) ? parseInt(digits, hex ? 16 : 10) : -1
1670 if (!isChar(code)) throw this.syntax("invalid character reference", offset + amp)
1671 return String.fromCodePoint(code)
1672 }
1673 const name = raw.slice(amp + 1, semicolon)
1674 if (!isName(name)) throw this.syntax("invalid reference", offset + amp)
1675 if (this.doctype) {
1676 throw this.error(
1677 "Unsupported",
1678 `entity references other than the predefined entities are not supported: &${name};`,
1679 this.base + offset + amp
1680 )
1681 }
1682 throw this.syntax(`undefined entity &${name};`, offset + amp)
1683 }
1684
1685 // Parses the markup at `i`, and returns its end or -1 when it is incomplete
1686 private markup(s: string, i: number): number {

Callers 4

decodeTextMethod · 0.95
convertDraft07Function · 0.80
convertReferenceFunction · 0.80
convertOpenApi30Function · 0.80

Calls 5

syntaxMethod · 0.95
errorMethod · 0.95
isCharFunction · 0.85
isNameFunction · 0.85
sliceMethod · 0.80

Tested by

no test coverage detected