Small improvements for string and char repr with gc:arc (#14400)

* Small improvements for string and char repr with gc:arc

* Fix test
This commit is contained in:
Clyybber
2020-05-20 12:54:04 +02:00
committed by GitHub
parent 3d20f14193
commit 7fe4c66f35
3 changed files with 11 additions and 9 deletions

View File

@@ -27,21 +27,23 @@ proc repr*(x: bool): string {.magic: "BoolToStr", noSideEffect.}
## repr for a boolean argument. Returns `x`
## converted to the string "false" or "true".
proc repr*(x: char): string {.magic: "CharToStr", noSideEffect.}
proc repr*(x: char): string {.noSideEffect.} =
## repr for a character argument. Returns `x`
## converted to a string.
##
## .. code-block:: Nim
## assert repr('c') == "c"
'\'' & $x & '\''
proc repr*(x: cstring): string {.magic: "CStrToStr", noSideEffect.}
proc repr*(x: cstring): string {.noSideEffect.} =
## repr for a CString argument. Returns `x`
## converted to a string.
## converted to a quoted string.
'"' & $x & '"'
proc repr*(x: string): string {.magic: "StrToStr", noSideEffect.}
proc repr*(x: string): string {.noSideEffect.} =
## repr for a string argument. Returns `x`
## as it is. This operator is useful for generic code, so
## that ``$expr`` also works if ``expr`` is already a string.
## but quoted.
'"' & x & '"'
proc repr*[Enum: enum](x: Enum): string {.magic: "EnumToStr", noSideEffect.}
## repr for an enumeration argument. This works for

View File

@@ -7,8 +7,8 @@ nil
output: '''
nil
2
Obj(member: ref @[hello])
ref (member: ref @[hello])
Obj(member: ref @["hello"])
ref (member: ref @["hello"])
'''
"""
import tables

View File

@@ -1,6 +1,6 @@
discard """
cmd: "nim c --gc:arc $file"
output: '''Foo(field: Dick Laurent, k: ka, x: 0.0)
output: '''Foo(field: "Dick Laurent", k: ka, x: 0.0)
Nobody is dead
Dick Laurent is dead'''
"""