strictdefs for repr so that it can used for debugging purposes in t… (#23501)

…he compiler
This commit is contained in:
ringabout
2024-04-15 15:36:37 +08:00
committed by GitHub
parent bcc935ae6a
commit 7208a27c0f

View File

@@ -41,7 +41,7 @@ proc repr*(x: char): string {.noSideEffect, raises: [].} =
## ```Nim
## assert repr('c') == "'c'"
## ```
result.add '\''
result = "'"
# Elides string creations if not needed
if x in {'\\', '\0'..'\31', '\127'..'\255'}:
result.add '\\'
@@ -54,7 +54,7 @@ proc repr*(x: char): string {.noSideEffect, raises: [].} =
proc repr*(x: string | cstring): string {.noSideEffect, raises: [].} =
## repr for a string argument. Returns `x`
## converted to a quoted and escaped string.
result.add '\"'
result = "\""
for i in 0..<x.len:
if x[i] in {'"', '\\', '\0'..'\31', '\127'..'\255'}:
result.add '\\'