Differences From
Artifact [0c9ba1d780]:
59 59
60 60 var sz = lib.math.biggest(self.ct, other.ct)
61 61 for i = 0, sz do
62 62 if self.ptr[i] == 0 and other.ptr[i] == 0 then return true end
63 63 if self.ptr[i] ~= other.ptr[i] then return false end
64 64 end
65 65 return true
66 + end
67 + terra ty:startswith(other: ty)
68 + for i=0, other.ct do
69 + if other(i) == 0 then return true end
70 + if other(i) ~= self(i) then return false end
71 + end
72 + return true
66 73 end
67 74 terra ty:ffw()
68 75 var newp = m.ffw(self.ptr,self.ct)
69 76 var newct = self.ct - (newp - self.ptr)
70 77 return ty { ptr = newp, ct = newct }
71 78 end
72 79 terra ty:blob()
................................................................................
559 566 var cur = str while cur.ct > 0 do
560 567 var add, cont = disemvowel_codepoint(cur)
561 568 if add:ref() then acc:ppush(add) end
562 569 cur = cont
563 570 end
564 571 return acc:finalize()
565 572 end
573 +
574 +terra m.qesc(pool: &lib.mem.pool, str: m.t): m.t
575 + -- escape double-quotes
576 + var a: m.acc a:pool(pool, str.ct + str.ct/2)
577 + a:lpush '"'
578 + for i=0, str.ct do
579 + if str(i) == @'"' then a:lpush '\\"'
580 + elseif str(i) == @'\\' then a:lpush '\\\\'
581 + elseif str(i) < 0x20 then -- for json
582 + var hex = lib.math.hexbyte(str(i))
583 + a:lpush('\\u00'):push(&hex[0], 2)
584 + else a:push(str.ptr + i,1) end
585 + end
586 + a:lpush '"'
587 + return a:finalize()
588 +end
566 589
567 590 return m