From: Lucas Bajolet Date: Wed, 8 Jun 2016 18:48:42 +0000 (-0400) Subject: lib/core: Renamed `Text::bytelen` to `Text::byte_length` X-Git-Url: http://nitlanguage.org lib/core: Renamed `Text::bytelen` to `Text::byte_length` Signed-off-by: Lucas Bajolet --- diff --git a/lib/base64.nit b/lib/base64.nit index 8f6565b..0ba5c30 100644 --- a/lib/base64.nit +++ b/lib/base64.nit @@ -163,7 +163,7 @@ redef class String # 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. @@ -171,6 +171,6 @@ redef class String # 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 end end diff --git a/lib/binary/binary.nit b/lib/binary/binary.nit index c15cb52..dbe07be 100644 --- a/lib/binary/binary.nit +++ b/lib/binary/binary.nit @@ -107,7 +107,7 @@ redef abstract class Writer # 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 write text end diff --git a/lib/cocoa/foundation.nit b/lib/cocoa/foundation.nit index 3a6fa98..e7c3b17 100644 --- a/lib/cocoa/foundation.nit +++ b/lib/cocoa/foundation.nit @@ -51,7 +51,7 @@ end 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 diff --git a/lib/core/bytes.nit b/lib/core/bytes.nit index 7b25d61..1b726a0 100644 --- a/lib/core/bytes.nit +++ b/lib/core/bytes.nit @@ -456,7 +456,7 @@ class Bytes # 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) end end @@ -712,7 +712,7 @@ redef class Text # 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 @@ -730,7 +730,7 @@ redef class Text 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) end end @@ -757,7 +757,7 @@ redef class Text # assert "a b c".hexdigest_to_bytes.hexdigest == "0ABC" fun hexdigest_to_bytes: Bytes do var b = bytes - var max = bytelen + var max = byte_length var dlength = 0 # Number of hex digits var pos = 0 @@ -795,7 +795,7 @@ redef class Text # # assert "<STRING/&rt;".hexdigest == "266C743B535452494E47262334373B2672743B" fun hexdigest: String do - var ln = bytelen + var ln = byte_length var outns = new NativeString(ln * 2) var oi = 0 for i in [0 .. ln[ do @@ -815,7 +815,7 @@ redef class Text # 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 @@ -886,7 +886,7 @@ redef class Text fun binarydigest_to_bytes: Bytes do var b = bytes - var max = bytelen + var max = byte_length # Count bits var bitlen = 0 @@ -930,7 +930,7 @@ end 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 end diff --git a/lib/core/codecs/iso8859_1.nit b/lib/core/codecs/iso8859_1.nit index 02c39ef..21ea8a8 100644 --- a/lib/core/codecs/iso8859_1.nit +++ b/lib/core/codecs/iso8859_1.nit @@ -40,7 +40,7 @@ private class ISO88591Codec 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 diff --git a/lib/core/codecs/utf8.nit b/lib/core/codecs/utf8.nit index bb257dd..c6fc71c 100644 --- a/lib/core/codecs/utf8.nit +++ b/lib/core/codecs/utf8.nit @@ -41,14 +41,14 @@ private class UTF8Codec 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) - return s.bytelen + return s.byte_length end redef fun is_valid_char(ns, len) do @@ -73,7 +73,7 @@ private class UTF8Codec 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) end return ret end diff --git a/lib/core/file.nit b/lib/core/file.nit index 8bf8078..bea9672 100644 --- a/lib/core/file.nit +++ b/lib/core/file.nit @@ -858,7 +858,7 @@ redef class Text 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) end end @@ -1285,7 +1285,7 @@ end 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 diff --git a/lib/core/fixed_ints.nit b/lib/core/fixed_ints.nit index f2f3890..5e7c774 100644 --- a/lib/core/fixed_ints.nit +++ b/lib/core/fixed_ints.nit @@ -902,7 +902,7 @@ redef class Text # 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 diff --git a/lib/core/re.nit b/lib/core/re.nit index 0ac109c..94672b4 100644 --- a/lib/core/re.nit +++ b/lib/core/re.nit @@ -368,7 +368,7 @@ class Regex # 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 @@ -428,7 +428,7 @@ class Regex # 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 diff --git a/lib/core/stream.nit b/lib/core/stream.nit index 5ad8d75..a54c7e8 100644 --- a/lib/core/stream.nit +++ b/lib/core/stream.nit @@ -198,7 +198,7 @@ abstract class Reader var rets = "" var pos = 0 var str = s.items.clean_utf8(slen) - slen = str.bytelen + slen = str.byte_length var sits = str.items var remsp = slen while pos < slen do @@ -211,10 +211,10 @@ abstract class Reader 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) pos = st - remsp -= bytelen + remsp -= byte_length end if rets isa Concat then return rets.balance return rets @@ -732,5 +732,5 @@ class StringReader return new Bytes(nns, nslen, nslen) end - redef fun eof do return cursor >= source.bytelen + redef fun eof do return cursor >= source.byte_length end diff --git a/lib/core/text/abstract_text.nit b/lib/core/text/abstract_text.nit index e07e0d4..b3852c0 100644 --- a/lib/core/text/abstract_text.nit +++ b/lib/core/text/abstract_text.nit @@ -50,9 +50,9 @@ abstract class Text # 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 # Create a substring. # @@ -844,7 +844,7 @@ abstract class Text # assert "%c3%a9%e3%81%82%e3%81%84%e3%81%86".from_percent_encoding == "éあいう" fun from_percent_encoding: String do - var len = bytelen + var len = byte_length var has_percent = false for c in chars do if c == '%' then @@ -1181,7 +1181,7 @@ abstract class FlatText redef var length = 0 - redef var bytelen = 0 + redef var byte_length = 0 redef fun output do @@ -1226,11 +1226,11 @@ private abstract class StringByteView 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 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. @@ -2187,7 +2187,7 @@ redef class NativeString # 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, @@ -2197,13 +2197,13 @@ redef class NativeString # 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` # - # 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] diff --git a/lib/core/text/flat.nit b/lib/core/text/flat.nit index 6273609..1c7ab16 100644 --- a/lib/core/text/flat.nit +++ b/lib/core/text/flat.nit @@ -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 diff --git a/lib/core/text/native.nit b/lib/core/text/native.nit index 7902d11..ebb5661 100644 --- a/lib/core/text/native.nit +++ b/lib/core/text/native.nit @@ -268,23 +268,23 @@ extern class NativeString `{ char* `} return endpos 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 var st = from var ln = 0 - 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 - bytelen -= 4 + byte_length -= 4 st += 4 ln += 4 end - if bytelen == 0 then break + if byte_length == 0 then break var cln = length_of_char_at(st) st += cln ln += 1 - bytelen -= cln + byte_length -= cln end return ln end diff --git a/lib/core/text/ropes.nit b/lib/core/text/ropes.nit index f57b33d..f472d96 100644 --- a/lib/core/text/ropes.nit +++ b/lib/core/text/ropes.nit @@ -76,7 +76,7 @@ private class Concat 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) @@ -91,12 +91,12 @@ private class Concat var flat_last_pos_end: Int = -1 redef var to_cstring is lazy do - var len = _bytelen + var len = _byte_length var ns = new NativeString(len + 1) ns[len] = 0u8 var off = 0 for i in substrings do - var ilen = i._bytelen + var ilen = i._byte_length i.as(FlatString)._items.copy_to(ns, ilen, i.as(FlatString)._first_byte, off) off += ilen end @@ -112,10 +112,10 @@ private class Concat var l = _left var r = _right length = l.length + r.length - _bytelen = l.bytelen + r.bytelen + _byte_length = l.byte_length + r.byte_length end - redef fun is_empty do return _bytelen == 0 + redef fun is_empty do return _byte_length == 0 redef fun output do _left.output @@ -209,12 +209,12 @@ private class Concat redef fun +(o) do var s = o.to_s - var slen = s.bytelen + var slen = s.byte_length if s isa Concat then return new Concat(self, s) else var r = _right - var rlen = r.bytelen + var rlen = r.byte_length if rlen + slen > maxlen then return new Concat(self, s) return new Concat(_left, r + s) end @@ -222,8 +222,8 @@ private class Concat 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 @@ -331,7 +331,7 @@ class RopeBuffer end # Length of the complete rope in bytes - redef var bytelen = 0 + redef var byte_length = 0 # Length of the mutable part (in bytes) # @@ -353,7 +353,7 @@ class RopeBuffer self.str = str ns = new NativeString(maxlen) buf_size = maxlen - _bytelen = str.length + _byte_length = str.length dumped = 0 end @@ -384,7 +384,7 @@ class RopeBuffer 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) @@ -407,7 +407,7 @@ class RopeBuffer else ns.copy_to(ns, rpos - st_nxt, st_nxt, st_nxt + delta) end - _bytelen += delta + _byte_length += delta rpos += delta end ns.set_char_at(index, c) @@ -418,7 +418,7 @@ class RopeBuffer redef fun clear do str = "" - _bytelen = 0 + _byte_length = 0 rpos = 0 dumped = 0 if written then @@ -459,7 +459,7 @@ class RopeBuffer end redef fun append(s) do - var slen = s.bytelen + var slen = s.byte_length if slen >= maxlen then persist_buffer str += s.to_s @@ -495,7 +495,7 @@ class RopeBuffer end ns.set_char_at(rp, c) rp += cln - _bytelen += cln + _byte_length += cln rpos = rp end @@ -574,8 +574,8 @@ redef 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 if slen == 0 then return self if mlen == 0 then return s var nlen = slen + mlen @@ -591,7 +591,7 @@ redef class FlatString return new FlatString.full(ns, nlen, 0, length + s.length) else if s isa Concat then var sl = s._left - var sllen = sl.bytelen + var sllen = sl.byte_length if sllen + mlen > maxlen then return new Concat(self, s) return new Concat(self + sl, s._right) else @@ -663,7 +663,7 @@ private class RopeByteIterator 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 @@ -673,7 +673,7 @@ private class RopeByteIterator pns = pos - subs.index self.pos = pos ns = subs.item._items - max = root.bytelen - 1 + max = root.byte_length - 1 end redef fun item do return ns[pns] @@ -685,7 +685,7 @@ private class RopeByteIterator 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 @@ -984,7 +984,7 @@ private class RopeBytes 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] @@ -1004,7 +1004,7 @@ private class RopeBytes if s isa FlatString then break s = s.as(Concat) var lft = s._left - var llen = lft.bytelen + var llen = lft.byte_length if pos >= llen then s = s._right pos -= llen @@ -1013,7 +1013,7 @@ private class RopeBytes end end _cache_start = st - pos - _cache_end = st - pos + s.bytelen - 1 + _cache_end = st - pos + s.byte_length - 1 _cache = s return s end @@ -1114,7 +1114,7 @@ class RopeBufferByteIterator # Init the iterator from a RopeBuffer starting from `pos`. init from(t: RopeBuffer, pos: Int) do ns = t.ns - maxpos = t._bytelen + maxpos = t._byte_length sit = t.str.bytes.iterator_from(pos) pns = pos - t.str.length index = pos @@ -1155,7 +1155,7 @@ class RopeBufferByteReverseIterator # 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 @@ -1184,10 +1184,10 @@ class RopeBufferBytes 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.ns[i - target.str.bytelen] + return target.ns[i - target.str.byte_length] end end diff --git a/lib/csv/csv.nit b/lib/csv/csv.nit index 4542553..abc4437 100644 --- a/lib/csv/csv.nit +++ b/lib/csv/csv.nit @@ -20,7 +20,7 @@ redef class Text 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] @@ -67,7 +67,7 @@ redef class Text 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 diff --git a/lib/json/static.nit b/lib/json/static.nit index e333b85..dd1cc85 100644 --- a/lib/json/static.nit +++ b/lib/json/static.nit @@ -139,7 +139,7 @@ redef class Text # 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 @@ -188,7 +188,7 @@ redef class Text # "\"\\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 diff --git a/lib/libevent.nit b/lib/libevent.nit index 36de40f..614f3d9 100644 --- a/lib/libevent.nit +++ b/lib/libevent.nit @@ -161,7 +161,7 @@ class Connection 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) diff --git a/lib/nitcorn/http_response.nit b/lib/nitcorn/http_response.nit index 08d2968..dd3e03b 100644 --- a/lib/nitcorn/http_response.nit +++ b/lib/nitcorn/http_response.nit @@ -46,7 +46,7 @@ class HttpResponse # Set the content length if not already set if not header.keys.has("Content-Length") then # Size of the body - var len = body.bytelen + var len = body.byte_length # Size of included files for path in files do diff --git a/lib/ropes_debug.nit b/lib/ropes_debug.nit index 874961f..1fa3638 100644 --- a/lib/ropes_debug.nit +++ b/lib/ropes_debug.nit @@ -53,14 +53,14 @@ end 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 - 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" end end diff --git a/lib/sha1.nit b/lib/sha1.nit index 2bd8fbe..e00745c 100644 --- a/lib/sha1.nit +++ b/lib/sha1.nit @@ -247,7 +247,7 @@ redef class String # 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. diff --git a/lib/text_stat.nit b/lib/text_stat.nit index ad6d21e..e4dab5f 100644 --- a/lib/text_stat.nit +++ b/lib/text_stat.nit @@ -53,10 +53,10 @@ redef class Sys 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] @@ -98,8 +98,8 @@ Allocations, by type: printn "\n" end - 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 print "\t{k} = {v}" end @@ -120,7 +120,7 @@ Allocations, by type: index_len.print_content print "Byte length of the FlatStrings created:" - str_bytelen.print_content + str_byte_length.print_content end redef fun run do @@ -139,8 +139,8 @@ redef class Concat 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" return super end @@ -221,8 +221,8 @@ redef class RopeBuffer 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" return super end @@ -258,8 +258,8 @@ redef class FlatBuffer super end - redef fun bytelen do - sys.bytelen_call.inc "FlatBuffer" + redef fun byte_length do + sys.byte_length_call.inc "FlatBuffer" return super end @@ -301,8 +301,8 @@ redef class FlatString super end - redef fun bytelen do - sys.bytelen_call.inc "FlatString" + redef fun byte_length do + sys.byte_length_call.inc "FlatString" return super end @@ -328,7 +328,7 @@ redef class 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 @@ -348,7 +348,7 @@ redef class FlatString 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 @@ -357,7 +357,7 @@ redef class ASCIIFlatString 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 diff --git a/src/compiler/abstract_compiler.nit b/src/compiler/abstract_compiler.nit index 9811228..0fa3d4b 100644 --- a/src/compiler/abstract_compiler.nit +++ b/src/compiler/abstract_compiler.nit @@ -1652,9 +1652,9 @@ abstract class AbstractCompilerVisitor 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) - 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 diff --git a/src/interpreter/naive_interpreter.nit b/src/interpreter/naive_interpreter.nit index 539fb89..a9426c4 100644 --- a/src/interpreter/naive_interpreter.nit +++ b/src/interpreter/naive_interpreter.nit @@ -319,10 +319,10 @@ class NaiveInterpreter # 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) var val = instance.val - 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) return instance end @@ -352,7 +352,7 @@ class NaiveInterpreter 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 diff --git a/tests/bench_string_super.nit b/tests/bench_string_super.nit index 88b001a..be157b3 100644 --- a/tests/bench_string_super.nit +++ b/tests/bench_string_super.nit @@ -23,4 +23,4 @@ while i < n do s = "Je dis «{s}» et redis «{s}» et trois fois de plus : «{s}{s}{s}».\n" i = i + 1 end -print s.bytelen +print s.byte_length diff --git a/tests/bench_string_tos.nit b/tests/bench_string_tos.nit index f76b13a..0f34f86 100644 --- a/tests/bench_string_tos.nit +++ b/tests/bench_string_tos.nit @@ -23,4 +23,4 @@ while i < n do s = ["Je dis «", s, "» et redis «", s, "» et trois fois de plus : «", s, s, s, "».\n"].plain_to_s i = i + 1 end -print(s.bytelen) +print(s.byte_length) diff --git a/tests/sav/test_text_stat.res b/tests/sav/test_text_stat.res index 781b094..4a8c500 100644 --- a/tests/sav/test_text_stat.res +++ b/tests/sav/test_text_stat.res @@ -12,7 +12,7 @@ Allocations, 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: diff --git a/tests/test_buffer_unicode.nit b/tests/test_buffer_unicode.nit index f76ac5f..902993a 100644 --- a/tests/test_buffer_unicode.nit +++ b/tests/test_buffer_unicode.nit @@ -46,7 +46,7 @@ for i in fb.chars.reverse_iterator do l -= 1 end -l = fb.bytelen - 1 +l = fb.byte_length - 1 for i in fb.bytes.reverse_iterator do print "Byte {l} = {i}" diff --git a/tests/test_copy_to_native.nit b/tests/test_copy_to_native.nit index 380c02a..0018f1d 100644 --- a/tests/test_copy_to_native.nit +++ b/tests/test_copy_to_native.nit @@ -23,6 +23,6 @@ var str: String = base_str #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) diff --git a/tests/test_nativestring_fill_from.nit b/tests/test_nativestring_fill_from.nit index 1b9e491..4a88e23 100644 --- a/tests/test_nativestring_fill_from.nit +++ b/tests/test_nativestring_fill_from.nit @@ -21,7 +21,7 @@ var cpstr: Text = src_s #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) ns.fill_from(cpstr) -print ns.to_s_with_length(cpstr.bytelen) +print ns.to_s_with_length(cpstr.byte_length)