+ # Copies the content of self in `dest`
+ fun copy(start: Int, len: Int, dest: Buffer, new_start: Int)
+ do
+ var self_chars = self.chars
+ var dest_chars = dest.chars
+ for i in [0..len-1] do
+ dest_chars[new_start+i] = self_chars[start+i]
+ end
+ end
+
+ redef fun substring(from, count)
+ do
+ assert count >= 0
+ count += from
+ if from < 0 then from = 0
+ if count > length then count = length
+ if from < count then
+ var r = new FlatBuffer.with_capacity(count - from)
+ while from < count do
+ r.chars.push(items[from])
+ from += 1
+ end
+ return r.to_s
+ else
+ return ""
+ end
+ end
+end
+
+private class FlatBufferReverseIterator
+ super IndexedIterator[Char]
+
+ var target: FlatBuffer
+
+ var target_items: NativeString
+
+ var curr_pos: Int
+
+ init with_pos(tgt: FlatBuffer, pos: Int)
+ do
+ target = tgt
+ target_items = tgt.items
+ curr_pos = pos
+ end
+
+ redef fun index do return curr_pos
+
+ redef fun is_ok do return curr_pos >= 0
+
+ redef fun item do return target_items[curr_pos]
+
+ redef fun next do curr_pos -= 1
+
+end
+
+private class FlatBufferCharView
+ super BufferCharView
+ super StringCapable
+
+ redef type SELFTYPE: FlatBuffer
+
+ redef fun [](index) do return target.items[index]
+
+ redef fun []=(index, item)
+ do
+ assert index >= 0 and index <= length
+ if index == length then
+ add(item)
+ return
+ end
+ target.items[index] = item
+ end
+
+ redef fun push(c)
+ do
+ target.add(c)
+ end
+
+ redef fun add(c)
+ do
+ target.add(c)
+ end
+
+ fun enlarge(cap: Int)
+ do
+ target.enlarge(cap)
+ end
+
+ redef fun append(s)
+ do
+ var my_items = target.items
+ var s_length = s.length
+ if target.capacity < s.length then enlarge(s_length + target.length)
+ end
+
+ redef fun iterator_from(pos) do return new FlatBufferIterator.with_pos(target, pos)
+
+ redef fun reverse_iterator_from(pos) do return new FlatBufferReverseIterator.with_pos(target, pos)
+
+end
+
+private class FlatBufferIterator
+ super IndexedIterator[Char]
+
+ var target: FlatBuffer
+
+ var target_items: NativeString
+
+ var curr_pos: Int
+
+ init with_pos(tgt: FlatBuffer, pos: Int)
+ do
+ target = tgt
+ target_items = tgt.items
+ curr_pos = pos
+ end
+
+ redef fun index do return curr_pos
+
+ redef fun is_ok do return curr_pos < target.length
+
+ redef fun item do return target_items[curr_pos]
+
+ redef fun next do curr_pos += 1
+