From b4626a220b2de0fee7360672915332c402bf9dc7 Mon Sep 17 00:00:00 2001 From: data-man Date: Fri, 1 Jun 2018 21:28:23 +0300 Subject: [PATCH] Added $ for openarrays. Fixes #7940. --- lib/system.nim | 8 ++++++++ tests/system/toString.nim | 1 + 2 files changed, 9 insertions(+) diff --git a/lib/system.nim b/lib/system.nim index 06c4f103b3..13f16903a2 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -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) diff --git a/tests/system/toString.nim b/tests/system/toString.nim index 37c678a748..ea10f998ca 100644 --- a/tests/system/toString.nim +++ b/tests/system/toString.nim @@ -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'}