lib/string_exp/utf8_noindex: Added cache for last access.
authorLucas Bajolet <r4pass@hotmail.com>
Mon, 18 Aug 2014 15:59:07 +0000 (11:59 -0400)
committerLucas Bajolet <r4pass@hotmail.com>
Mon, 18 Aug 2014 15:59:07 +0000 (11:59 -0400)
Signed-off-by: Lucas Bajolet <r4pass@hotmail.com>

lib/string_experimentations/utf8_noindex.nit

index cef60f7..199428a 100644 (file)
@@ -171,6 +171,14 @@ extern class UnicodeChar `{ uint32_t* `}
        `}
 end
 
+# Used to keep track of the last accessed char in a String
+class CharCache
+       # The position (as in char) of a String
+       var position: Int
+       # The position in the NativeString underlying the String
+       var bytepos: Int
+end
+
 class FlatStringReviter
        super IndexedIterator[UnicodeChar]
 
@@ -263,6 +271,9 @@ redef class FlatString
        # Length in bytes of the string (e.g. the length of the C string)
        redef var bytelen: Int
 
+       # Cache for the last accessed character in the char
+       var cache = new CharCache(-1,-1)
+
        redef var length = length_l is lazy
 
        private init full(items: NativeString, from, to, bytelen, len: Int)