lib/standard/bytes: Added pop method
authorLucas Bajolet <r4pass@hotmail.com>
Mon, 13 Jul 2015 14:45:18 +0000 (10:45 -0400)
committerLucas Bajolet <r4pass@hotmail.com>
Mon, 13 Jul 2015 14:45:18 +0000 (10:45 -0400)
Signed-off-by: Lucas Bajolet <r4pass@hotmail.com>

lib/standard/bytes.nit

index 2a3526f..21d54d0 100644 (file)
@@ -96,6 +96,16 @@ class Bytes
                end
        end
 
+       #     var b = new Bytes.empty
+       #     b.append([0x41u8, 0x41u8, 0x18u8])
+       #     b.pop
+       #     assert b.to_s == "AA"
+       redef fun pop do
+               assert length >= 1
+               length -= 1
+               return items[length]
+       end
+
        redef fun clear do length = 0
 
        # Regenerates the buffer, necessary when it was persisted