core :: FlatText :: chars_to_escape_to_c
self
to C, how many more bytes will be needed ?This enables a double-optimization in escape_to_c
since if this
method returns 0, then self
does not need escaping and can be
returned as-is
# By escaping `self` to C, how many more bytes will be needed ?
#
# This enables a double-optimization in `escape_to_c` since if this
# method returns 0, then `self` does not need escaping and can be
# returned as-is
fun chars_to_escape_to_c: Int do
var its = _items
var max = last_byte
var pos = first_byte
var req_esc = 0
while pos <= max do
var c = its[pos]
if c == u'\n' then
req_esc += 1
else if c == u'\t' then
req_esc += 1
else if c == u'"' then
req_esc += 1
else if c == u'\'' then
req_esc += 1
else if c == u'\\' then
req_esc += 1
else if c == u'?' then
var j = pos + 1
if j < length then
var next = its[j]
# We ignore `??'` because it will be escaped as `??\'`.
if
next == 0x21 or
next == 0x28 or
next == 0x29 or
next == 0x2D or
next == 0x2F or
next == 0x3C or
next == 0x3D or
next == 0x3E
then req_esc += 1
end
else if c < 32 then
req_esc += 3
end
pos += 1
end
return req_esc
end
lib/core/text/flat.nit:199,2--243,4