added $ for arrays
This commit is contained in:
parent
ffb36db5a6
commit
71b69a627f
2 changed files with 19 additions and 15 deletions
|
|
@ -1705,6 +1705,15 @@ proc `$`*[T: tuple|object](x: T): string =
|
||||||
result.add($value)
|
result.add($value)
|
||||||
firstElement = false
|
firstElement = false
|
||||||
result.add(")")
|
result.add(")")
|
||||||
|
|
||||||
|
proc collectionToString[T](x: T, b, e: string): string =
|
||||||
|
result = b
|
||||||
|
var firstElement = true
|
||||||
|
for value in items(x):
|
||||||
|
if not(firstElement): result.add(", ")
|
||||||
|
result.add($value)
|
||||||
|
firstElement = false
|
||||||
|
result.add(e)
|
||||||
|
|
||||||
proc `$`*[T: set](x: T): string =
|
proc `$`*[T: set](x: T): string =
|
||||||
## generic ``$`` operator for sets that is lifted from the components
|
## generic ``$`` operator for sets that is lifted from the components
|
||||||
|
|
@ -1712,13 +1721,7 @@ proc `$`*[T: set](x: T): string =
|
||||||
##
|
##
|
||||||
## .. code-block:: nimrod
|
## .. code-block:: nimrod
|
||||||
## ${23, 45} == "{23, 45}"
|
## ${23, 45} == "{23, 45}"
|
||||||
result = "{"
|
collectionToString(x, "{", "}")
|
||||||
var firstElement = true
|
|
||||||
for value in items(x):
|
|
||||||
if not(firstElement): result.add(", ")
|
|
||||||
result.add($value)
|
|
||||||
firstElement = false
|
|
||||||
result.add("}")
|
|
||||||
|
|
||||||
proc `$`*[T: seq](x: T): string =
|
proc `$`*[T: seq](x: T): string =
|
||||||
## generic ``$`` operator for seqs that is lifted from the components
|
## generic ``$`` operator for seqs that is lifted from the components
|
||||||
|
|
@ -1726,13 +1729,10 @@ proc `$`*[T: seq](x: T): string =
|
||||||
##
|
##
|
||||||
## .. code-block:: nimrod
|
## .. code-block:: nimrod
|
||||||
## $(@[23, 45]) == "@[23, 45]"
|
## $(@[23, 45]) == "@[23, 45]"
|
||||||
result = "@["
|
collectionToString(x, "@[", "]")
|
||||||
var firstElement = true
|
|
||||||
for value in items(x):
|
proc `$`*[T: array](x: T): string =
|
||||||
if not(firstElement): result.add(", ")
|
collectionToString(x, "[", "]")
|
||||||
result.add($value)
|
|
||||||
firstElement = false
|
|
||||||
result.add("]")
|
|
||||||
|
|
||||||
# ----------------- GC interface ---------------------------------------------
|
# ----------------- GC interface ---------------------------------------------
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,11 @@
|
||||||
discard """
|
discard """
|
||||||
output:'''@[23, 45]
|
output:'''@[23, 45]
|
||||||
@[, \"foo\", \"bar\"]'''
|
@[, foo, bar]
|
||||||
|
[, foo, bar]
|
||||||
|
[23, 45]'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
echo($(@[23, 45]))
|
echo($(@[23, 45]))
|
||||||
echo($(@["", "foo", "bar"]))
|
echo($(@["", "foo", "bar"]))
|
||||||
|
echo($(["", "foo", "bar"]))
|
||||||
|
echo($([23, 45]))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue