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

Method processingInstruction

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

Source from the content-addressed store, hash-verified

2036 }
2037
2038 private processingInstruction(s: string, i: number): number {
2039 const end = s.indexOf("?>", i + 2)
2040 if (end === -1) return -1
2041 const t = scanName(s, i + 2, end)
2042 if (t === i + 2) throw this.syntax("invalid processing instruction target", i + 2)
2043 const target = s.slice(i + 2, t)
2044 if (isReservedTarget(target)) {
2045 if (target === "xml" && this.base + i === 0) return this.declaration(s, i, t, end)
2046 throw this.syntax(
2047 target === "xml" ?
2048 "the XML declaration is only allowed at the start of the document" :
2049 `processing instruction target ${target} is reserved`,
2050 i
2051 )
2052 }
2053 if (this.namespaces && target.includes(":")) {
2054 throw this.syntax(`processing instruction target ${target} contains a colon`, i)
2055 }
2056 let data = ""
2057 if (t < end) {
2058 if (!isSpace(s.charCodeAt(t))) throw this.syntax("expected whitespace after the target", t)
2059 data = normalizeLines(s.slice(skipSpace(s, t, end), end))
2060 }
2061 this.checkSize(i, end + 2)
2062 this.flushText()
2063 this.out.push({ _tag: "ProcessingInstruction", target, data })
2064 return end + 2
2065 }
2066
2067 private declaration(s: string, i: number, t: number, end: number): number {
2068 this.checkSize(i, end + 2)

Callers 1

markupMethod · 0.95

Calls 11

syntaxMethod · 0.95
declarationMethod · 0.95
checkSizeMethod · 0.95
flushTextMethod · 0.95
scanNameFunction · 0.85
isReservedTargetFunction · 0.85
isSpaceFunction · 0.85
normalizeLinesFunction · 0.85
skipSpaceFunction · 0.85
sliceMethod · 0.80
pushMethod · 0.65

Tested by

no test coverage detected