import math
import collection
+intrude import collection::array
`{
#include <stdio.h>
return self.chars.iterator
end
- # Is 'c' contained in self ?
- #
- # DEPRECATED : Use self.chars.has instead
- fun has(c: Char): Bool
- do
- return self.chars.has(c)
- end
# Gets an Array containing the chars of self
#
# As with substring, a `from` index < 0 will be replaced by 0
fun substring_from(from: Int): SELFTYPE
do
- if from > self.length then return empty
+ if from >= self.length then return empty
if from < 0 then from = 0
return substring(from, length - from)
end
if iter.item.ascii > 32 then break
iter.next
end
- if iter.index == length then return self.empty
+ if iter.index < 0 then return self.empty
return self.substring(0, iter.index + 1)
end
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 #
################################################
curr_pos = pos + tgt.index_from
end
- redef fun is_ok do return curr_pos >= 0
+ redef fun is_ok do return curr_pos >= target.index_from
redef fun item do return target_items[curr_pos]
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
end
redef class Array[E]
+
# Fast implementation
redef fun to_s
do
- var s = new FlatBuffer
- var i = 0
var l = length
+ if l == 0 then return ""
+ if l == 1 then if self[0] == null then return "" else return self[0].to_s
+ var its = _items
+ var na = new NativeArray[String](l)
+ var i = 0
+ var sl = 0
+ var mypos = 0
while i < l do
- var e = self[i]
- if e != null then s.append(e.to_s)
+ var itsi = its[i]
+ if itsi == null then
+ i += 1
+ continue
+ end
+ var tmp = itsi.to_s
+ sl += tmp.length
+ na[mypos] = tmp
i += 1
+ mypos += 1
end
- return s.to_s
+ var ns = new NativeString(sl + 1)
+ ns[sl] = '\0'
+ i = 0
+ var off = 0
+ while i < mypos do
+ var tmp = na[i]
+ var tpl = tmp.length
+ if tmp isa FlatString then
+ tmp.items.copy_to(ns, tpl, tmp.index_from, off)
+ off += tpl
+ else
+ for j in tmp.substrings do
+ var s = j.as(FlatString)
+ var slen = s.length
+ s.items.copy_to(ns, slen, s.index_from, off)
+ off += slen
+ end
+ end
+ i += 1
+ end
+ return ns.to_s_with_length(sl)
end
end
end
redef class Sys
- var _args_cache: nullable Sequence[String]
+ private var args_cache: nullable Sequence[String]
# The arguments of the program as given by the OS
fun program_args: Sequence[String]