This commit is contained in:
Araq
2018-09-03 08:37:32 +02:00
parent dc67dd3bef
commit fa338768a3
2 changed files with 10 additions and 2 deletions

View File

@@ -3972,7 +3972,7 @@ proc addQuoted*[T](s: var string, x: T) =
## tmp.add(", ")
## tmp.addQuoted('c')
## assert(tmp == """1, "string", 'c'""")
when T is string:
when T is string or T is cstring:
s.add("\"")
for c in x:
# Only ASCII chars are escaped to avoid butchering

View File

@@ -106,4 +106,12 @@ var nilstring: string
bar(nilstring)
static:
stringCompare()
stringCompare()
# bug 8847
var a2: cstring = "fo\"o2"
block:
var s: string
s.addQuoted a2
doAssert s == "\"fo\\\"o2\""