breaking change: arrays of char do not convert to cstring; ptr to array of char does

This commit is contained in:
Andreas Rumpf 2017-10-10 00:17:20 +02:00
commit 3308d26581
12 changed files with 73 additions and 36 deletions

View file

@ -21,9 +21,14 @@ proc toStrMaxPrecision*(f: BiggestFloat, literalPostfix = ""): string =
if f > 0.0: result = "INF"
else: result = "-INF"
else:
var buf: array[0..80, char]
discard c_snprintf(buf.cstring, buf.len.uint, "%#.16e%s", f, literalPostfix.cstring)
result = $buf.cstring
when defined(nimNoArrayToCstringConversion):
result = newString(81)
let n = c_snprintf(result.cstring, result.len.uint, "%#.16e%s", f, literalPostfix.cstring)
setLen(result, n)
else:
var buf: array[0..80, char]
discard c_snprintf(buf.cstring, buf.len.uint, "%#.16e%s", f, literalPostfix.cstring)
result = $buf.cstring
proc encodeStr*(s: string, result: var string) =
for i in countup(0, len(s) - 1):