Ascii character code 127 (DEL) is not printable and must be quoted. (#5984)
This is a follow-up to #5823.
This commit is contained in:
parent
6ca9ad6608
commit
a0f39e0ab4
6 changed files with 9 additions and 9 deletions
|
|
@ -543,7 +543,7 @@ var
|
||||||
|
|
||||||
proc toCChar*(c: char): string =
|
proc toCChar*(c: char): string =
|
||||||
case c
|
case c
|
||||||
of '\0'..'\x1F', '\x80'..'\xFF': result = '\\' & toOctal(c)
|
of '\0'..'\x1F', '\x7F'..'\xFF': result = '\\' & toOctal(c)
|
||||||
of '\'', '\"', '\\', '?': result = '\\' & c
|
of '\'', '\"', '\\', '?': result = '\\' & c
|
||||||
else: result = $(c)
|
else: result = $(c)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1001,7 +1001,7 @@ proc escapeJson*(s: string; result: var string) =
|
||||||
result.add("\"")
|
result.add("\"")
|
||||||
for x in runes(s):
|
for x in runes(s):
|
||||||
var r = int(x)
|
var r = int(x)
|
||||||
if r >= 32 and r <= 127:
|
if r >= 32 and r <= 126:
|
||||||
var c = chr(r)
|
var c = chr(r)
|
||||||
case c
|
case c
|
||||||
of '"': result.add("\\\"")
|
of '"': result.add("\\\"")
|
||||||
|
|
|
||||||
|
|
@ -371,7 +371,7 @@ proc esc(c: char, reserved = {'\0'..'\255'}): string =
|
||||||
of '\a': result = "\\a"
|
of '\a': result = "\\a"
|
||||||
of '\\': result = "\\\\"
|
of '\\': result = "\\\\"
|
||||||
of 'a'..'z', 'A'..'Z', '0'..'9', '_': result = $c
|
of 'a'..'z', 'A'..'Z', '0'..'9', '_': result = $c
|
||||||
elif c < ' ' or c >= '\128': result = '\\' & $ord(c)
|
elif c < ' ' or c >= '\127': result = '\\' & $ord(c)
|
||||||
elif c in reserved: result = '\\' & c
|
elif c in reserved: result = '\\' & c
|
||||||
else: result = $c
|
else: result = $c
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1643,7 +1643,7 @@ proc escape*(s: string, prefix = "\"", suffix = "\""): string {.noSideEffect,
|
||||||
## * replaces any ``\`` by ``\\``
|
## * replaces any ``\`` by ``\\``
|
||||||
## * replaces any ``'`` by ``\'``
|
## * replaces any ``'`` by ``\'``
|
||||||
## * replaces any ``"`` by ``\"``
|
## * replaces any ``"`` by ``\"``
|
||||||
## * replaces any other character in the set ``{'\0'..'\31', '\128'..'\255'}``
|
## * replaces any other character in the set ``{'\0'..'\31', '\127'..'\255'}``
|
||||||
## by ``\xHH`` where ``HH`` is its hexadecimal value.
|
## by ``\xHH`` where ``HH`` is its hexadecimal value.
|
||||||
## The procedure has been designed so that its output is usable for many
|
## The procedure has been designed so that its output is usable for many
|
||||||
## different common syntaxes. The resulting string is prefixed with
|
## different common syntaxes. The resulting string is prefixed with
|
||||||
|
|
@ -1653,7 +1653,7 @@ proc escape*(s: string, prefix = "\"", suffix = "\""): string {.noSideEffect,
|
||||||
result.add(prefix)
|
result.add(prefix)
|
||||||
for c in items(s):
|
for c in items(s):
|
||||||
case c
|
case c
|
||||||
of '\0'..'\31', '\128'..'\255':
|
of '\0'..'\31', '\127'..'\255':
|
||||||
add(result, "\\x")
|
add(result, "\\x")
|
||||||
add(result, toHex(ord(c), 2))
|
add(result, toHex(ord(c), 2))
|
||||||
of '\\': add(result, "\\\\")
|
of '\\': add(result, "\\\\")
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ proc reprStrAux(result: var string, s: cstring; len: int) =
|
||||||
of '"': add result, "\\\""
|
of '"': add result, "\\\""
|
||||||
of '\\': add result, "\\\\" # BUGFIX: forgotten
|
of '\\': add result, "\\\\" # BUGFIX: forgotten
|
||||||
of '\10': add result, "\\10\"\n\"" # " \n " # better readability
|
of '\10': add result, "\\10\"\n\"" # " \n " # better readability
|
||||||
of '\128' .. '\255', '\0'..'\9', '\11'..'\31':
|
of '\127' .. '\255', '\0'..'\9', '\11'..'\31':
|
||||||
add result, "\\" & reprInt(ord(c))
|
add result, "\\" & reprInt(ord(c))
|
||||||
else:
|
else:
|
||||||
result.add(c)
|
result.add(c)
|
||||||
|
|
@ -68,7 +68,7 @@ proc reprChar(x: char): string {.compilerRtl.} =
|
||||||
case x
|
case x
|
||||||
of '"': add result, "\\\""
|
of '"': add result, "\\\""
|
||||||
of '\\': add result, "\\\\"
|
of '\\': add result, "\\\\"
|
||||||
of '\128' .. '\255', '\0'..'\31': add result, "\\" & reprInt(ord(x))
|
of '\127' .. '\255', '\0'..'\31': add result, "\\" & reprInt(ord(x))
|
||||||
else: add result, x
|
else: add result, x
|
||||||
add result, "\'"
|
add result, "\'"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ proc reprChar(x: char): string {.compilerRtl.} =
|
||||||
case x
|
case x
|
||||||
of '"': add(result, "\\\"")
|
of '"': add(result, "\\\"")
|
||||||
of '\\': add(result, "\\\\")
|
of '\\': add(result, "\\\\")
|
||||||
of '\128'..'\255', '\0'..'\31': add( result, "\\" & reprInt(ord(x)) )
|
of '\127'..'\255', '\0'..'\31': add( result, "\\" & reprInt(ord(x)) )
|
||||||
else: add(result, x)
|
else: add(result, x)
|
||||||
add(result, "\'")
|
add(result, "\'")
|
||||||
|
|
||||||
|
|
@ -56,7 +56,7 @@ proc reprStrAux(result: var string, s: cstring, len: int) =
|
||||||
of '"': add(result, "\\\"")
|
of '"': add(result, "\\\"")
|
||||||
of '\\': add(result, "\\\\")
|
of '\\': add(result, "\\\\")
|
||||||
of '\10': add(result, "\\10\"\n\"")
|
of '\10': add(result, "\\10\"\n\"")
|
||||||
of '\128'..'\255', '\0'..'\9', '\11'..'\31':
|
of '\127'..'\255', '\0'..'\9', '\11'..'\31':
|
||||||
add( result, "\\" & reprInt(ord(c)) )
|
add( result, "\\" & reprInt(ord(c)) )
|
||||||
else:
|
else:
|
||||||
add( result, reprInt(ord(c)) ) # Not sure about this.
|
add( result, reprInt(ord(c)) ) # Not sure about this.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue