From: Lucas Bajolet Date: Fri, 27 Nov 2015 16:06:29 +0000 (-0500) Subject: lib/core: Added `add_char` method to `Bytes` X-Git-Tag: v0.8~74^2~2 X-Git-Url: http://nitlanguage.org lib/core: Added `add_char` method to `Bytes` Signed-off-by: Lucas Bajolet --- diff --git a/lib/core/bytes.nit b/lib/core/bytes.nit index 94d3d27..1efda33 100644 --- a/lib/core/bytes.nit +++ b/lib/core/bytes.nit @@ -155,6 +155,21 @@ class Bytes length += 1 end + # Adds the UTF-8 representation of `c` to `self` + # + # var b = new Bytes.empty + # b.add_char('A') + # b.add_char('キ') + # assert b.hexdigest == "41E382AD" + fun add_char(c: Char) do + if persisted then regen + var cln = c.u8char_len + var ln = length + enlarge(ln + cln) + items.set_char_at(length, c) + length += cln + end + # var b = new Bytes.empty # b.append([104u8, 101u8, 108u8, 108u8, 111u8]) # assert b.to_s == "hello"