567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
|
var add, cont = disemvowel_codepoint(cur)
if add:ref() then acc:ppush(add) end
cur = cont
end
return acc:finalize()
end
terra m.qesc(pool: &lib.mem.pool, str: m.t, wrap: bool): m.t
-- escape double-quotes
var a: m.acc a:pool(pool, str.ct + str.ct/2)
if wrap then a:lpush '"' end
for i=0, str.ct do
if str(i) == @'"' then a:lpush '\\"'
elseif str(i) == @'\\' then a:lpush '\\\\'
elseif str(i) < 0x20 then -- for json
var hex = lib.math.hexbyte(str(i))
a:lpush('\\u00'):push(&hex[0], 2)
else a:push(str.ptr + i,1) end
end
if wrap then a:lpush '"' end
return a:finalize()
end
return m
|
|
<
|
|
|
>
>
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
|
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
|
var add, cont = disemvowel_codepoint(cur)
if add:ref() then acc:ppush(add) end
cur = cont
end
return acc:finalize()
end
terra m.acc:qesc(str: m.t, wrap: bool)
-- escape double-quotes
if wrap then self:lpush '"' end
for i=0, str.ct do
if str(i) == @'"' then self:lpush '\\"'
elseif str(i) == @'\\' then self:lpush '\\\\'
elseif str(i) == @'\n' then self:lpush '\\n'
elseif str(i) == @'\t' then self:lpush '\\t'
elseif str(i) < 0x20 then -- for json
var hex = lib.math.hexbyte(str(i))
self:lpush('\\u00'):push(&hex[0], 2)
else self:push(str.ptr + i,1) end
end
if wrap then self:lpush '"' end
return self
end
terra m.qesc(pool: &lib.mem.pool, str: m.t, wrap: bool): m.t
-- convenience function
var a: m.acc a:pool(pool, 2 + str.ct + str.ct/2)
a:qesc(str,wrap)
return a:finalize()
end
terra m.acc:qpush(str: m.t)
-- convenience adaptor
return self:qesc(str, false)
end
return m
|