add sink and lent annotations for xmltree and streams (#18037)
This commit is contained in:
parent
fac5bae7b7
commit
6e0fe965da
2 changed files with 16 additions and 16 deletions
|
|
@ -1252,7 +1252,7 @@ else: # after 1.3 or JS not defined
|
||||||
var s = StringStream(s)
|
var s = StringStream(s)
|
||||||
s.data = ""
|
s.data = ""
|
||||||
|
|
||||||
proc newStringStream*(s: string = ""): owned StringStream =
|
proc newStringStream*(s: sink string = ""): owned StringStream =
|
||||||
## Creates a new stream from the string `s`.
|
## Creates a new stream from the string `s`.
|
||||||
##
|
##
|
||||||
## See also:
|
## See also:
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ proc newXmlNode(kind: XmlNodeKind): XmlNode =
|
||||||
## Creates a new ``XmlNode``.
|
## Creates a new ``XmlNode``.
|
||||||
result = XmlNode(k: kind)
|
result = XmlNode(k: kind)
|
||||||
|
|
||||||
proc newElement*(tag: string): XmlNode =
|
proc newElement*(tag: sink string): XmlNode =
|
||||||
## Creates a new ``XmlNode`` of kind ``xnElement`` with the given `tag`.
|
## Creates a new ``XmlNode`` of kind ``xnElement`` with the given `tag`.
|
||||||
##
|
##
|
||||||
## See also:
|
## See also:
|
||||||
|
|
@ -89,7 +89,7 @@ proc newElement*(tag: string): XmlNode =
|
||||||
result.s = @[]
|
result.s = @[]
|
||||||
# init attributes lazily to save memory
|
# init attributes lazily to save memory
|
||||||
|
|
||||||
proc newText*(text: string): XmlNode =
|
proc newText*(text: sink string): XmlNode =
|
||||||
## Creates a new ``XmlNode`` of kind ``xnText`` with the text `text`.
|
## Creates a new ``XmlNode`` of kind ``xnText`` with the text `text`.
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
var b = newText("my text")
|
var b = newText("my text")
|
||||||
|
|
@ -99,13 +99,13 @@ proc newText*(text: string): XmlNode =
|
||||||
result = newXmlNode(xnText)
|
result = newXmlNode(xnText)
|
||||||
result.fText = text
|
result.fText = text
|
||||||
|
|
||||||
proc newVerbatimText*(text: string): XmlNode {.since: (1, 3).} =
|
proc newVerbatimText*(text: sink string): XmlNode {.since: (1, 3).} =
|
||||||
## Creates a new ``XmlNode`` of kind ``xnVerbatimText`` with the text `text`.
|
## Creates a new ``XmlNode`` of kind ``xnVerbatimText`` with the text `text`.
|
||||||
## **Since**: Version 1.3.
|
## **Since**: Version 1.3.
|
||||||
result = newXmlNode(xnVerbatimText)
|
result = newXmlNode(xnVerbatimText)
|
||||||
result.fText = text
|
result.fText = text
|
||||||
|
|
||||||
proc newComment*(comment: string): XmlNode =
|
proc newComment*(comment: sink string): XmlNode =
|
||||||
## Creates a new ``XmlNode`` of kind ``xnComment`` with the text `comment`.
|
## Creates a new ``XmlNode`` of kind ``xnComment`` with the text `comment`.
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
var c = newComment("my comment")
|
var c = newComment("my comment")
|
||||||
|
|
@ -115,7 +115,7 @@ proc newComment*(comment: string): XmlNode =
|
||||||
result = newXmlNode(xnComment)
|
result = newXmlNode(xnComment)
|
||||||
result.fText = comment
|
result.fText = comment
|
||||||
|
|
||||||
proc newCData*(cdata: string): XmlNode =
|
proc newCData*(cdata: sink string): XmlNode =
|
||||||
## Creates a new ``XmlNode`` of kind ``xnCData`` with the text `cdata`.
|
## Creates a new ``XmlNode`` of kind ``xnCData`` with the text `cdata`.
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
var d = newCData("my cdata")
|
var d = newCData("my cdata")
|
||||||
|
|
@ -135,7 +135,7 @@ proc newEntity*(entity: string): XmlNode =
|
||||||
result = newXmlNode(xnEntity)
|
result = newXmlNode(xnEntity)
|
||||||
result.fText = entity
|
result.fText = entity
|
||||||
|
|
||||||
proc newXmlTree*(tag: string, children: openArray[XmlNode],
|
proc newXmlTree*(tag: sink string, children: openArray[XmlNode],
|
||||||
attributes: XmlAttributes = nil): XmlNode =
|
attributes: XmlAttributes = nil): XmlNode =
|
||||||
## Creates a new XML tree with `tag`, `children` and `attributes`.
|
## Creates a new XML tree with `tag`, `children` and `attributes`.
|
||||||
##
|
##
|
||||||
|
|
@ -163,7 +163,7 @@ proc newXmlTree*(tag: string, children: openArray[XmlNode],
|
||||||
for i in 0..children.len-1: result.s[i] = children[i]
|
for i in 0..children.len-1: result.s[i] = children[i]
|
||||||
result.fAttr = attributes
|
result.fAttr = attributes
|
||||||
|
|
||||||
proc text*(n: XmlNode): string {.inline.} =
|
proc text*(n: XmlNode): lent string {.inline.} =
|
||||||
## Gets the associated text with the node `n`.
|
## Gets the associated text with the node `n`.
|
||||||
##
|
##
|
||||||
## `n` can be a CDATA, Text, comment, or entity node.
|
## `n` can be a CDATA, Text, comment, or entity node.
|
||||||
|
|
@ -181,7 +181,7 @@ proc text*(n: XmlNode): string {.inline.} =
|
||||||
assert n.k in {xnText, xnComment, xnCData, xnEntity}
|
assert n.k in {xnText, xnComment, xnCData, xnEntity}
|
||||||
result = n.fText
|
result = n.fText
|
||||||
|
|
||||||
proc `text=`*(n: XmlNode, text: string){.inline.} =
|
proc `text=`*(n: XmlNode, text: sink string) {.inline.} =
|
||||||
## Sets the associated text with the node `n`.
|
## Sets the associated text with the node `n`.
|
||||||
##
|
##
|
||||||
## `n` can be a CDATA, Text, comment, or entity node.
|
## `n` can be a CDATA, Text, comment, or entity node.
|
||||||
|
|
@ -199,7 +199,7 @@ proc `text=`*(n: XmlNode, text: string){.inline.} =
|
||||||
assert n.k in {xnText, xnComment, xnCData, xnEntity}
|
assert n.k in {xnText, xnComment, xnCData, xnEntity}
|
||||||
n.fText = text
|
n.fText = text
|
||||||
|
|
||||||
proc tag*(n: XmlNode): string {.inline.} =
|
proc tag*(n: XmlNode): lent string {.inline.} =
|
||||||
## Gets the tag name of `n`.
|
## Gets the tag name of `n`.
|
||||||
##
|
##
|
||||||
## `n` has to be an ``xnElement`` node.
|
## `n` has to be an ``xnElement`` node.
|
||||||
|
|
@ -220,7 +220,7 @@ proc tag*(n: XmlNode): string {.inline.} =
|
||||||
assert n.k == xnElement
|
assert n.k == xnElement
|
||||||
result = n.fTag
|
result = n.fTag
|
||||||
|
|
||||||
proc `tag=`*(n: XmlNode, tag: string) {.inline.} =
|
proc `tag=`*(n: XmlNode, tag: sink string) {.inline.} =
|
||||||
## Sets the tag name of `n`.
|
## Sets the tag name of `n`.
|
||||||
##
|
##
|
||||||
## `n` has to be an ``xnElement`` node.
|
## `n` has to be an ``xnElement`` node.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue