use hexchar in stdlib (#16290)
This commit is contained in:
parent
8cd3655dee
commit
e1e069dd6c
7 changed files with 68 additions and 75 deletions
|
|
@ -12,8 +12,8 @@
|
|||
##
|
||||
## Unstable API.
|
||||
|
||||
import
|
||||
strutils, lexbase
|
||||
import strutils, lexbase
|
||||
import std/private/decode_helpers
|
||||
|
||||
# ------------------- scanner -------------------------------------------------
|
||||
|
||||
|
|
@ -72,20 +72,6 @@ proc getColumn(L: SqlLexer): int =
|
|||
proc getLine(L: SqlLexer): int =
|
||||
result = L.lineNumber
|
||||
|
||||
proc handleHexChar(c: var SqlLexer, xi: var int) =
|
||||
case c.buf[c.bufpos]
|
||||
of '0'..'9':
|
||||
xi = (xi shl 4) or (ord(c.buf[c.bufpos]) - ord('0'))
|
||||
inc(c.bufpos)
|
||||
of 'a'..'f':
|
||||
xi = (xi shl 4) or (ord(c.buf[c.bufpos]) - ord('a') + 10)
|
||||
inc(c.bufpos)
|
||||
of 'A'..'F':
|
||||
xi = (xi shl 4) or (ord(c.buf[c.bufpos]) - ord('A') + 10)
|
||||
inc(c.bufpos)
|
||||
else:
|
||||
discard
|
||||
|
||||
proc handleOctChar(c: var SqlLexer, xi: var int) =
|
||||
if c.buf[c.bufpos] in {'0'..'7'}:
|
||||
xi = (xi shl 3) or (ord(c.buf[c.bufpos]) - ord('0'))
|
||||
|
|
@ -130,8 +116,10 @@ proc getEscapedChar(c: var SqlLexer, tok: var Token) =
|
|||
of 'x', 'X':
|
||||
inc(c.bufpos)
|
||||
var xi = 0
|
||||
handleHexChar(c, xi)
|
||||
handleHexChar(c, xi)
|
||||
if handleHexChar(c.buf[c.bufpos], xi):
|
||||
inc(c.bufpos)
|
||||
if handleHexChar(c.buf[c.bufpos], xi):
|
||||
inc(c.bufpos)
|
||||
add(tok.literal, chr(xi))
|
||||
of '0'..'7':
|
||||
var xi = 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue