Added $ for openarrays. Fixes #7940.
This commit is contained in:
parent
cb87bba82f
commit
b4626a220b
2 changed files with 9 additions and 0 deletions
|
|
@ -3443,6 +3443,14 @@ when not defined(nimNoArrayToString):
|
||||||
## generic ``$`` operator for arrays that is lifted from the components
|
## generic ``$`` operator for arrays that is lifted from the components
|
||||||
collectionToString(x, "[", ", ", "]")
|
collectionToString(x, "[", ", ", "]")
|
||||||
|
|
||||||
|
proc `$`*[T](x: openarray[T]): string =
|
||||||
|
## generic ``$`` operator for openarrays that is lifted from the components
|
||||||
|
## of `x`. Example:
|
||||||
|
##
|
||||||
|
## .. code-block:: nim
|
||||||
|
## $(@[23, 45].toOpenArray(0, 1)) == "[23, 45]"
|
||||||
|
collectionToString(x, "[", ", ", "]")
|
||||||
|
|
||||||
proc quit*(errormsg: string, errorcode = QuitFailure) {.noReturn.} =
|
proc quit*(errormsg: string, errorcode = QuitFailure) {.noReturn.} =
|
||||||
## a shorthand for ``echo(errormsg); quit(errorcode)``.
|
## a shorthand for ``echo(errormsg); quit(errorcode)``.
|
||||||
echo(errormsg)
|
echo(errormsg)
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ doAssert "@[23, 45]" == $(@[23, 45])
|
||||||
doAssert "[32, 45]" == $([32, 45])
|
doAssert "[32, 45]" == $([32, 45])
|
||||||
doAssert """@["", "foo", "bar"]""" == $(@["", "foo", "bar"])
|
doAssert """@["", "foo", "bar"]""" == $(@["", "foo", "bar"])
|
||||||
doAssert """["", "foo", "bar"]""" == $(["", "foo", "bar"])
|
doAssert """["", "foo", "bar"]""" == $(["", "foo", "bar"])
|
||||||
|
doAssert """["", "foo", "bar"]""" == $(@["", "foo", "bar"].toOpenArray(0, 2))
|
||||||
|
|
||||||
# bug #2395
|
# bug #2395
|
||||||
let alphaSet: set[char] = {'a'..'c'}
|
let alphaSet: set[char] = {'a'..'c'}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue