Added $ for openarrays. Fixes #7940.

This commit is contained in:
data-man
2018-06-01 21:28:23 +03:00
parent cb87bba82f
commit b4626a220b
2 changed files with 9 additions and 0 deletions

View File

@@ -3443,6 +3443,14 @@ when not defined(nimNoArrayToString):
## generic ``$`` operator for arrays that is lifted from the components
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.} =
## a shorthand for ``echo(errormsg); quit(errorcode)``.
echo(errormsg)

View File

@@ -6,6 +6,7 @@ doAssert "@[23, 45]" == $(@[23, 45])
doAssert "[32, 45]" == $([32, 45])
doAssert """@["", "foo", "bar"]""" == $(@["", "foo", "bar"])
doAssert """["", "foo", "bar"]""" == $(["", "foo", "bar"])
doAssert """["", "foo", "bar"]""" == $(@["", "foo", "bar"].toOpenArray(0, 2))
# bug #2395
let alphaSet: set[char] = {'a'..'c'}