180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
...
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
|
end
if self.buf ~= nil and self.space > 0 then
lib.mem.heapf(self.buf)
end
end;
terra m.acc:crush()
--lib.dbg('crushing string accumulator')
if self.pool ~= nil then return self end -- no point unless at end of buffer
self.buf = [rawstring](lib.mem.heapr_raw(self.buf, self.sz))
self.space = self.sz
return self
end;
terra m.acc:finalize()
--lib.dbg('finalizing string accumulator')
................................................................................
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): m.t
-- escape double-quotes
var a: m.acc a:pool(pool, str.ct + str.ct/2)
a:lpush '"'
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
a:lpush '"'
return a:finalize()
end
return m
|
|
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
...
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
|
end
if self.buf ~= nil and self.space > 0 then
lib.mem.heapf(self.buf)
end
end;
terra m.acc:crush()
if self.pool ~= nil then return self end -- no point unless at end of buffer
--lib.dbg('crushing string accumulator', &self.buf[0])
self.buf = [rawstring](lib.mem.heapr_raw(self.buf, self.sz))
self.space = self.sz
return self
end;
terra m.acc:finalize()
--lib.dbg('finalizing string accumulator')
................................................................................
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
|