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

Method doctypeDeclaration

packages/effect/src/encoding/Xml.ts:2107–2141  ·  view source on GitHub ↗
(s: string, i: number)

Source from the content-addressed store, hash-verified

2105 }
2106
2107 private doctypeDeclaration(s: string, i: number): number {
2108 if (this.state !== PROLOG || this.doctype) {
2109 throw this.syntax("a DOCTYPE is only allowed once, before the root element", i)
2110 }
2111 const scanner = new Scanner()
2112 scanner.reset(S_DOCTYPE)
2113 const end = scanner.scan(s, i + 9)
2114 if (end === -1) return -1
2115 this.checkSize(i, end)
2116 this.doctype = true
2117 let j = this.space(s, i + 9, end)
2118 const nameEnd = this.name(s, j, end)
2119 const event: { -readonly [K in keyof Doctype]: Doctype[K] } = { _tag: "Doctype", name: s.slice(j, nameEnd) }
2120 j = skipSpace(s, nameEnd, end)
2121 if (j > nameEnd && (s.startsWith("PUBLIC", j) || s.startsWith("SYSTEM", j))) {
2122 if (s.charCodeAt(j) === 80) {
2123 // Whitespace in public identifiers is normalized for matching
2124 event.publicId = this.publicLiteral(s, this.space(s, j + 6, end), end).replace(publicIdWhitespace, " ").trim()
2125 j = this.literalEnd
2126 }
2127 event.systemId = normalizeLines(
2128 this.literal(s, this.space(s, j + (event.publicId === undefined ? 6 : 0), end), end)
2129 )
2130 j = skipSpace(s, this.literalEnd, end)
2131 }
2132 if (s.charCodeAt(j) === LBRACKET) {
2133 // The scanner skips the internal subset, whose declarations are not
2134 // checked, and ends the token early only at malformed markup
2135 if (scanner.state !== S_AFTER_SUBSET) throw this.syntax("invalid markup in the internal subset", end)
2136 j = skipSpace(s, s.lastIndexOf("]", end - 1) + 1, end)
2137 }
2138 if (j !== end - 1 || s.charCodeAt(j) !== GT) throw this.syntax("invalid DOCTYPE", j)
2139 this.out.push(event)
2140 return end
2141 }
2142
2143 // Skips the whitespace that is required at `i`
2144 private space(s: string, i: number, end: number): number {

Callers 1

markupMethod · 0.95

Calls 14

syntaxMethod · 0.95
resetMethod · 0.95
scanMethod · 0.95
checkSizeMethod · 0.95
spaceMethod · 0.95
nameMethod · 0.95
publicLiteralMethod · 0.95
literalMethod · 0.95
skipSpaceFunction · 0.85
normalizeLinesFunction · 0.85
sliceMethod · 0.80
trimMethod · 0.80

Tested by

no test coverage detected