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

Method declaration

packages/effect/src/encoding/Xml.ts:2067–2096  ·  view source on GitHub ↗
(s: string, i: number, t: number, end: number)

Source from the content-addressed store, hash-verified

2065 }
2066
2067 private declaration(s: string, i: number, t: number, end: number): number {
2068 this.checkSize(i, end + 2)
2069 const match = declarationPattern.exec(s.slice(t, end))
2070 if (match === null) throw this.syntax("invalid XML declaration", i)
2071 const encoding = match[3] ?? match[4]
2072 const standalone = match[5] ?? match[6]
2073 if (this.bytes && encoding !== undefined) {
2074 const lower = encoding.toLowerCase()
2075 if (wideEncodingPattern.test(lower) || (this.bom && (lower === "us-ascii" || lower === "iso-8859-1"))) {
2076 const evidence = this.bom ? "UTF-8 byte order mark" : "ASCII bytes of the declaration"
2077 throw this.syntax(`encoding ${encoding} does not match the ${evidence}`, i)
2078 }
2079 if (lower !== "utf-8" && lower !== "us-ascii") {
2080 throw this.error(
2081 "Unsupported",
2082 `encoding ${encoding} is not supported for byte input, decode the bytes to text first`,
2083 this.base + i
2084 )
2085 }
2086 this.ascii = lower === "us-ascii"
2087 }
2088 const event: { -readonly [K in keyof Declaration]: Declaration[K] } = {
2089 _tag: "Declaration",
2090 version: match[1] ?? match[2]
2091 }
2092 if (encoding !== undefined) event.encoding = encoding
2093 if (standalone !== undefined) event.standalone = standalone === "yes"
2094 this.out.push(event)
2095 return end + 2
2096 }
2097
2098 private cdata(s: string, i: number): number {
2099 const end = s.indexOf("]]>", i + 9)

Callers 1

processingInstructionMethod · 0.95

Calls 6

checkSizeMethod · 0.95
syntaxMethod · 0.95
errorMethod · 0.95
sliceMethod · 0.80
pushMethod · 0.65
execMethod · 0.45

Tested by

no test coverage detected