- assert count >= 0
- count += from
- if from < 0 then from = 0
- if count > length then count = length
- if from < count then
- var r = new Buffer.with_capacity(count - from)
- while from < count do
- r.chars.push(_items[from])
- from += 1
- end
- return r.to_s
- else
- return ""
+ return index_of_from(c, 0)
+ end
+
+ # Gets the last char of self
+ #
+ # DEPRECATED : Use self.chars.last instead
+ fun last: Char do return self.chars[length-1]
+
+ # Gets the index of the first occurence of ´c´ starting from ´pos´
+ #
+ # Returns -1 if not found
+ #
+ # DEPRECATED : Use self.chars.index_of_from instead
+ fun index_of_from(c: Char, pos: Int): Int
+ do
+ var iter = self.chars.iterator_from(pos)
+ while iter.is_ok do
+ if iter.item == c then return iter.index
+ end
+ return -1
+ end
+
+ # Gets the last index of char ´c´
+ #
+ # Returns -1 if not found
+ #
+ # DEPRECATED : Use self.chars.last_index_of instead
+ fun last_index_of(c: Char): Int
+ do
+ return last_index_of_from(c, length - 1)
+ end
+
+ # The index of the last occurrence of an element starting from pos (in reverse order).
+ # Example :
+ # assert "/etc/bin/test/test.nit".last_index_of_from('/', length-1) == 13
+ # assert "/etc/bin/test/test.nit".last_index_of_from('/', 12) == 8
+ #
+ # Returns -1 if not found
+ #
+ # DEPRECATED : Use self.chars.last_index_of_from instead
+ fun last_index_of_from(item: Char, pos: Int): Int
+ do
+ var iter = self.chars.reverse_iterator_from(pos)
+ while iter.is_ok do
+ if iter.item == item then return iter.index
+ iter.next