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