protected fun first_byte: Int do return 0
# Last byte of the NativeString
- protected fun last_byte: Int do return _bytelen - 1
+ protected fun last_byte: Int do return first_byte + _bytelen - 1
# Cache of the latest position (char) explored in the string
var position: Int = 0
end
pos += 1
end
- var s = new FlatString.with_infos(nits, nlen, 0, nlen - 1)
+ var s = new FlatString.with_infos(nits, nlen, 0)
return s
end
# Index at which `self` begins in `_items`, inclusively
redef var first_byte is noinit
- # Index at which `self` ends in `_items`, inclusively
- redef var last_byte is noinit
-
redef var chars = new FlatStringCharView(self) is lazy
redef var bytes = new FlatStringByteView(self) is lazy
#
# `_items` will be used as is, without copy, to retrieve the characters of the string.
# Aliasing issues is the responsibility of the caller.
- private init with_infos(items: NativeString, bytelen, from, to: Int)
+ private init with_infos(items: NativeString, bytelen, from: Int)
do
self._items = items
self._bytelen = bytelen
_first_byte = from
- _last_byte = to
_bytepos = from
end
#
# `_items` will be used as is, without copy, to retrieve the characters of the string.
# Aliasing issues is the responsibility of the caller.
- private init full(items: NativeString, bytelen, from, to, length: Int)
+ private init full(items: NativeString, bytelen, from, length: Int)
do
self._items = items
self.length = length
self._bytelen = bytelen
_first_byte = from
- _last_byte = to
_bytepos = from
end
var ns = new NativeString(nlen + 1)
mits.copy_to(ns, mlen, mifrom, 0)
sits.copy_to(ns, slen, sifrom, mlen)
- return new FlatString.full(ns, nlen, 0, nlen - 1, length + o.length)
+ return new FlatString.full(ns, nlen, 0, _length + o.length)
else
abort
end
offset += mybtlen
i -= 1
end
- return new FlatString.full(ns, new_bytelen, 0, new_bytelen - 1, newlen)
+ return new FlatString.full(ns, new_bytelen, 0, newlen)
end
var i = _first_byte
var my_items = _items
- var max = _last_byte
+ var max = last_byte
while i <= max do
h = (h << 5) + h + my_items[i].to_i
curr_pos += tgt._first_byte
end
- redef fun is_ok do return curr_pos <= target._last_byte
+ redef fun is_ok do return curr_pos <= target.last_byte
redef fun item do return target_items[curr_pos]
redef fun [](index)
do
- # Check that the index (+ _first_byte) is not larger than _last_byte
+ # Check that the index (+ _first_byte) is not larger than last_byte
# In other terms, if the index is valid
assert index >= 0
var target = self.target
var ind = index + target._first_byte
- assert ind <= target._last_byte
+ assert ind <= target.last_byte
return target._items[ind]
end
written = true
var bln = _bytelen
if bln == 0 then _items = new NativeString(1)
- return new FlatString.full(_items, bln, 0, bln - 1, length)
+ return new FlatString.full(_items, bln, 0, _length)
end
redef fun to_cstring
redef fun times(repeats)
do
var bln = _bytelen
- var x = new FlatString.full(_items, bln, 0, bln - 1, length)
+ var x = new FlatString.full(_items, bln, 0, _length)
for i in [1 .. repeats[ do
append(x)
end
end
redef fun to_s_full(bytelen, unilen) do
- return new FlatString.full(self, bytelen, 0, bytelen - 1, unilen)
+ return new FlatString.full(self, bytelen, 0, unilen)
end
# Returns `self` as a new String.
if r.items != self then return r
var new_self = new NativeString(length + 1)
copy_to(new_self, length, 0, 0)
- var str = new FlatString.with_infos(new_self, length, 0, length - 1)
+ var str = new FlatString.with_infos(new_self, length, 0)
new_self[length] = 0u8
str.to_cstring = new_self
return str
end
copy_to(ret, len - old_repl, old_repl, off)
end
- return new FlatString.full(ret, end_length, 0, end_length - 1, chr_ln)
+ return new FlatString.full(ret, end_length, 0, chr_ln)
end
# Sets the next bytes at position `pos` to the value of `c`, encoded in UTF-8
var ns = new NativeString(nslen + 1)
ns[nslen] = 0u8
native_int_to_s(ns, nslen + 1)
- return new FlatString.full(ns, nslen, 0, nslen - 1, nslen)
+ return new FlatString.full(ns, nslen, 0, nslen)
end
end
end
i += 1
end
- return new FlatString.with_infos(ns, sl, 0, sl - 1)
+ return new FlatString.with_infos(ns, sl, 0)
end
end
end
i += 1
end
- return new FlatString.with_infos(ns, sl, 0, sl - 1)
+ return new FlatString.with_infos(ns, sl, 0)
end
end
var lft = _left
var llen = lft.length
if from < llen then
- if from + len < llen then return lft.substring(from,len)
+ if from + count < llen then return lft.substring(from, count)
var lsublen = llen - from
- return lft.substring_from(from) + _right.substring(0, len - lsublen)
+ return lft.substring_from(from) + _right.substring(0, count - lsublen)
else
- return _right.substring(from - llen, len)
+ return _right.substring(from - llen, count)
end
end
# the final String and re-allocates a new larger Buffer.
private fun dump_buffer do
written = false
- var nstr = new FlatString.with_infos(ns, rpos - dumped, dumped, rpos - 1)
+ var nstr = new FlatString.with_infos(ns, rpos - dumped, dumped)
str += nstr
var bs = buf_size
bs = bs * 2
# Similar to dump_buffer, but does not reallocate a new NativeString
private fun persist_buffer do
if rpos == dumped then return
- var nstr = new FlatString.with_infos(ns, rpos - dumped, dumped, rpos - 1)
+ var nstr = new FlatString.with_infos(ns, rpos - dumped, dumped)
str += nstr
dumped = rpos
end
redef fun output do
str.output
- new FlatString.with_infos(ns, rpos - dumped, dumped, rpos - 1).output
+ new FlatString.with_infos(ns, rpos - dumped, dumped).output
end
# Enlarge is useless here since the `Buffer`
redef fun reverse do
# Flush the buffer in order to only have to reverse `str`.
if rpos > 0 and dumped != rpos then
- str += new FlatString.with_infos(ns, rpos - dumped, dumped, rpos - 1)
+ str += new FlatString.with_infos(ns, rpos - dumped, dumped)
dumped = rpos
end
str = str.reversed
var ns = new NativeString(nlen + 1)
mits.copy_to(ns, mlen, mifrom, 0)
sits.copy_to(ns, slen, sifrom, mlen)
- return new FlatString.full(ns, nlen, 0, nlen - 1, length + s.length)
+ return new FlatString.full(ns, nlen, 0, length + s.length)
else if s isa Concat then
var sl = s._left
var sllen = sl.bytelen
if not subs.is_ok then return
var s = subs.item
ns = s._items
- pns = s._last_byte
+ pns = s.last_byte
end
end
init from(str: RopeBuffer) do
iter = str.str.substrings
- nsstr = new FlatString.with_infos(str.ns, str.rpos - str.dumped, str.dumped, str.rpos - 1)
+ nsstr = new FlatString.with_infos(str.ns, str.rpos - str.dumped, str.dumped)
if str.length == 0 then nsstr_done = true
end