mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-12 22:33:49 +00:00
Added $ for openarrays. Fixes #7940.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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'}
|
||||
|
||||
Reference in New Issue
Block a user