text/ropes: Fixed `RopeBuffer::add` when dealing with something other than an ASCII...
authorLucas Bajolet <r4pass@hotmail.com>
Fri, 30 Oct 2015 15:23:45 +0000 (11:23 -0400)
committerLucas Bajolet <r4pass@hotmail.com>
Fri, 6 Nov 2015 21:33:47 +0000 (16:33 -0500)
Signed-off-by: Lucas Bajolet <r4pass@hotmail.com>

lib/core/text/ropes.nit

index c164529..bcfa7e5 100644 (file)
@@ -463,14 +463,15 @@ class RopeBuffer
 
        redef fun add(c) do
                var rp = rpos
-               if rp >= buf_size then
+               var remsp = buf_size - rp
+               var cln = c.u8char_len
+               if cln > remsp then
                        dump_buffer
                        rp = 0
                end
-               # TODO: Fix when supporting UTF-8
-               ns[rp] = c.ascii
-               rp += 1
-               _bytelen += 1
+               ns.set_char_at(rp, c)
+               rp += cln
+               _bytelen += cln
                rpos = rp
        end