var req_esc = 0
while pos <= max do
var c = its[pos]
- if c == 0x0Au8 then
+ if c == b'\n' then
req_esc += 1
- else if c == 0x09u8 then
+ else if c == b'\t' then
req_esc += 1
- else if c == 0x22u8 then
+ else if c == b'"' then
req_esc += 1
- else if c == 0x27u8 then
+ else if c == b'\'' then
req_esc += 1
- else if c == 0x5Cu8 then
+ else if c == b'\\' then
req_esc += 1
+ else if c == 0x3Fu8 then
+ var j = pos + 1
+ if j < length then
+ var next = its[j]
+ # We ignore `??'` because it will be escaped as `??\'`.
+ if
+ next == 0x21u8 or
+ next == 0x28u8 or
+ next == 0x29u8 or
+ next == 0x2Du8 or
+ next == 0x2Fu8 or
+ next == 0x3Cu8 or
+ next == 0x3Du8 or
+ next == 0x3Eu8
+ then req_esc += 1
+ end
else if c < 32u8 then
req_esc += 3
end
# * 0x22 => \"
# * 0x27 => \'
# * 0x5C => \\
- if c == 0x09u8 then
- nns[opos] = 0x5Cu8
- nns[opos + 1] = 0x74u8
+ if c == b'\t' then
+ nns[opos] = b'\\'
+ nns[opos + 1] = b't'
opos += 2
- else if c == 0x0Au8 then
- nns[opos] = 0x5Cu8
- nns[opos + 1] = 0x6Eu8
+ else if c == b'\n' then
+ nns[opos] = b'\\'
+ nns[opos + 1] = b'n'
opos += 2
- else if c == 0x22u8 then
- nns[opos] = 0x5Cu8
- nns[opos + 1] = 0x22u8
+ else if c == b'"' then
+ nns[opos] = b'\\'
+ nns[opos + 1] = b'"'
opos += 2
- else if c == 0x27u8 then
- nns[opos] = 0x5Cu8
- nns[opos + 1] = 0x27u8
+ else if c == b'\'' then
+ nns[opos] = b'\\'
+ nns[opos + 1] = b'\''
opos += 2
- else if c == 0x5Cu8 then
- nns[opos] = 0x5Cu8
- nns[opos + 1] = 0x5Cu8
+ else if c == b'\\' then
+ nns[opos] = b'\\'
+ nns[opos + 1] = b'\\'
opos += 2
+ else if c == 0x3Fu8 then
+ var j = pos + 1
+ if j < length then
+ var next = its[j]
+ # We ignore `??'` because it will be escaped as `??\'`.
+ if
+ next == 0x21u8 or
+ next == 0x28u8 or
+ next == 0x29u8 or
+ next == 0x2Du8 or
+ next == 0x2Fu8 or
+ next == 0x3Cu8 or
+ next == 0x3Du8 or
+ next == 0x3Eu8
+ then
+ nns[opos] = 0x5Cu8
+ opos += 1
+ end
+ end
+ nns[opos] = 0x3Fu8
+ opos += 1
else if c < 32u8 then
- nns[opos] = 0x5Cu8
- nns[opos + 1] = 0x30u8
- nns[opos + 2] = ((c & 0x38u8) >> 3) + 0x30u8
- nns[opos + 3] = (c & 0x07u8) + 0x30u8
+ nns[opos] = b'\\'
+ nns[opos + 1] = b'0'
+ nns[opos + 2] = ((c & 0x38u8) >> 3) + b'0'
+ nns[opos + 3] = (c & 0x07u8) + b'0'
opos += 4
else
nns[opos] = c