From 9765c08bf5b61120d90307818ad9ead177f27fbc Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Fri, 27 Nov 2015 11:06:29 -0500 Subject: [PATCH] lib/core: Added `add_char` method to `Bytes` Signed-off-by: Lucas Bajolet --- lib/core/bytes.nit | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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" -- 1.7.9.5