Skip to content

Commit 6e0fe96

Browse files
authored
add sink and lent annotations for xmltree and streams (#18037)
1 parent fac5bae commit 6e0fe96

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

lib/pure/streams.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,7 @@ else: # after 1.3 or JS not defined
12521252
var s = StringStream(s)
12531253
s.data = ""
12541254

1255-
proc newStringStream*(s: string = ""): owned StringStream =
1255+
proc newStringStream*(s: sink string = ""): owned StringStream =
12561256
## Creates a new stream from the string `s`.
12571257
##
12581258
## See also:

lib/pure/xmltree.nim

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ proc newXmlNode(kind: XmlNodeKind): XmlNode =
7070
## Creates a new ``XmlNode``.
7171
result = XmlNode(k: kind)
7272

73-
proc newElement*(tag: string): XmlNode =
73+
proc newElement*(tag: sink string): XmlNode =
7474
## Creates a new ``XmlNode`` of kind ``xnElement`` with the given `tag`.
7575
##
7676
## See also:
@@ -89,7 +89,7 @@ proc newElement*(tag: string): XmlNode =
8989
result.s = @[]
9090
# init attributes lazily to save memory
9191

92-
proc newText*(text: string): XmlNode =
92+
proc newText*(text: sink string): XmlNode =
9393
## Creates a new ``XmlNode`` of kind ``xnText`` with the text `text`.
9494
runnableExamples:
9595
var b = newText("my text")
@@ -99,13 +99,13 @@ proc newText*(text: string): XmlNode =
9999
result = newXmlNode(xnText)
100100
result.fText = text
101101

102-
proc newVerbatimText*(text: string): XmlNode {.since: (1, 3).} =
102+
proc newVerbatimText*(text: sink string): XmlNode {.since: (1, 3).} =
103103
## Creates a new ``XmlNode`` of kind ``xnVerbatimText`` with the text `text`.
104104
## **Since**: Version 1.3.
105105
result = newXmlNode(xnVerbatimText)
106106
result.fText = text
107107

108-
proc newComment*(comment: string): XmlNode =
108+
proc newComment*(comment: sink string): XmlNode =
109109
## Creates a new ``XmlNode`` of kind ``xnComment`` with the text `comment`.
110110
runnableExamples:
111111
var c = newComment("my comment")
@@ -115,7 +115,7 @@ proc newComment*(comment: string): XmlNode =
115115
result = newXmlNode(xnComment)
116116
result.fText = comment
117117

118-
proc newCData*(cdata: string): XmlNode =
118+
proc newCData*(cdata: sink string): XmlNode =
119119
## Creates a new ``XmlNode`` of kind ``xnCData`` with the text `cdata`.
120120
runnableExamples:
121121
var d = newCData("my cdata")
@@ -135,7 +135,7 @@ proc newEntity*(entity: string): XmlNode =
135135
result = newXmlNode(xnEntity)
136136
result.fText = entity
137137

138-
proc newXmlTree*(tag: string, children: openArray[XmlNode],
138+
proc newXmlTree*(tag: sink string, children: openArray[XmlNode],
139139
attributes: XmlAttributes = nil): XmlNode =
140140
## Creates a new XML tree with `tag`, `children` and `attributes`.
141141
##
@@ -151,7 +151,7 @@ proc newXmlTree*(tag: string, children: openArray[XmlNode],
151151
h.add newEntity("some entity")
152152
let att = {"key1": "first value", "key2": "second value"}.toXmlAttributes
153153
let k = newXmlTree("treeTag", [g, h], att)
154-
154+
155155
doAssert $k == """<treeTag key1="first value" key2="second value">
156156
<myTag>some text<!-- this is comment --></myTag>
157157
<secondTag>&some entity;</secondTag>
@@ -163,7 +163,7 @@ proc newXmlTree*(tag: string, children: openArray[XmlNode],
163163
for i in 0..children.len-1: result.s[i] = children[i]
164164
result.fAttr = attributes
165165

166-
proc text*(n: XmlNode): string {.inline.} =
166+
proc text*(n: XmlNode): lent string {.inline.} =
167167
## Gets the associated text with the node `n`.
168168
##
169169
## `n` can be a CDATA, Text, comment, or entity node.
@@ -181,7 +181,7 @@ proc text*(n: XmlNode): string {.inline.} =
181181
assert n.k in {xnText, xnComment, xnCData, xnEntity}
182182
result = n.fText
183183

184-
proc `text=`*(n: XmlNode, text: string){.inline.} =
184+
proc `text=`*(n: XmlNode, text: sink string) {.inline.} =
185185
## Sets the associated text with the node `n`.
186186
##
187187
## `n` can be a CDATA, Text, comment, or entity node.
@@ -199,7 +199,7 @@ proc `text=`*(n: XmlNode, text: string){.inline.} =
199199
assert n.k in {xnText, xnComment, xnCData, xnEntity}
200200
n.fText = text
201201

202-
proc tag*(n: XmlNode): string {.inline.} =
202+
proc tag*(n: XmlNode): lent string {.inline.} =
203203
## Gets the tag name of `n`.
204204
##
205205
## `n` has to be an ``xnElement`` node.
@@ -220,7 +220,7 @@ proc tag*(n: XmlNode): string {.inline.} =
220220
assert n.k == xnElement
221221
result = n.fTag
222222

223-
proc `tag=`*(n: XmlNode, tag: string) {.inline.} =
223+
proc `tag=`*(n: XmlNode, tag: sink string) {.inline.} =
224224
## Sets the tag name of `n`.
225225
##
226226
## `n` has to be an ``xnElement`` node.
@@ -389,13 +389,13 @@ proc clear*(n: var XmlNode) =
389389
var g = newElement("myTag")
390390
g.add newText("some text")
391391
g.add newComment("this is comment")
392-
392+
393393
var h = newElement("secondTag")
394394
h.add newEntity("some entity")
395-
395+
396396
let att = {"key1": "first value", "key2": "second value"}.toXmlAttributes
397397
var k = newXmlTree("treeTag", [g, h], att)
398-
398+
399399
doAssert $k == """<treeTag key1="first value" key2="second value">
400400
<myTag>some text<!-- this is comment --></myTag>
401401
<secondTag>&some entity;</secondTag>
@@ -447,7 +447,7 @@ proc toXmlAttributes*(keyValuePairs: varargs[tuple[key,
447447
let att = {"key1": "first value", "key2": "second value"}.toXmlAttributes
448448
var j = newElement("myTag")
449449
j.attrs = att
450-
450+
451451
doAssert $j == """<myTag key1="first value" key2="second value" />"""
452452

453453
newStringTable(keyValuePairs)

0 commit comments

Comments
 (0)