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

Method startTag

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

Source from the content-addressed store, hash-verified

1710 }
1711
1712 private startTag(s: string, i: number): number {
1713 const n = s.length
1714 if (this.state === EPILOG) throw this.syntax("content after the root element", i)
1715 let j = scanName(s, i + 1, n)
1716 if (j === i + 1) throw this.syntax("invalid element name", i + 1)
1717 if (j >= n) return -1
1718 const name = copyString(s.slice(i + 1, j))
1719 let attributes: Record<string, string> | undefined
1720 let shape: Array<string> | null | undefined
1721 let index = 0
1722 let selfClosing = false
1723 while (true) {
1724 let c = s.charCodeAt(j)
1725 const space = isSpace(c)
1726 if (space) {
1727 j = skipSpace(s, j, n)
1728 if (j >= n) return -1
1729 c = s.charCodeAt(j)
1730 }
1731 if (c === GT) {
1732 j++
1733 break
1734 }
1735 if (c === SLASH) {
1736 if (j + 1 >= n) return -1
1737 if (s.charCodeAt(j + 1) !== GT) throw this.syntax("expected \">\"", j + 1)
1738 j += 2
1739 selfClosing = true
1740 break
1741 }
1742 if (!space) throw this.syntax("expected whitespace, \">\" or \"/>\"", j)
1743 const nameStart = j
1744 j = scanName(s, j, n)
1745 if (j === nameStart) throw this.syntax("invalid attribute name", j)
1746 if (j >= n) return -1
1747 const attribute = s.slice(nameStart, j)
1748 j = skipSpace(s, j, n)
1749 if (j >= n) return -1
1750 if (s.charCodeAt(j) !== EQUALS) throw this.syntax("expected \"=\"", j)
1751 j = skipSpace(s, j + 1, n)
1752 if (j >= n) return -1
1753 const quote = s.charCodeAt(j)
1754 if (quote !== DQUOTE && quote !== SQUOTE) throw this.syntax("expected a quoted attribute value", j)
1755 const close = s.indexOf(quote === DQUOTE ? "\"" : "'", j + 1)
1756 if (close === -1) {
1757 const lt = s.indexOf("<", j + 1)
1758 if (lt !== -1) throw this.syntax("\"<\" is not allowed in attribute values", lt)
1759 return -1
1760 }
1761 const value = this.attributeValue(s, j + 1, close)
1762 if (attributes === undefined) {
1763 shape = this.shapes.get(name)
1764 if (shape === undefined && this.shapes.size < maxShapes) {
1765 shape = []
1766 this.shapes.set(name, shape)
1767 }
1768 attributes = shape === undefined || shape === null || shape.length > maxFastAttributes ?
1769 Object.create(null) as Record<string, string> :

Callers 1

markupMethod · 0.95

Calls 15

syntaxMethod · 0.95
attributeValueMethod · 0.95
checkSizeMethod · 0.95
errorMethod · 0.95
openScopeMethod · 0.95
flushTextMethod · 0.95
countMethod · 0.95
endElementMethod · 0.95
scanNameFunction · 0.85
copyStringFunction · 0.85
isSpaceFunction · 0.85
skipSpaceFunction · 0.85

Tested by

no test coverage detected