repr.nim: minor improvement when outputting addresses of cstrings
This commit is contained in:
parent
0b93db5a7c
commit
8d3d9ce5cc
1 changed files with 5 additions and 5 deletions
|
|
@ -38,12 +38,12 @@ proc `$`(x: uint64): string =
|
||||||
for t in 0 .. < half: swap(buf[t], buf[i-t-1])
|
for t in 0 .. < half: swap(buf[t], buf[i-t-1])
|
||||||
result = $buf
|
result = $buf
|
||||||
|
|
||||||
proc reprStrAux(result: var string, s: string) =
|
proc reprStrAux(result: var string, s: cstring; len: int) =
|
||||||
if cast[pointer](s) == nil:
|
if cast[pointer](s) == nil:
|
||||||
add result, "nil"
|
add result, "nil"
|
||||||
return
|
return
|
||||||
add result, reprPointer(cast[pointer](s)) & "\""
|
add result, reprPointer(cast[pointer](s)) & "\""
|
||||||
for i in 0.. <s.len:
|
for i in 0.. <len:
|
||||||
let c = s[i]
|
let c = s[i]
|
||||||
case c
|
case c
|
||||||
of '"': add result, "\\\""
|
of '"': add result, "\\\""
|
||||||
|
|
@ -57,7 +57,7 @@ proc reprStrAux(result: var string, s: string) =
|
||||||
|
|
||||||
proc reprStr(s: string): string {.compilerRtl.} =
|
proc reprStr(s: string): string {.compilerRtl.} =
|
||||||
result = ""
|
result = ""
|
||||||
reprStrAux(result, s)
|
reprStrAux(result, s, s.len)
|
||||||
|
|
||||||
proc reprBool(x: bool): string {.compilerRtl.} =
|
proc reprBool(x: bool): string {.compilerRtl.} =
|
||||||
if x: result = "true"
|
if x: result = "true"
|
||||||
|
|
@ -277,11 +277,11 @@ when not defined(useNimRtl):
|
||||||
of tyEnum: add result, reprEnum(getInt(p, typ.size), typ)
|
of tyEnum: add result, reprEnum(getInt(p, typ.size), typ)
|
||||||
of tyBool: add result, reprBool(cast[ptr bool](p)[])
|
of tyBool: add result, reprBool(cast[ptr bool](p)[])
|
||||||
of tyChar: add result, reprChar(cast[ptr char](p)[])
|
of tyChar: add result, reprChar(cast[ptr char](p)[])
|
||||||
of tyString: reprStrAux(result, cast[ptr string](p)[])
|
of tyString: reprStrAux(result, cast[ptr string](p)[], cast[ptr string](p)[].len)
|
||||||
of tyCString:
|
of tyCString:
|
||||||
let cs = cast[ptr cstring](p)[]
|
let cs = cast[ptr cstring](p)[]
|
||||||
if cs.isNil: add result, "nil"
|
if cs.isNil: add result, "nil"
|
||||||
else: reprStrAux(result, $cs)
|
else: reprStrAux(result, cs, cs.len)
|
||||||
of tyRange: reprAux(result, p, typ.base, cl)
|
of tyRange: reprAux(result, p, typ.base, cl)
|
||||||
of tyProc, tyPointer:
|
of tyProc, tyPointer:
|
||||||
if cast[PPointer](p)[] == nil: add result, "nil"
|
if cast[PPointer](p)[] == nil: add result, "nil"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue