parsav  Diff

Differences From Artifact [6c699847d5]:

To Artifact [072253bf19]:


   180    180   	end
   181    181   	if self.buf ~= nil and self.space > 0 then
   182    182   		lib.mem.heapf(self.buf)
   183    183   	end
   184    184   end;
   185    185   
   186    186   terra m.acc:crush()
   187         -	--lib.dbg('crushing string accumulator')
   188    187   	if self.pool ~= nil then return self end -- no point unless at end of buffer
          188  +	--lib.dbg('crushing string accumulator', &self.buf[0])
   189    189   	self.buf = [rawstring](lib.mem.heapr_raw(self.buf, self.sz))
   190    190   	self.space = self.sz
   191    191   	return self
   192    192   end;
   193    193   
   194    194   terra m.acc:finalize()
   195    195   	--lib.dbg('finalizing string accumulator')
................................................................................
   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): m.t
          574  +terra m.qesc(pool: &lib.mem.pool, str: m.t, wrap: bool): m.t
   575    575    -- escape double-quotes
   576    576   	var a: m.acc a:pool(pool, str.ct + str.ct/2)
   577         -	a:lpush '"'
          577  +	if wrap then a:lpush '"' end
   578    578   	for i=0, str.ct do
   579    579   		if     str(i) == @'"'  then a:lpush '\\"'
   580    580   		elseif str(i) == @'\\' then a:lpush '\\\\'
   581    581   		elseif str(i) < 0x20 then -- for json
   582    582   			var hex = lib.math.hexbyte(str(i))
   583    583   			a:lpush('\\u00'):push(&hex[0], 2)
   584    584   		else   a:push(str.ptr + i,1) end
   585    585   	end
   586         -	a:lpush '"'
          586  +	if wrap then a:lpush '"' end
   587    587   	return a:finalize()
   588    588   end
   589    589   
   590    590   return m