From: Jean Privat Date: Wed, 27 Aug 2014 02:11:56 +0000 (-0400) Subject: lib/string: redefine [] for FlatString and FlatBuffer without using chars X-Git-Tag: v0.6.8~7^2~2 X-Git-Url: http://nitlanguage.org lib/string: redefine [] for FlatString and FlatBuffer without using chars Signed-off-by: Jean Privat --- diff --git a/lib/standard/string.nit b/lib/standard/string.nit index 5a0c039..e4423d3 100644 --- a/lib/standard/string.nit +++ b/lib/standard/string.nit @@ -856,6 +856,15 @@ class FlatString redef var chars: SequenceRead[Char] = new FlatStringCharView(self) + redef fun [](index) + do + # Check that the index (+ index_from) is not larger than indexTo + # In other terms, if the index is valid + assert index >= 0 + assert (index + index_from) <= index_to + return items[index + index_from] + end + ################################################ # AbstractString specific methods # ################################################ @@ -1278,6 +1287,13 @@ class FlatBuffer redef fun substrings do return new FlatSubstringsIter(self) + redef fun [](index) + do + assert index >= 0 + assert index < length + return items[index] + end + redef fun []=(index, item) do is_dirty = true