+ # Index in _items of the start of the string
+ private var index_from: Int
+
+ # Indes in _items of the last item of the string
+ private var index_to: Int
+
+ redef var chars: StringCharView = new FlatStringCharView(self)
+
+ ################################################
+ # AbstractString specific methods #
+ ################################################
+
+ redef fun [](index) do
+ assert index >= 0
+ # Check that the index (+ index_from) is not larger than indexTo
+ # In other terms, if the index is valid
+ assert (index + index_from) <= index_to
+ return items[index + index_from]
+ end
+
+ redef fun substring(from: Int, count: Int): String
+ do
+ assert count >= 0
+
+ if from < 0 then
+ count += from
+ if count < 0 then count = 0
+ from = 0
+ end
+
+ var realFrom = index_from + from
+
+ if (realFrom + count) > index_to then return new String.with_infos(items, index_to - realFrom + 1, realFrom, index_to)
+
+ if count == 0 then return ""
+
+ var to = realFrom + count - 1
+
+ return new String.with_infos(items, to - realFrom + 1, realFrom, to)
+ end
+
+ redef fun to_upper: String
+ do
+ var outstr = calloc_string(self.length + 1)
+ var out_index = 0
+
+ var myitems = self.items
+ var index_from = self.index_from
+ var max = self.index_to
+
+ while index_from <= max do
+ outstr[out_index] = myitems[index_from].to_upper
+ out_index += 1
+ index_from += 1
+ end
+
+ outstr[self.length] = '\0'
+
+ return outstr.to_s_with_length(self.length)
+ end
+
+ redef fun to_lower : String
+ do
+ var outstr = calloc_string(self.length + 1)
+ var out_index = 0
+
+ var myitems = self.items
+ var index_from = self.index_from
+ var max = self.index_to
+
+ while index_from <= max do
+ outstr[out_index] = myitems[index_from].to_lower
+ out_index += 1
+ index_from += 1
+ end
+
+ outstr[self.length] = '\0'
+
+ return outstr.to_s_with_length(self.length)
+ end
+
+ redef fun trim: String
+ do
+ if self.length == 0 then return self
+ # find position of the first non white space char (ascii < 32) from the start of the string
+ var start_pos = self.index_from
+ while items[start_pos].ascii <= 32 do
+ start_pos += 1
+ if start_pos == index_to + 1 then return ""
+ end
+ # find position of the first non white space char from the end of the string
+ var end_pos = index_to
+ while items[end_pos].ascii <= 32 do
+ end_pos -= 1
+ if end_pos == start_pos then return items[start_pos].to_s
+ end
+ start_pos -= index_from
+ end_pos -= index_from
+ return self.substring(start_pos, end_pos - start_pos + 1)
+ end
+
+ redef fun output