don't filter '\0' characters in string generation
This commit is contained in:
parent
3bf1f019a7
commit
54808ab12f
3 changed files with 4 additions and 8 deletions
|
|
@ -22,7 +22,7 @@ proc toStrMaxPrecision*(f: BiggestFloat, literalPostfix = ""): string =
|
||||||
else: result = "-INF"
|
else: result = "-INF"
|
||||||
else:
|
else:
|
||||||
var buf: array[0..80, char]
|
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
|
result = $buf.cstring
|
||||||
|
|
||||||
proc encodeStr*(s: string, result: var string) =
|
proc encodeStr*(s: string, result: var string) =
|
||||||
|
|
|
||||||
|
|
@ -2427,11 +2427,6 @@ proc collectionToString[T](x: T, prefix, separator, suffix: string): string =
|
||||||
result.add($value)
|
result.add($value)
|
||||||
# prevent temporary string allocation
|
# prevent temporary string allocation
|
||||||
elif compiles(result.add(value)):
|
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:
|
else:
|
||||||
result.add($value)
|
result.add($value)
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ doAssert dataStr == $data
|
||||||
|
|
||||||
import strutils
|
import strutils
|
||||||
# array test
|
# array test
|
||||||
|
|
||||||
let arr = ['H','e','l','l','o',' ','W','o','r','l','d','!','\0']
|
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!"
|
doAssert $arr.cstring == "Hello World!"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue