Signed-off-by: Lucas Bajolet <r4pass@hotmail.com>
29 files changed:
# If using the default padding character `=`, see `encode_base64`.
fun encode_base64(padding: nullable Byte): String
do
# If using the default padding character `=`, see `encode_base64`.
fun encode_base64(padding: nullable Byte): String
do
- return to_cstring.encode_base64(bytelen, padding).to_s
+ return to_cstring.encode_base64(byte_length, padding).to_s
end
# Decodes the receiver string to base64 using a custom padding character.
end
# Decodes the receiver string to base64 using a custom padding character.
# Default padding character `=`
fun decode_base64(padding : nullable Byte) : String
do
# Default padding character `=`
fun decode_base64(padding : nullable Byte) : String
do
- return to_cstring.decode_base64(bytelen, padding).to_s
+ return to_cstring.decode_base64(byte_length, padding).to_s
# Compared to `write_string`, this method supports null bytes in `text`.
fun write_block(text: Text)
do
# Compared to `write_string`, this method supports null bytes in `text`.
fun write_block(text: Text)
do
- write_int64 text.bytelen
+ write_int64 text.byte_length
redef class Text
# Get a `NSString` from `self`
redef class Text
# Get a `NSString` from `self`
- fun to_nsstring: NSString do return to_cstring.to_nsstring(bytelen)
+ fun to_nsstring: NSString do return to_cstring.to_nsstring(byte_length)
end
# Wrapper of byte buffers
end
# Wrapper of byte buffers
# Appends the bytes of `s` to `selftextextt`
fun append_text(s: Text) do
for i in s.substrings do
# Appends the bytes of `s` to `selftextextt`
fun append_text(s: Text) do
for i in s.substrings do
- append_ns(i.fast_cstring, i.bytelen)
+ append_ns(i.fast_cstring, i.byte_length)
# assert "String".to_bytes == [83u8, 116u8, 114u8, 105u8, 110u8, 103u8]
# ~~~
fun to_bytes: Bytes do
# assert "String".to_bytes == [83u8, 116u8, 114u8, 105u8, 110u8, 103u8]
# ~~~
fun to_bytes: Bytes do
- var b = new Bytes.with_capacity(bytelen)
+ var b = new Bytes.with_capacity(byte_length)
append_to_bytes b
return b
end
append_to_bytes b
return b
end
fun append_to_bytes(b: Bytes) do
for s in substrings do
var from = if s isa FlatString then s.first_byte else 0
fun append_to_bytes(b: Bytes) do
for s in substrings do
var from = if s isa FlatString then s.first_byte else 0
- b.append_ns_from(s.items, s.bytelen, from)
+ b.append_ns_from(s.items, s.byte_length, from)
# assert "a b c".hexdigest_to_bytes.hexdigest == "0ABC"
fun hexdigest_to_bytes: Bytes do
var b = bytes
# assert "a b c".hexdigest_to_bytes.hexdigest == "0ABC"
fun hexdigest_to_bytes: Bytes do
var b = bytes
var dlength = 0 # Number of hex digits
var pos = 0
var dlength = 0 # Number of hex digits
var pos = 0
#
# assert "<STRING/&rt;".hexdigest == "266C743B535452494E47262334373B2672743B"
fun hexdigest: String do
#
# assert "<STRING/&rt;".hexdigest == "266C743B535452494E47262334373B2672743B"
fun hexdigest: String do
var outns = new NativeString(ln * 2)
var oi = 0
for i in [0 .. ln[ do
var outns = new NativeString(ln * 2)
var oi = 0
for i in [0 .. ln[ do
# assert "\\x41\\x42\\x43".unescape_to_bytes.chexdigest == "\\x41\\x42\\x43"
# assert "B\\n\\x41\\u0103D3".unescape_to_bytes.chexdigest == "\\x42\\x0A\\x41\\xF0\\x90\\x8F\\x93"
fun unescape_to_bytes: Bytes do
# assert "\\x41\\x42\\x43".unescape_to_bytes.chexdigest == "\\x41\\x42\\x43"
# assert "B\\n\\x41\\u0103D3".unescape_to_bytes.chexdigest == "\\x42\\x0A\\x41\\xF0\\x90\\x8F\\x93"
fun unescape_to_bytes: Bytes do
- var res = new Bytes.with_capacity(self.bytelen)
+ var res = new Bytes.with_capacity(self.byte_length)
var was_slash = false
var i = 0
while i < length do
var was_slash = false
var i = 0
while i < length do
fun binarydigest_to_bytes: Bytes
do
var b = bytes
fun binarydigest_to_bytes: Bytes
do
var b = bytes
# Count bits
var bitlen = 0
# Count bits
var bitlen = 0
redef class FlatText
redef fun append_to_bytes(b) do
var from = if self isa FlatString then first_byte else 0
redef class FlatText
redef fun append_to_bytes(b) do
var from = if self isa FlatString then first_byte else 0
- b.append_ns_from(items, bytelen, from)
+ b.append_ns_from(items, byte_length, from)
end
redef fun encode_string(s) do
end
redef fun encode_string(s) do
- var ns = new Bytes.with_capacity(s.bytelen)
+ var ns = new Bytes.with_capacity(s.byte_length)
add_string_to(s, ns)
return ns
end
add_string_to(s, ns)
return ns
end
end
redef fun encode_string(s) do
end
redef fun encode_string(s) do
- var buf = new Bytes.with_capacity(s.bytelen)
+ var buf = new Bytes.with_capacity(s.byte_length)
add_string_to(s, buf)
return buf
end
redef fun add_string_to(s, b) do
s.append_to_bytes(b)
add_string_to(s, buf)
return buf
end
redef fun add_string_to(s, b) do
s.append_to_bytes(b)
end
redef fun is_valid_char(ns, len) do
end
redef fun is_valid_char(ns, len) do
if rit == ns then
var nns = new NativeString(len)
rit.copy_to(nns, len, 0, 0)
if rit == ns then
var nns = new NativeString(len)
rit.copy_to(nns, len, 0, 0)
- return nns.to_s_full(ret.bytelen, ret.length)
+ return nns.to_s_full(ret.byte_length, ret.length)
private fun write_native_to(s: FileWriter)
do
private fun write_native_to(s: FileWriter)
do
- for i in substrings do s.write_native(i.to_cstring, 0, i.bytelen)
+ for i in substrings do s.write_native(i.to_cstring, 0, i.byte_length)
redef class FlatString
redef fun write_native_to(s)
do
redef class FlatString
redef fun write_native_to(s)
do
- s.write_native(items, first_byte, bytelen)
+ s.write_native(items, first_byte, byte_length)
end
redef fun file_extension do
end
redef fun file_extension do
# assert not "Not an Int".is_int
# assert not "-".is_int
fun is_int: Bool do
# assert not "Not an Int".is_int
# assert not "-".is_int
fun is_int: Bool do
- if bytelen == 0 then return false
+ if byte_length == 0 then return false
var s = remove_all('_')
var pos = 0
var len = s.length
var s = remove_all('_')
var pos = 0
var len = s.length
# Actually execute
var cstr = text.to_cstring
# Actually execute
var cstr = text.to_cstring
- var rets = cstr.to_s_with_length(text.bytelen)
+ var rets = cstr.to_s_with_length(text.byte_length)
var bytefrom = cstr.char_to_byte_index_cached(charfrom, 0, 0)
var subcstr = cstr.fast_cstring(bytefrom)
var eflags = gather_eflags
var bytefrom = cstr.char_to_byte_index_cached(charfrom, 0, 0)
var subcstr = cstr.fast_cstring(bytefrom)
var eflags = gather_eflags
# Actually execute
var cstr = text.to_cstring
var subcstr = cstr
# Actually execute
var cstr = text.to_cstring
var subcstr = cstr
- var rets = cstr.to_s_with_length(text.bytelen)
+ var rets = cstr.to_s_with_length(text.byte_length)
var eflags = gather_eflags
var eflags_or_notbol = eflags | flag_notbol
var native_match = self.native_match
var eflags = gather_eflags
var eflags_or_notbol = eflags | flag_notbol
var native_match = self.native_match
var rets = ""
var pos = 0
var str = s.items.clean_utf8(slen)
var rets = ""
var pos = 0
var str = s.items.clean_utf8(slen)
var sits = str.items
var remsp = slen
while pos < slen do
var sits = str.items
var remsp = slen
while pos < slen do
break
end
var st = sits.find_beginning_of_char_at(pos + chunksz - 1)
break
end
var st = sits.find_beginning_of_char_at(pos + chunksz - 1)
- var bytelen = st - pos
- rets += new FlatString.with_infos(sits, bytelen, pos)
+ var byte_length = st - pos
+ rets += new FlatString.with_infos(sits, byte_length, pos)
end
if rets isa Concat then return rets.balance
return rets
end
if rets isa Concat then return rets.balance
return rets
return new Bytes(nns, nslen, nslen)
end
return new Bytes(nns, nslen, nslen)
end
- redef fun eof do return cursor >= source.bytelen
+ redef fun eof do return cursor >= source.byte_length
# Number of bytes in `self`
#
# Number of bytes in `self`
#
- # assert "12345".bytelen == 5
- # assert "あいうえお".bytelen == 15
- fun bytelen: Int is abstract
+ # assert "12345".byte_length == 5
+ # assert "あいうえお".byte_length == 15
+ fun byte_length: Int is abstract
# assert "%c3%a9%e3%81%82%e3%81%84%e3%81%86".from_percent_encoding == "éあいう"
fun from_percent_encoding: String
do
# assert "%c3%a9%e3%81%82%e3%81%84%e3%81%86".from_percent_encoding == "éあいう"
fun from_percent_encoding: String
do
var has_percent = false
for c in chars do
if c == '%' then
var has_percent = false
for c in chars do
if c == '%' then
+ redef var byte_length = 0
redef fun is_empty do return target.is_empty
redef fun is_empty do return target.is_empty
- redef fun length do return target.bytelen
+ redef fun length do return target.byte_length
redef fun iterator do return self.iterator_from(0)
redef fun iterator do return self.iterator_from(0)
- redef fun reverse_iterator do return self.reverse_iterator_from(target.bytelen - 1)
+ redef fun reverse_iterator do return self.reverse_iterator_from(target.byte_length - 1)
end
# Immutable sequence of characters.
end
# Immutable sequence of characters.
# use only when the data has already been verified as valid UTF-8.
fun to_s_unsafe(length: nullable Int): String is abstract
# use only when the data has already been verified as valid UTF-8.
fun to_s_unsafe(length: nullable Int): String is abstract
- # Get a `String` from the raw `bytelen` bytes at `self` with `unilen` Unicode characters
+ # Get a `String` from the raw `byte_length` bytes at `self` with `unilen` Unicode characters
#
# The created `String` points to the data at `self`.
# This method should be used when `self` was allocated by the Nit GC,
#
# The created `String` points to the data at `self`.
# This method should be used when `self` was allocated by the Nit GC,
# use only when the data has already been verified as valid UTF-8.
#
# SEE: `abstract_text::Text` for more info on the difference
# use only when the data has already been verified as valid UTF-8.
#
# SEE: `abstract_text::Text` for more info on the difference
- # between `Text::bytelen` and `Text::length`.
- fun to_s_full(bytelen, unilen: Int): String is abstract
+ # between `Text::byte_length` and `Text::length`.
+ fun to_s_full(byte_length, unilen: Int): String is abstract
# Copies the content of `src` to `self`
#
# Copies the content of `src` to `self`
#
- # NOTE: `self` must be large enough to withold `self.bytelen` bytes
- fun fill_from(src: Text) do src.copy_to_native(self, src.bytelen, 0, 0)
+ # NOTE: `self` must be large enough to withold `self.byte_length` bytes
+ fun fill_from(src: Text) do src.copy_to_native(self, src.byte_length, 0, 0)
end
redef class NativeArray[E]
end
redef class NativeArray[E]
protected fun first_byte: Int do return 0
# Last byte of the NativeString
protected fun first_byte: Int do return 0
# Last byte of the NativeString
- protected fun last_byte: Int do return first_byte + _bytelen - 1
+ protected fun last_byte: Int do return first_byte + _byte_length - 1
# Cache of the latest position (char) explored in the string
var position: Int = 0
# Cache of the latest position (char) explored in the string
var position: Int = 0
var its = _items
var max = last_byte
var pos = first_byte
var its = _items
var max = last_byte
var pos = first_byte
- var nlen = extra + _bytelen
+ var nlen = extra + _byte_length
var nits = new NativeString(nlen)
var outpos = 0
while pos <= max do
var nits = new NativeString(nlen)
var outpos = 0
while pos <= max do
if ln_extra == 0 then return self.to_s
var its = _items
var max = last_byte
if ln_extra == 0 then return self.to_s
var its = _items
var max = last_byte
- var nlen = _bytelen + ln_extra
+ var nlen = _byte_length + ln_extra
var nns = new NativeString(nlen)
var pos = first_byte
var opos = 0
var nns = new NativeString(nlen)
var pos = first_byte
var opos = 0
redef var bytes = new FlatStringByteView(self) is lazy
redef var to_cstring is lazy do
redef var bytes = new FlatStringByteView(self) is lazy
redef var to_cstring is lazy do
+ var blen = _byte_length
var new_items = new NativeString(blen + 1)
_items.copy_to(new_items, blen, _first_byte, 0)
new_items[blen] = 0u8
var new_items = new NativeString(blen + 1)
_items.copy_to(new_items, blen, _first_byte, 0)
new_items[blen] = 0u8
end
redef fun reversed do
end
redef fun reversed do
- var b = new FlatBuffer.with_capacity(_bytelen + 1)
+ var b = new FlatBuffer.with_capacity(_byte_length + 1)
var i = _length - 1
while i >= 0 do
b.add self.fetch_char_at(i)
var i = _length - 1
while i >= 0 do
b.add self.fetch_char_at(i)
- var outstr = new FlatBuffer.with_capacity(self._bytelen + 1)
+ var outstr = new FlatBuffer.with_capacity(self._byte_length + 1)
var mylen = _length
var pos = 0
var mylen = _length
var pos = 0
- var outstr = new FlatBuffer.with_capacity(self._bytelen + 1)
+ var outstr = new FlatBuffer.with_capacity(self._byte_length + 1)
var mylen = _length
var pos = 0
var mylen = _length
var pos = 0
#
# `_items` will be used as is, without copy, to retrieve the characters of the string.
# Aliasing issues is the responsibility of the caller.
#
# `_items` will be used as is, without copy, to retrieve the characters of the string.
# Aliasing issues is the responsibility of the caller.
- private new with_infos(items: NativeString, bytelen, from: Int)
+ private new with_infos(items: NativeString, byte_length, from: Int)
- var len = items.utf8_length(from, bytelen)
- if bytelen == len then return new ASCIIFlatString.full_data(items, bytelen, from, len)
- return new UnicodeFlatString.full_data(items, bytelen, from, len)
+ var len = items.utf8_length(from, byte_length)
+ if byte_length == len then return new ASCIIFlatString.full_data(items, byte_length, from, len)
+ return new UnicodeFlatString.full_data(items, byte_length, from, len)
end
# Low-level creation of a new string with all the data.
#
# `_items` will be used as is, without copy, to retrieve the characters of the string.
# Aliasing issues is the responsibility of the caller.
end
# Low-level creation of a new string with all the data.
#
# `_items` will be used as is, without copy, to retrieve the characters of the string.
# Aliasing issues is the responsibility of the caller.
- private new full(items: NativeString, bytelen, from, length: Int)
+ private new full(items: NativeString, byte_length, from, length: Int)
- if bytelen == length then return new ASCIIFlatString.full_data(items, bytelen, from, length)
- return new UnicodeFlatString.full_data(items, bytelen, from, length)
+ if byte_length == length then return new ASCIIFlatString.full_data(items, byte_length, from, length)
+ return new UnicodeFlatString.full_data(items, byte_length, from, length)
if self.object_id == other.object_id then return true
if self.object_id == other.object_id then return true
- var my_length = _bytelen
+ var my_length = _byte_length
- if other._bytelen != my_length then return false
+ if other._byte_length != my_length then return false
var my_index = _first_byte
var its_index = other.first_byte
var my_index = _first_byte
var its_index = other.first_byte
var myits = _items
var itsits = other._items
var myits = _items
var itsits = other._items
- var mbt = _bytelen
- var obt = other.bytelen
+ var mbt = _byte_length
+ var obt = other.byte_length
var minln = if mbt < obt then mbt else obt
var mst = _first_byte
var minln = if mbt < obt then mbt else obt
var mst = _first_byte
redef fun +(o) do
var s = o.to_s
redef fun +(o) do
var s = o.to_s
- var slen = s.bytelen
- var mlen = _bytelen
+ var slen = s.byte_length
+ var mlen = _byte_length
var nlen = mlen + slen
var mits = _items
var mifrom = _first_byte
var nlen = mlen + slen
var mits = _items
var mifrom = _first_byte
- var mybtlen = _bytelen
- var new_bytelen = mybtlen * i
+ var mybtlen = _byte_length
+ var new_byte_length = mybtlen * i
var mylen = _length
var newlen = mylen * i
var its = _items
var fb = _first_byte
var mylen = _length
var newlen = mylen * i
var its = _items
var fb = _first_byte
- var ns = new NativeString(new_bytelen + 1)
- ns[new_bytelen] = 0u8
+ var ns = new NativeString(new_byte_length + 1)
+ ns[new_byte_length] = 0u8
var offset = 0
while i > 0 do
its.copy_to(ns, mybtlen, fb, offset)
offset += mybtlen
i -= 1
end
var offset = 0
while i > 0 do
its.copy_to(ns, mybtlen, fb, offset)
offset += mybtlen
i -= 1
end
- return new FlatString.full(ns, new_bytelen, 0, newlen)
+ return new FlatString.full(ns, new_byte_length, 0, newlen)
private class UnicodeFlatString
super FlatString
private class UnicodeFlatString
super FlatString
- init full_data(items: NativeString, bytelen, from, length: Int) do
+ init full_data(items: NativeString, byte_length, from, length: Int) do
self._items = items
self._length = length
self._items = items
self._length = length
- self._bytelen = bytelen
+ self._byte_length = byte_length
_first_byte = from
_bytepos = from
end
_first_byte = from
_bytepos = from
end
if from <= 0 then return self
var c = char_to_byte_index(from)
var st = c - _first_byte
if from <= 0 then return self
var c = char_to_byte_index(from)
var st = c - _first_byte
+ var fln = byte_length - st
return new FlatString.full(items, fln, c, _length - from)
end
end
return new FlatString.full(items, fln, c, _length - from)
end
end
private class ASCIIFlatString
super FlatString
private class ASCIIFlatString
super FlatString
- init full_data(items: NativeString, bytelen, from, length: Int) do
+ init full_data(items: NativeString, byte_length, from, length: Int) do
self._items = items
self._length = length
self._items = items
self._length = length
- self._bytelen = bytelen
+ self._byte_length = byte_length
_first_byte = from
_bytepos = from
end
redef fun [](idx) do
_first_byte = from
_bytepos = from
end
redef fun [](idx) do
- assert idx < _bytelen and idx >= 0
+ assert idx < _byte_length and idx >= 0
return _items[idx + _first_byte].ascii
end
return _items[idx + _first_byte].ascii
end
end
redef fun reversed do
end
redef fun reversed do
- var b = new FlatBuffer.with_capacity(_bytelen + 1)
+ var b = new FlatBuffer.with_capacity(_byte_length + 1)
var i = _length - 1
while i >= 0 do
b.add self[i]
var i = _length - 1
while i >= 0 do
b.add self[i]
# Check that the index (+ _first_byte) is not larger than last_byte
# In other terms, if the index is valid
var target = _target
# Check that the index (+ _first_byte) is not larger than last_byte
# In other terms, if the index is valid
var target = _target
- assert index >= 0 and index < target._bytelen
+ assert index >= 0 and index < target._byte_length
var ind = index + target._first_byte
return target._items[ind]
end
var ind = index + target._first_byte
return target._items[ind]
end
# the Copy-On-Write flag `written` is set at true.
private fun reset do
var nns = new NativeString(capacity)
# the Copy-On-Write flag `written` is set at true.
private fun reset do
var nns = new NativeString(capacity)
- if _bytelen != 0 then _items.copy_to(nns, _bytelen, 0, 0)
+ if _byte_length != 0 then _items.copy_to(nns, _byte_length, 0, 0)
_items = nns
written = false
end
# Shifts the content of the buffer by `len` bytes to the right, starting at byte `from`
#
_items = nns
written = false
end
# Shifts the content of the buffer by `len` bytes to the right, starting at byte `from`
#
- # Internal only, does not modify _bytelen or length, this is the caller's responsability
+ # Internal only, does not modify _byte_length or length, this is the caller's responsability
private fun rshift_bytes(from: Int, len: Int) do
var oit = _items
var nit = _items
private fun rshift_bytes(from: Int, len: Int) do
var oit = _items
var nit = _items
if bt + len > capacity then
capacity = capacity * 2 + 2
nit = new NativeString(capacity)
if bt + len > capacity then
capacity = capacity * 2 + 2
nit = new NativeString(capacity)
# Shifts the content of the buffer by `len` bytes to the left, starting at `from`
#
# Shifts the content of the buffer by `len` bytes to the left, starting at `from`
#
- # Internal only, does not modify _bytelen or length, this is the caller's responsability
+ # Internal only, does not modify _byte_length or length, this is the caller's responsability
private fun lshift_bytes(from: Int, len: Int) do
var it = _items
private fun lshift_bytes(from: Int, len: Int) do
var it = _items
- it.copy_to(it, _bytelen - from, from, from - len)
+ it.copy_to(it, _byte_length - from, from, from - len)
end
redef fun []=(index, item)
end
redef fun []=(index, item)
else if size_diff < 0 then
lshift_bytes(ip + clen, -size_diff)
end
else if size_diff < 0 then
lshift_bytes(ip + clen, -size_diff)
end
+ _byte_length += size_diff
it.set_char_at(ip, item)
end
it.set_char_at(ip, item)
end
if written then reset
is_dirty = true
var clen = c.u8char_len
if written then reset
is_dirty = true
var clen = c.u8char_len
enlarge(bt + clen)
_items.set_char_at(bt, c)
enlarge(bt + clen)
_items.set_char_at(bt, c)
_length += 1
end
redef fun clear do
is_dirty = true
_length += 1
end
redef fun clear do
is_dirty = true
_length = 0
if written then
_capacity = 16
_length = 0
if written then
_capacity = 16
# The COW flag can be set at false here, since
# it does a copy of the current `Buffer`
written = false
# The COW flag can be set at false here, since
# it does a copy of the current `Buffer`
written = false
var a = new NativeString(c)
if bln > 0 then
var it = _items
var a = new NativeString(c)
if bln > 0 then
var it = _items
redef fun to_s
do
written = true
redef fun to_s
do
written = true
if bln == 0 then _items = new NativeString(1)
return new FlatString.full(_items, bln, 0, _length)
end
if bln == 0 then _items = new NativeString(1)
return new FlatString.full(_items, bln, 0, _length)
end
redef fun to_cstring
do
if is_dirty then
redef fun to_cstring
do
if is_dirty then
var new_native = new NativeString(bln + 1)
new_native[bln] = 0u8
if _length > 0 then _items.copy_to(new_native, bln, 0, 0)
var new_native = new NativeString(bln + 1)
new_native[bln] = 0u8
if _length > 0 then _items.copy_to(new_native, bln, 0, 0)
#
# If `_items` is shared, `written` should be set to true after the creation
# so that a modification will do a copy-on-write.
#
# If `_items` is shared, `written` should be set to true after the creation
# so that a modification will do a copy-on-write.
- private init with_infos(items: NativeString, capacity, bytelen, length: Int)
+ private init with_infos(items: NativeString, capacity, byte_length, length: Int)
do
self._items = items
self.capacity = capacity
do
self._items = items
self.capacity = capacity
- self._bytelen = bytelen
+ self._byte_length = byte_length
self._length = length
end
# Create a new string copied from `s`.
init from(s: Text)
do
self._length = length
end
# Create a new string copied from `s`.
init from(s: Text)
do
- _items = new NativeString(s.bytelen)
- for i in s.substrings do i._items.copy_to(_items, i._bytelen, first_byte, 0)
- _bytelen = s.bytelen
+ _items = new NativeString(s.byte_length)
+ for i in s.substrings do i._items.copy_to(_items, i._byte_length, first_byte, 0)
+ _byte_length = s.byte_length
+ _capacity = _byte_length
end
# Create a new empty string with a given capacity.
end
# Create a new empty string with a given capacity.
assert cap >= 0
_items = new NativeString(cap)
capacity = cap
assert cap >= 0
_items = new NativeString(cap)
capacity = cap
end
redef fun append(s)
do
if s.is_empty then return
is_dirty = true
end
redef fun append(s)
do
if s.is_empty then return
is_dirty = true
- var sl = s.bytelen
- var nln = _bytelen + sl
+ var sl = s.byte_length
+ var nln = _byte_length + sl
enlarge(nln)
if s isa FlatText then
enlarge(nln)
if s isa FlatText then
- s._items.copy_to(_items, sl, s.first_byte, _bytelen)
+ s._items.copy_to(_items, sl, s.first_byte, _byte_length)
else
for i in s.substrings do append i
return
end
else
for i in s.substrings do append i
return
end
var bytest = s.char_to_byte_index(from)
var bytend = s.char_to_byte_index(from + length - 1)
var btln = bytend - bytest + 1
var bytest = s.char_to_byte_index(from)
var bytend = s.char_to_byte_index(from + length - 1)
var btln = bytend - bytest + 1
- enlarge(btln + _bytelen)
- s._items.copy_to(_items, btln, bytest, _bytelen)
- _bytelen += btln
+ enlarge(btln + _byte_length)
+ s._items.copy_to(_items, btln, bytest, _byte_length)
+ _byte_length += btln
redef fun times(repeats)
do
redef fun times(repeats)
do
var x = new FlatString.full(_items, bln, 0, _length)
for i in [1 .. repeats[ do
append(x)
var x = new FlatString.full(_items, bln, 0, _length)
for i in [1 .. repeats[ do
append(x)
redef fun index do return curr_pos
redef fun index do return curr_pos
- redef fun is_ok do return curr_pos < target._bytelen
+ redef fun is_ok do return curr_pos < target._byte_length
redef fun item do return target_items[curr_pos]
redef fun item do return target_items[curr_pos]
return clean_utf8(length)
end
return clean_utf8(length)
end
- redef fun to_s_full(bytelen, unilen) do
- return new FlatString.full(self, bytelen, 0, unilen)
+ redef fun to_s_full(byte_length, unilen) do
+ return new FlatString.full(self, byte_length, 0, unilen)
end
redef fun to_s_unsafe(len) do
end
redef fun to_s_unsafe(len) do
continue
end
var tmp = itsi.to_s
continue
end
var tmp = itsi.to_s
na[mypos] = tmp
i += 1
mypos += 1
na[mypos] = tmp
i += 1
mypos += 1
while i < mypos do
var tmp = na[i]
if tmp isa FlatString then
while i < mypos do
var tmp = na[i]
if tmp isa FlatString then
+ var tpl = tmp._byte_length
tmp._items.copy_to(ns, tpl, tmp._first_byte, off)
off += tpl
else
for j in tmp.substrings do
var s = j.as(FlatString)
tmp._items.copy_to(ns, tpl, tmp._first_byte, off)
off += tpl
else
for j in tmp.substrings do
var s = j.as(FlatString)
+ var slen = s._byte_length
s._items.copy_to(ns, slen, s._first_byte, off)
off += slen
end
s._items.copy_to(ns, slen, s._first_byte, off)
off += slen
end
var sl = 0
var mypos = 0
while i < l do
var sl = 0
var mypos = 0
while i < l do
+ sl += na[i].byte_length
while i < mypos do
var tmp = na[i]
if tmp isa FlatString then
while i < mypos do
var tmp = na[i]
if tmp isa FlatString then
+ var tpl = tmp._byte_length
tmp._items.copy_to(ns, tpl, tmp._first_byte, off)
off += tpl
else
for j in tmp.substrings do
var s = j.as(FlatString)
tmp._items.copy_to(ns, tpl, tmp._first_byte, off)
off += tpl
else
for j in tmp.substrings do
var s = j.as(FlatString)
+ var slen = s._byte_length
s._items.copy_to(ns, slen, s._first_byte, off)
off += slen
end
s._items.copy_to(ns, slen, s._first_byte, off)
off += slen
end
- # Number of UTF-8 characters in `self` starting at `from`, for a length of `bytelen`
- fun utf8_length(from, bytelen: Int): Int is intern do
+ # Number of UTF-8 characters in `self` starting at `from`, for a length of `byte_length`
+ fun utf8_length(from, byte_length: Int): Int is intern do
- while bytelen > 0 do
- while bytelen >= 4 do
+ while byte_length > 0 do
+ while byte_length >= 4 do
var i = fetch_4_chars(st)
if i & 0x80808080 != 0 then break
var i = fetch_4_chars(st)
if i & 0x80808080 != 0 then break
- if bytelen == 0 then break
+ if byte_length == 0 then break
var cln = length_of_char_at(st)
st += cln
ln += 1
var cln = length_of_char_at(st)
st += cln
ln += 1
redef var length is noinit
redef var length is noinit
- redef var bytelen is noinit
+ redef var byte_length is noinit
redef fun substrings do return new RopeSubstrings.from(self, 0)
redef fun substrings do return new RopeSubstrings.from(self, 0)
var flat_last_pos_end: Int = -1
redef var to_cstring is lazy do
var flat_last_pos_end: Int = -1
redef var to_cstring is lazy do
var ns = new NativeString(len + 1)
ns[len] = 0u8
var off = 0
for i in substrings do
var ns = new NativeString(len + 1)
ns[len] = 0u8
var off = 0
for i in substrings do
+ var ilen = i._byte_length
i.as(FlatString)._items.copy_to(ns, ilen, i.as(FlatString)._first_byte, off)
off += ilen
end
i.as(FlatString)._items.copy_to(ns, ilen, i.as(FlatString)._first_byte, off)
off += ilen
end
var l = _left
var r = _right
length = l.length + r.length
var l = _left
var r = _right
length = l.length + r.length
- _bytelen = l.bytelen + r.bytelen
+ _byte_length = l.byte_length + r.byte_length
- redef fun is_empty do return _bytelen == 0
+ redef fun is_empty do return _byte_length == 0
redef fun output do
_left.output
redef fun output do
_left.output
redef fun +(o) do
var s = o.to_s
redef fun +(o) do
var s = o.to_s
+ var slen = s.byte_length
if s isa Concat then
return new Concat(self, s)
else
var r = _right
if s isa Concat then
return new Concat(self, s)
else
var r = _right
+ var rlen = r.byte_length
if rlen + slen > maxlen then return new Concat(self, s)
return new Concat(_left, r + s)
end
if rlen + slen > maxlen then return new Concat(self, s)
return new Concat(_left, r + s)
end
redef fun copy_to_native(dest, n, src_offset, dest_offset) do
var l = _left
redef fun copy_to_native(dest, n, src_offset, dest_offset) do
var l = _left
- if src_offset < l.bytelen then
- var lcopy = l.bytelen - src_offset
+ if src_offset < l.byte_length then
+ var lcopy = l.byte_length - src_offset
lcopy = if lcopy > n then n else lcopy
l.copy_to_native(dest, lcopy, src_offset, dest_offset)
dest_offset += lcopy
lcopy = if lcopy > n then n else lcopy
l.copy_to_native(dest, lcopy, src_offset, dest_offset)
dest_offset += lcopy
end
# Length of the complete rope in bytes
end
# Length of the complete rope in bytes
+ redef var byte_length = 0
# Length of the mutable part (in bytes)
#
# Length of the mutable part (in bytes)
#
self.str = str
ns = new NativeString(maxlen)
buf_size = maxlen
self.str = str
ns = new NativeString(maxlen)
buf_size = maxlen
+ _byte_length = str.length
assert i >= 0 and i <= length
if i == length then add c
if i < str.length then
assert i >= 0 and i <= length
if i == length then add c
if i < str.length then
- _bytelen += c.u8char_len - str[i].u8char_len
+ _byte_length += c.u8char_len - str[i].u8char_len
var s = str
var l = s.substring(0, i)
var r = s.substring_from(i + 1)
var s = str
var l = s.substring(0, i)
var r = s.substring_from(i + 1)
else
ns.copy_to(ns, rpos - st_nxt, st_nxt, st_nxt + delta)
end
else
ns.copy_to(ns, rpos - st_nxt, st_nxt, st_nxt + delta)
end
rpos += delta
end
ns.set_char_at(index, c)
rpos += delta
end
ns.set_char_at(index, c)
redef fun clear do
str = ""
redef fun clear do
str = ""
rpos = 0
dumped = 0
if written then
rpos = 0
dumped = 0
if written then
end
redef fun append(s) do
end
redef fun append(s) do
+ var slen = s.byte_length
if slen >= maxlen then
persist_buffer
str += s.to_s
if slen >= maxlen then
persist_buffer
str += s.to_s
end
ns.set_char_at(rp, c)
rp += cln
end
ns.set_char_at(rp, c)
rp += cln
redef fun +(o) do
var s = o.to_s
redef fun +(o) do
var s = o.to_s
- var slen = s.bytelen
- var mlen = _bytelen
+ var slen = s.byte_length
+ var mlen = _byte_length
if slen == 0 then return self
if mlen == 0 then return s
var nlen = slen + mlen
if slen == 0 then return self
if mlen == 0 then return s
var nlen = slen + mlen
return new FlatString.full(ns, nlen, 0, length + s.length)
else if s isa Concat then
var sl = s._left
return new FlatString.full(ns, nlen, 0, length + s.length)
else if s isa Concat then
var sl = s._left
+ var sllen = sl.byte_length
if sllen + mlen > maxlen then return new Concat(self, s)
return new Concat(self + sl, s._right)
else
if sllen + mlen > maxlen then return new Concat(self, s)
return new Concat(self + sl, s._right)
else
var ns: NativeString is noautoinit
# Substrings of the Rope
var subs: IndexedIterator[FlatString] is noautoinit
var ns: NativeString is noautoinit
# Substrings of the Rope
var subs: IndexedIterator[FlatString] is noautoinit
- # Maximum position to iterate on (e.g. Rope.bytelen)
+ # Maximum position to iterate on (e.g. Rope.byte_length)
var max: Int is noautoinit
# Position (char) in the Rope (0-indexed)
var pos: Int is noautoinit
var max: Int is noautoinit
# Position (char) in the Rope (0-indexed)
var pos: Int is noautoinit
pns = pos - subs.index
self.pos = pos
ns = subs.item._items
pns = pos - subs.index
self.pos = pos
ns = subs.item._items
+ max = root.byte_length - 1
end
redef fun item do return ns[pns]
end
redef fun item do return ns[pns]
redef fun next do
pns += 1
pos += 1
redef fun next do
pns += 1
pos += 1
- if pns < subs.item._bytelen then return
+ if pns < subs.item._byte_length then return
if not subs.is_ok then return
subs.next
if not subs.is_ok then return
if not subs.is_ok then return
subs.next
if not subs.is_ok then return
var cache_end: Int = -1
redef fun [](i) do
var cache_end: Int = -1
redef fun [](i) do
- assert i >= 0 and i < target._bytelen
+ assert i >= 0 and i < target._byte_length
var flps = _cache_start
if i >= flps and i <= _cache_end then
return _cache.bytes[i - flps]
var flps = _cache_start
if i >= flps and i <= _cache_end then
return _cache.bytes[i - flps]
if s isa FlatString then break
s = s.as(Concat)
var lft = s._left
if s isa FlatString then break
s = s.as(Concat)
var lft = s._left
+ var llen = lft.byte_length
if pos >= llen then
s = s._right
pos -= llen
if pos >= llen then
s = s._right
pos -= llen
end
end
_cache_start = st - pos
end
end
_cache_start = st - pos
- _cache_end = st - pos + s.bytelen - 1
+ _cache_end = st - pos + s.byte_length - 1
# Init the iterator from a RopeBuffer starting from `pos`.
init from(t: RopeBuffer, pos: Int) do
ns = t.ns
# Init the iterator from a RopeBuffer starting from `pos`.
init from(t: RopeBuffer, pos: Int) do
ns = t.ns
+ maxpos = t._byte_length
sit = t.str.bytes.iterator_from(pos)
pns = pos - t.str.length
index = pos
sit = t.str.bytes.iterator_from(pos)
pns = pos - t.str.length
index = pos
# Init the iterator from a RopeBuffer starting from `pos`.
init from(tgt: RopeBuffer, pos: Int) do
sit = tgt.str.bytes.reverse_iterator_from(pos - (tgt.rpos - tgt.dumped))
# Init the iterator from a RopeBuffer starting from `pos`.
init from(tgt: RopeBuffer, pos: Int) do
sit = tgt.str.bytes.reverse_iterator_from(pos - (tgt.rpos - tgt.dumped))
- pns = pos - tgt.str.bytelen + tgt.rpos
+ pns = pos - tgt.str.byte_length + tgt.rpos
index = pos
ns = tgt.ns
end
index = pos
ns = tgt.ns
end
redef type SELFTYPE: RopeBuffer
redef fun [](i) do
redef type SELFTYPE: RopeBuffer
redef fun [](i) do
- if i < target.str.bytelen then
+ if i < target.str.byte_length then
return target.str.bytes[i]
else
return target.str.bytes[i]
else
- return target.ns[i - target.str.bytelen]
+ return target.ns[i - target.str.byte_length]
private fun escape_to_csv(sep_char, delim_char: Char, eol: String): String do
var add_sp = chars_to_escape_csv(sep_char, delim_char, eol)
if add_sp == 0 then return to_s
private fun escape_to_csv(sep_char, delim_char: Char, eol: String): String do
var add_sp = chars_to_escape_csv(sep_char, delim_char, eol)
if add_sp == 0 then return to_s
- var bf = new Buffer.with_cap(add_sp + bytelen)
+ var bf = new Buffer.with_cap(add_sp + byte_length)
bf.add '"'
for i in [0 .. length[ do
var c = self[i]
bf.add '"'
for i in [0 .. length[ do
var c = self[i]
private fun unescape_csv(delim_char: Char): String do
var to_un = chars_to_unescape_csv(delim_char)
if to_un == 0 then return to_s
private fun unescape_csv(delim_char: Char): String do
var to_un = chars_to_unescape_csv(delim_char)
if to_un == 0 then return to_s
- var buf = new Buffer.with_cap(bytelen - to_un)
+ var buf = new Buffer.with_cap(byte_length - to_un)
var pos = 0
var ln = length
while pos < ln do
var pos = 0
var ln = length
while pos < ln do
# assert "\\nEscape\\t\\n".json_to_nit_string == "\nEscape\t\n"
# assert "\\u0041zu\\uD800\\uDFD3".json_to_nit_string == "Azu𐏓"
protected fun json_to_nit_string: String do
# assert "\\nEscape\\t\\n".json_to_nit_string == "\nEscape\t\n"
# assert "\\u0041zu\\uD800\\uDFD3".json_to_nit_string == "Azu𐏓"
protected fun json_to_nit_string: String do
- var res = new FlatBuffer.with_capacity(bytelen)
+ var res = new FlatBuffer.with_capacity(byte_length)
var i = 0
var ln = self.length
while i < ln do
var i = 0
var ln = self.length
while i < ln do
# "\"\\t\\\"http://example.com\\\"\\r\\n\\u0000\\\\\""
# ~~~
redef fun to_json do
# "\"\\t\\\"http://example.com\\\"\\r\\n\\u0000\\\\\""
# ~~~
redef fun to_json do
- var b = new FlatBuffer.with_capacity(bytelen)
+ var b = new FlatBuffer.with_capacity(byte_length)
append_json(b)
return b.to_s
end
append_json(b)
return b.to_s
end
redef fun write(str)
do
if close_requested then return
redef fun write(str)
do
if close_requested then return
- native_buffer_event.write(str.to_cstring, str.bytelen)
+ native_buffer_event.write(str.to_cstring, str.byte_length)
end
redef fun write_byte(byte)
end
redef fun write_byte(byte)
# Set the content length if not already set
if not header.keys.has("Content-Length") then
# Size of the body
# Set the content length if not already set
if not header.keys.has("Content-Length") then
# Size of the body
+ var len = body.byte_length
# Size of included files
for path in files do
# Size of included files
for path in files do
redef class FlatString
redef fun internal_to_dot: String
do
redef class FlatString
redef fun internal_to_dot: String
do
- return "n{object_id} [label=\"FlatString\\nlength = {length}\\nbytelen = {bytelen}\\nfirst_byte = {first_byte}\\nlast_byte = {last_byte}\\nText = {self.escape_to_dot}\"];\n"
+ return "n{object_id} [label=\"FlatString\\nlength = {length}\\nbyte_length = {byte_length}\\nfirst_byte = {first_byte}\\nlast_byte = {last_byte}\\nText = {self.escape_to_dot}\"];\n"
end
end
redef class FlatBuffer
redef fun internal_to_dot: String
do
end
end
redef class FlatBuffer
redef fun internal_to_dot: String
do
- return "n{object_id} [label=\"FlatBuffer\\nbytelen = {bytelen}\\nlength = {length}\\ncapacity = {capacity}\\nText = {escape_to_dot}\"];\n"
+ return "n{object_id} [label=\"FlatBuffer\\nbyte_length = {byte_length}\\nlength = {length}\\ncapacity = {capacity}\\nText = {escape_to_dot}\"];\n"
# import base64
# assert "The quick brown fox jumps over the lazy dog".sha1 == [0x2Fu8, 0xD4u8, 0xE1u8, 0xC6u8, 0x7Au8, 0x2Du8, 0x28u8, 0xFCu8, 0xEDu8, 0x84u8, 0x9Eu8, 0xE1u8, 0xBBu8, 0x76u8, 0xE7u8, 0x39u8, 0x1Bu8, 0x93u8, 0xEBu8, 0x12u8]
fun sha1: Bytes do
# import base64
# assert "The quick brown fox jumps over the lazy dog".sha1 == [0x2Fu8, 0xD4u8, 0xE1u8, 0xC6u8, 0x7Au8, 0x2Du8, 0x28u8, 0xFCu8, 0xEDu8, 0x84u8, 0x9Eu8, 0xE1u8, 0xBBu8, 0x76u8, 0xE7u8, 0x39u8, 0x1Bu8, 0x93u8, 0xEBu8, 0x12u8]
fun sha1: Bytes do
- return new Bytes(to_cstring.sha1_intern(bytelen), 20, 20)
+ return new Bytes(to_cstring.sha1_intern(byte_length), 20, 20)
end
# Computes the SHA1 of the receiver.
end
# Computes the SHA1 of the receiver.
var index_len = new Counter[Int]
# Length (bytes) of the FlatString created by lib
var index_len = new Counter[Int]
# Length (bytes) of the FlatString created by lib
- var str_bytelen = new Counter[Int]
+ var str_byte_length = new Counter[Int]
- # Counter of the times `bytelen` is called on FlatString
- var bytelen_call = new Counter[String]
+ # Counter of the times `byte_length` is called on FlatString
+ var byte_length_call = new Counter[String]
# Counter of the times `bytepos` is called on each type of receiver
var position_call = new Counter[String]
# Counter of the times `bytepos` is called on each type of receiver
var position_call = new Counter[String]
- print "Calls to bytelen for each type:"
- for k, v in bytelen_call do
+ print "Calls to byte_length for each type:"
+ for k, v in byte_length_call do
index_len.print_content
print "Byte length of the FlatStrings created:"
index_len.print_content
print "Byte length of the FlatStrings created:"
- str_bytelen.print_content
+ str_byte_length.print_content
sys.concat_allocations += 1
end
sys.concat_allocations += 1
end
- redef fun bytelen do
- sys.bytelen_call.inc "Concat"
+ redef fun byte_length do
+ sys.byte_length_call.inc "Concat"
sys.ropebuf_allocations += 1
end
sys.ropebuf_allocations += 1
end
- redef fun bytelen do
- sys.bytelen_call.inc "RopeBuffer"
+ redef fun byte_length do
+ sys.byte_length_call.inc "RopeBuffer"
- redef fun bytelen do
- sys.bytelen_call.inc "FlatBuffer"
+ redef fun byte_length do
+ sys.byte_length_call.inc "FlatBuffer"
- redef fun bytelen do
- sys.bytelen_call.inc "FlatString"
+ redef fun byte_length do
+ sys.byte_length_call.inc "FlatString"
var l = length_cache
if l != null then return l
sys.length_cache_miss.inc "FlatString"
var l = length_cache
if l != null then return l
sys.length_cache_miss.inc "FlatString"
- if bytelen == 0 then return 0
+ if byte_length == 0 then return 0
var st = first_byte
var its = items
var ln = 0
var st = first_byte
var its = items
var ln = 0
end
redef class ASCIIFlatString
end
redef class ASCIIFlatString
- redef init full_data(items, bytelen, from, length)
+ redef init full_data(items, byte_length, from, length)
do
super
sys.asciiflatstr_allocations += 1
do
super
sys.asciiflatstr_allocations += 1
end
redef class UnicodeFlatString
end
redef class UnicodeFlatString
- redef init full_data(items, bytelen, from, length)
+ redef init full_data(items, byte_length, from, length)
do
super
sys.uniflatstr_allocations += 1
do
super
sys.uniflatstr_allocations += 1
var native_mtype = mmodule.native_string_type
var nat = self.new_var(native_mtype)
self.add("{nat} = \"{string.escape_to_c}\";")
var native_mtype = mmodule.native_string_type
var nat = self.new_var(native_mtype)
self.add("{nat} = \"{string.escape_to_c}\";")
- var bytelen = self.int_instance(string.bytelen)
+ var byte_length = self.int_instance(string.byte_length)
var unilen = self.int_instance(string.length)
var unilen = self.int_instance(string.length)
- self.add("{res} = {self.send(self.get_property("to_s_full", native_mtype), [nat, bytelen, unilen]).as(not null)};")
+ self.add("{res} = {self.send(self.get_property("to_s_full", native_mtype), [nat, byte_length, unilen]).as(not null)};")
self.add("{name} = {res};")
self.add("\}")
return res
self.add("{name} = {res};")
self.add("\}")
return res
# Return a new native string initialized with `txt`
fun native_string_instance(txt: String): Instance
do
# Return a new native string initialized with `txt`
fun native_string_instance(txt: String): Instance
do
- var instance = native_string_instance_len(txt.bytelen+1)
+ var instance = native_string_instance_len(txt.byte_length+1)
- val[txt.bytelen] = 0u8
- txt.to_cstring.copy_to(val, txt.bytelen, 0, 0)
+ val[txt.byte_length] = 0u8
+ txt.to_cstring.copy_to(val, txt.byte_length, 0, 0)
fun string_instance(txt: String): Instance
do
var nat = native_string_instance(txt)
fun string_instance(txt: String): Instance
do
var nat = native_string_instance(txt)
- var res = self.send(self.force_get_primitive_method("to_s_full", nat.mtype), [nat, self.int_instance(txt.bytelen), self.int_instance(txt.length)])
+ var res = self.send(self.force_get_primitive_method("to_s_full", nat.mtype), [nat, self.int_instance(txt.byte_length), self.int_instance(txt.length)])
assert res != null
return res
end
assert res != null
return res
end
s = "Je dis «{s}» et redis «{s}» et trois fois de plus : «{s}{s}{s}».\n"
i = i + 1
end
s = "Je dis «{s}» et redis «{s}» et trois fois de plus : «{s}{s}{s}».\n"
i = i + 1
end
s = ["Je dis «", s, "» et redis «", s, "» et trois fois de plus : «", s, s, s, "».\n"].plain_to_s
i = i + 1
end
s = ["Je dis «", s, "» et redis «", s, "» et trois fois de plus : «", s, s, s, "».\n"].plain_to_s
i = i + 1
end
Calls to length, by type:
FlatString = 19
Indexed accesses, by type:
Calls to length, by type:
FlatString = 19
Indexed accesses, by type:
-Calls to bytelen for each type:
+Calls to byte_length for each type:
FlatString = 48
Calls to position for each type:
Calls to bytepos for each type:
FlatString = 48
Calls to position for each type:
Calls to bytepos for each type:
for i in fb.bytes.reverse_iterator do
print "Byte {l} = {i}"
for i in fb.bytes.reverse_iterator do
print "Byte {l} = {i}"
#alt1 str = new Concat(base_str, base_str)
#alt2 str = new Concat(base_str, base_str.substring_from(2))
#alt1 str = new Concat(base_str, base_str)
#alt2 str = new Concat(base_str, base_str.substring_from(2))
-var copy_len = (str.bytelen - 4).min(9)
+var copy_len = (str.byte_length - 4).min(9)
str.copy_to_native(ons, copy_len, 4, 0)
print ons.to_s_with_length(copy_len)
str.copy_to_native(ons, copy_len, 4, 0)
print ons.to_s_with_length(copy_len)
#alt2 cpstr = new FlatBuffer.from(src_s)
#alt3 cpstr = cpstr.substring(1, 5)
#alt2 cpstr = new FlatBuffer.from(src_s)
#alt3 cpstr = cpstr.substring(1, 5)
-var ns = new NativeString(cpstr.bytelen)
+var ns = new NativeString(cpstr.byte_length)
-print ns.to_s_with_length(cpstr.bytelen)
+print ns.to_s_with_length(cpstr.byte_length)