From 54808ab12fcbf8cc253129ed03f560fc6dd2648e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arne=20D=C3=B6ring?= Date: Mon, 7 Aug 2017 18:21:21 +0200 Subject: [PATCH] don't filter '\0' characters in string generation --- compiler/rodutils.nim | 2 +- lib/system.nim | 7 +------ tests/system/toString.nim | 3 ++- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/compiler/rodutils.nim b/compiler/rodutils.nim index 3a90a207c0..6e77e6b8f9 100644 --- a/compiler/rodutils.nim +++ b/compiler/rodutils.nim @@ -22,7 +22,7 @@ proc toStrMaxPrecision*(f: BiggestFloat, literalPostfix = ""): string = else: result = "-INF" else: var buf: array[0..80, char] - let newLen = c_snprintf(buf.cstring, buf.len.uint, "%#.16e%s", f, literalPostfix.cstring) + discard c_snprintf(buf.cstring, buf.len.uint, "%#.16e%s", f, literalPostfix.cstring) result = $buf.cstring proc encodeStr*(s: string, result: var string) = diff --git a/lib/system.nim b/lib/system.nim index 0bc0a0dbfb..d2bdeae0e5 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -2427,12 +2427,7 @@ proc collectionToString[T](x: T, prefix, separator, suffix: string): string = result.add($value) # prevent temporary string allocation elif compiles(result.add(value)): - # don't insert '\0' characters into the result string - when value is char: - if value != '\0': - result.add(value) - else: - result.add(value) + result.add(value) else: result.add($value) diff --git a/tests/system/toString.nim b/tests/system/toString.nim index 0eed596aee..377336c90c 100644 --- a/tests/system/toString.nim +++ b/tests/system/toString.nim @@ -46,6 +46,7 @@ doAssert dataStr == $data import strutils # array test + let arr = ['H','e','l','l','o',' ','W','o','r','l','d','!','\0'] -doAssert $arr == "[H, e, l, l, o, , W, o, r, l, d, !, ]" +doAssert $arr == "[H, e, l, l, o, , W, o, r, l, d, !, \0]" doAssert $arr.cstring == "Hello World!"