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

Function parseSegment

packages/effect/src/encoding/Xml.ts:2349–2359  ·  view source on GitHub ↗
(segment: string)

Source from the content-addressed store, hash-verified

2347type Segment = string | { readonly namespace: string | undefined; readonly localName: string }
2348
2349const parseSegment = (segment: string): Segment => {
2350 if (segment === "*" || isName(segment)) return segment
2351 // The last "}" ends the namespace: a namespace can contain "}", a local name cannot
2352 const close = segment.lastIndexOf("}")
2353 const localName = segment.slice(close + 1)
2354 if (segment.startsWith("{") && isName(localName) && !localName.includes(":")) {
2355 const namespace = segment.slice(1, close)
2356 return { namespace: namespace === "*" ? undefined : namespace, localName }
2357 }
2358 throw new Error(`Xml: invalid element name in path: ${JSON.stringify(segment)}`)
2359}
2360
2361const matches = (segment: Segment, event: StartElement): boolean =>
2362 typeof segment === "string" ?

Callers

nothing calls this directly

Calls 2

isNameFunction · 0.85
sliceMethod · 0.80

Tested by

no test coverage detected