lib/core: Renamed `Text::bytelen` to `Text::byte_length`
[nit.git] / lib / core / text / flat.nit
index 6273609..1c7ab16 100644 (file)
@@ -40,7 +40,7 @@ redef class FlatText
        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
@@ -138,7 +138,7 @@ redef class FlatText
                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
@@ -254,7 +254,7 @@ redef class FlatText
                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
@@ -425,7 +425,7 @@ abstract class FlatString
        redef var bytes = new FlatStringByteView(self) is lazy
 
        redef var to_cstring is lazy do
-               var blen = _bytelen
+               var blen = _byte_length
                var new_items = new NativeString(blen + 1)
                _items.copy_to(new_items, blen, _first_byte, 0)
                new_items[blen] = 0u8
@@ -433,7 +433,7 @@ abstract class FlatString
        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)
@@ -489,7 +489,7 @@ abstract class FlatString
 
        redef fun to_upper
        do
-               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
@@ -504,7 +504,7 @@ abstract class FlatString
 
        redef fun to_lower
        do
-               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
@@ -530,21 +530,21 @@ abstract class FlatString
        #
        # `_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)
        do
-               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.
-       private new full(items: NativeString, bytelen, from, length: Int)
+       private new full(items: NativeString, byte_length, from, length: Int)
        do
-               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)
        end
 
        redef fun ==(other)
@@ -553,9 +553,9 @@ abstract class FlatString
 
                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
@@ -583,8 +583,8 @@ abstract class FlatString
                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
@@ -606,8 +606,8 @@ abstract class FlatString
 
        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
@@ -624,21 +624,21 @@ abstract class FlatString
        end
 
        redef fun *(i) do
-               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 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
-               return new FlatString.full(ns, new_bytelen, 0, newlen)
+               return new FlatString.full(ns, new_byte_length, 0, newlen)
        end
 
        redef fun hash
@@ -669,10 +669,10 @@ end
 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._bytelen = bytelen
+               self._byte_length = byte_length
                _first_byte = from
                _bytepos = from
        end
@@ -682,7 +682,7 @@ private class UnicodeFlatString
                if from <= 0 then return self
                var c = char_to_byte_index(from)
                var st = c - _first_byte
-               var fln = bytelen - st
+               var fln = byte_length - st
                return new FlatString.full(items, fln, c, _length - from)
        end
 end
@@ -693,16 +693,16 @@ end
 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._bytelen = bytelen
+               self._byte_length = byte_length
                _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
 
@@ -720,7 +720,7 @@ private class ASCIIFlatString
        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]
@@ -852,7 +852,7 @@ private class FlatStringByteView
                # 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
@@ -897,18 +897,18 @@ class FlatBuffer
        # 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`
        #
-       # 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
-               var bt = _bytelen
+               var bt = _byte_length
                if bt + len > capacity then
                        capacity = capacity * 2 + 2
                        nit = new NativeString(capacity)
@@ -919,10 +919,10 @@ class FlatBuffer
 
        # 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
-               it.copy_to(it, _bytelen - from, from, from - len)
+               it.copy_to(it, _byte_length - from, from, from - len)
        end
 
        redef fun []=(index, item)
@@ -945,7 +945,7 @@ class FlatBuffer
                else if size_diff < 0 then
                        lshift_bytes(ip + clen, -size_diff)
                end
-               _bytelen += size_diff
+               _byte_length += size_diff
                it.set_char_at(ip, item)
        end
 
@@ -954,16 +954,16 @@ class FlatBuffer
                if written then reset
                is_dirty = true
                var clen = c.u8char_len
-               var bt = _bytelen
+               var bt = _byte_length
                enlarge(bt + clen)
                _items.set_char_at(bt, c)
-               _bytelen += clen
+               _byte_length += clen
                _length += 1
        end
 
        redef fun clear do
                is_dirty = true
-               _bytelen = 0
+               _byte_length = 0
                _length = 0
                if written then
                        _capacity = 16
@@ -982,7 +982,7 @@ class FlatBuffer
                # The COW flag can be set at false here, since
                # it does a copy of the current `Buffer`
                written = false
-               var bln = _bytelen
+               var bln = _byte_length
                var a = new NativeString(c)
                if bln > 0 then
                        var it = _items
@@ -995,7 +995,7 @@ class FlatBuffer
        redef fun to_s
        do
                written = true
-               var bln = _bytelen
+               var bln = _byte_length
                if bln == 0 then _items = new NativeString(1)
                return new FlatString.full(_items, bln, 0, _length)
        end
@@ -1003,7 +1003,7 @@ class FlatBuffer
        redef fun to_cstring
        do
                if is_dirty then
-                       var bln = _bytelen
+                       var bln = _byte_length
                        var new_native = new NativeString(bln + 1)
                        new_native[bln] = 0u8
                        if _length > 0 then _items.copy_to(new_native, bln, 0, 0)
@@ -1023,22 +1023,22 @@ class FlatBuffer
        #
        # 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
-               self._bytelen = bytelen
+               self._byte_length = byte_length
                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
                _length = s.length
-               _capacity = _bytelen
+               _capacity = _byte_length
        end
 
        # Create a new empty string with a given capacity.
@@ -1047,23 +1047,23 @@ class FlatBuffer
                assert cap >= 0
                _items = new NativeString(cap)
                capacity = cap
-               _bytelen = 0
+               _byte_length = 0
        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
-                       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
-               _bytelen = nln
+               _byte_length = nln
                _length += s.length
        end
 
@@ -1102,9 +1102,9 @@ class FlatBuffer
                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
                _length += length
        end
 
@@ -1118,7 +1118,7 @@ class FlatBuffer
 
        redef fun times(repeats)
        do
-               var bln = _bytelen
+               var bln = _byte_length
                var x = new FlatString.full(_items, bln, 0, _length)
                for i in [1 .. repeats[ do
                        append(x)
@@ -1185,7 +1185,7 @@ private class FlatBufferByteIterator
 
        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]
 
@@ -1288,8 +1288,8 @@ redef class NativeString
                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
@@ -1471,7 +1471,7 @@ redef class Array[E]
                                continue
                        end
                        var tmp = itsi.to_s
-                       sl += tmp.bytelen
+                       sl += tmp.byte_length
                        na[mypos] = tmp
                        i += 1
                        mypos += 1
@@ -1483,13 +1483,13 @@ redef class Array[E]
                while i < mypos do
                        var tmp = na[i]
                        if tmp isa FlatString then
-                               var tpl = tmp._bytelen
+                               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)
-                                       var slen = s._bytelen
+                                       var slen = s._byte_length
                                        s._items.copy_to(ns, slen, s._first_byte, off)
                                        off += slen
                                end
@@ -1509,7 +1509,7 @@ redef class NativeArray[E]
                var sl = 0
                var mypos = 0
                while i < l do
-                       sl += na[i].bytelen
+                       sl += na[i].byte_length
                        i += 1
                        mypos += 1
                end
@@ -1520,13 +1520,13 @@ redef class NativeArray[E]
                while i < mypos do
                        var tmp = na[i]
                        if tmp isa FlatString then
-                               var tpl = tmp._bytelen
+                               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)
-                                       var slen = s._bytelen
+                                       var slen = s._byte_length
                                        s._items.copy_to(ns, slen, s._first_byte, off)
                                        off += slen
                                end