core :: FlatBuffer
core :: FlatBuffer :: defaultinit
core :: FlatBuffer :: with_capacity
Create a new empty string with a given capacity.core $ FlatBuffer :: SELF
Type of this instance, automatically specialized in every classcore $ FlatBuffer :: append_substring_impl
Unsafe version ofappend_substring
for performance
text_stat :: text_stat $ FlatBuffer :: byte_length
Number of bytes inself
core $ FlatBuffer :: bytes
Gets a view on the bytes of the Text objecttext_stat :: text_stat $ FlatBuffer :: char_to_byte_index
Index of the characterindex
in _items
core $ FlatBuffer :: chars
Gets a view on the chars of the Text objectcore $ FlatBuffer :: enlarge
Enlarges the subsequent array containing the chars of selfcore $ FlatBuffer :: fast_cstring
Returns a char* starting at positionfirst_byte
text_stat :: text_stat $ FlatBuffer :: init
core $ FlatBuffer :: lower
Changes each upper-case char inself
by its lower-case variant
core $ FlatBuffer :: times
self
is appended in such a way that self
is repeated r
times
core $ FlatBuffer :: upper
Changes each lower-case char inself
by its upper-case variant
serialization :: Serializable :: accept_json_serializer
Refinable service to customize the serialization of this class to JSONserialization :: Serializable :: accept_msgpack_attribute_counter
Hook to customize the behavior of theAttributeCounter
serialization :: Serializable :: accept_msgpack_serializer
Hook to customize the serialization of this class to MessagePackserialization :: Serializable :: add_to_bundle
Called by[]=
to dynamically choose the appropriate method according
core :: Buffer :: append_substring
Appendslength
chars from s
starting at index from
core :: Buffer :: append_substring_impl
Unsafe version ofappend_substring
for performance
core :: Text :: binarydigest_to_bytes
Return aBytes
by reading 0 and 1.
core :: FlatText :: byte_length=
core :: Buffer :: capitalize
Capitalizes each word inself
core :: Text :: capitalized
Returns a capitalizedself
core :: FlatText :: char_to_byte_index
Index of the characterindex
in _items
core :: FlatText :: chars_to_escape_to_c
By escapingself
to C, how many more bytes will be needed ?
core :: FlatText :: chars_to_html_escape
By escapingself
to HTML, how many more bytes will be needed ?
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
core :: Text :: copy_to_native
Copiesn
bytes from self
at src_offset
into dest
starting at dest_offset
serialization :: Serializable :: core_serialize_to
Actual serialization ofself
to serializer
core :: Text :: decode_base64
Decodes the receiver string to base64 using a custom padding character.core :: Cloneable :: defaultinit
core :: Object :: defaultinit
core :: Writable :: defaultinit
mpi :: Sendable :: defaultinit
core :: Comparable :: defaultinit
core :: Pattern :: defaultinit
core :: FlatText :: defaultinit
core :: Text :: defaultinit
core :: FlatBuffer :: defaultinit
mpi :: Receptacle :: defaultinit
core :: Buffer :: defaultinit
core :: Text :: deserialize_json
Deserialize anullable Object
from this JSON formatted string
core :: Text :: encode_base64
Encodes the receiver string to base64 using a custom padding character.core :: Text :: english_scoring
Scoreself
according to english's letter frequency.
core :: Text :: escape_more_to_c
Escape additionnal characterscore :: Text :: escape_to_c
Escape"
\
'
, trigraphs and non printable characters using the rules of literal C strings and characters
core :: Text :: escape_to_js
Escape the content ofself
to pass to JavaScript code
core :: Text :: escape_to_utf16
Returnsself
with all characters escaped with their UTF-16 representation
core :: FlatText :: fast_cstring
Returns a char* starting at positionfirst_byte
core :: Text :: file_extension
Return right-most extension (without the dot)core :: Text :: file_lstat
The status of a file or of a symlink. see POSIX lstat(2).serialization :: Serializable :: from_deserializer
Create an instance of this class from thedeserializer
core :: Text :: from_percent_encoding
Decodeself
from percent (or URL) encoding to a clear string
core :: Text :: from_utf16_digit
Returns a UTF-16 escape valuecore :: Text :: from_utf16_escape
Returns the Unicode char escaped byself
core :: Text :: group_exists
Does the operating system know the group namedself
?
core :: Text :: has_substring
Does self have a substringstr
starting from position pos
?
core :: Text :: hexdigest_to_bytes
Returns a newBytes
instance with the digest as content
core :: Text :: html_escape
Escape the characters<
, >
, &
, "
, '
and /
as HTML/XML entity references.
core :: Text :: http_download
Download the file at URLself
to output_path
with a simple HTTP request
core :: Text :: index_of_from
Gets the index of the first occurence of ´c´ starting from ´pos´core :: Text :: is_numeric
Is this string in a valid numeric format compatible withto_f
?
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
core :: Text :: is_whitespace
Is the string non-empty but only made of whitespaces?core :: Text :: last_index_of_from
The index of the last occurrence of an element starting from pos (in reverse order).core :: Text :: levenshtein_distance
Return the Levenshtein distance between two stringscore :: Text :: light_gray
Make the text appear in light gray (or white) in a ANSI/VT100 terminal.serialization :: Serializable :: msgpack_extra_array_items
Hook to request a larger than usual metadata arraycore :: Object :: output_class_name
Display class name on stdout (debug only).core :: Text :: parse_bmfont
Parseself
as an XML BMFont description file
core :: Text :: remove_all
Returns a copy ofself
minus all occurences of pattern
core :: Text :: replace_first
Replace the first occurrence ofpattern
with string
core :: Text :: search_all
Search all occurrences ofpattern
into self.
core :: Pattern :: search_all_in
Search allself
occurrences into s
.
core :: Text :: search_from
Search the first occurence ofpattern
after from
.
core :: Pattern :: search_index_in
Searchself
into s
from a certain position.
core :: Text :: search_last
Search the last occurence of the textt
.
core :: Text :: search_last_up_to
Search the last occurence of the textt
before up_to
.
serialization :: Serializable :: serialize_msgpack
Serializeself
to MessagePack bytes
serialization :: Serializable :: serialize_to
Serializeself
to serializer
serialization :: Serializable :: serialize_to_json
Serializeself
to JSON
core :: Text :: simplify_path
Simplify a file path by remove useless.
, removing //
, and resolving ..
core :: Text :: split_once_on
Splitself
on the first occurence of pattern
core :: Text :: split_with
@deprecated alias forsplit
core :: Text :: strip_extension
Remove the trailingextension
.
core :: Text :: strip_nullable
Strip thenullable
prefix from the type name self
core :: Text :: strip_nullable_and_params
Strip thenullable
prefix and the params from the type name self
core :: Text :: substring_from
Create a substring fromself
beginning at the from
position
core :: Text :: to_camel_case
Takes a snake caseself
and converts it to camel case
core :: Text :: to_cmangle
Mangle a string to be a unique string only made of alphanumeric characters and underscores.core :: Text :: to_percent_encoding
Encodeself
to percent (or URL) encoding
serialization :: Serializable :: to_pretty_json
Serializeself
to plain pretty JSON
core :: Text :: to_program_name
Convert the path (self
) to a program name.
core :: Text :: to_snake_case
Takes a camel caseself
and converts it to snake case
core :: Text :: to_sql_date_string
Format the date represented byself
into an escaped string for SQLite
core :: Text :: unescape_json
Removes JSON-escaping if necessary in a JSON stringcore :: Text :: unescape_nit
Return a string where Nit escape sequences are transformed.core :: Text :: unescape_to_bytes
Return aBytes
instance where Nit escape sequences are transformed.
core :: Text :: user_exists
Does the operating system know the user namedself
?
core :: FlatBuffer :: with_capacity
Create a new empty string with a given capacity.core :: Writable :: write_to_bytes
Likewrite_to
but return a new Bytes (may be quite large)
core :: Writable :: write_to_file
Likewrite_to
but take care of creating the file
core :: Writable :: write_to_string
Likewrite_to
but return a new String (may be quite large).
serialization :: DirectSerializable
Instances of this class are not delayed and instead serialized immediatelySerializer::serialize
mpi :: Receptacle
Something which can receive data directly and efficiently from MPI
# Mutable strings of characters.
class FlatBuffer
super FlatText
super Buffer
redef fun chars do return new FlatBufferCharView(self)
redef fun bytes do return new FlatBufferByteView(self)
private var capacity = 0
redef fun fast_cstring do return _items.fast_cstring(0)
redef fun substrings do return new FlatSubstringsIter(self)
# Re-copies the `CString` into a new one and sets it as the new `Buffer`
#
# This happens when an operation modifies the current `Buffer` and
# the Copy-On-Write flag `written` is set at true.
private fun reset do
var nns = new CString(capacity)
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 _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 = _byte_length
if bt + len > capacity then
capacity = capacity * 2 + 2
nit = new CString(capacity)
oit.copy_to(nit, 0, 0, from)
end
oit.copy_to(nit, bt - from, from, from + len)
end
# Shifts the content of the buffer by `len` bytes to the left, starting at `from`
#
# 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, _byte_length - from, from, from - len)
end
redef fun []=(index, item)
do
assert index >= 0 and index <= _length
if written then reset
if index == _length then
add item
return
end
var it = _items
var ip = it.char_to_byte_index(index)
var c = it.char_at(ip)
var clen = c.u8char_len
var itemlen = item.u8char_len
var size_diff = itemlen - clen
if size_diff > 0 then
rshift_bytes(ip + clen, size_diff)
else if size_diff < 0 then
lshift_bytes(ip + clen, -size_diff)
end
_byte_length += size_diff
it.set_char_at(ip, item)
end
redef fun insert(s, pos) do
assert pos >= 0 and pos <= length
if pos == length then
append s
return
end
var slen = s.byte_length
enlarge(byte_length + slen)
var it = _items
var shpos = it.char_to_byte_index(pos)
rshift_bytes(shpos, slen)
s.copy_to_native(it, slen, 0, shpos)
length += s.length
byte_length += slen
end
redef fun insert_char(c, pos) do
assert pos >= 0 and pos <= length
if pos == length then
add c
return
end
var clen = c.u8char_len
enlarge(byte_length + clen)
var it = _items
var shpos = it.char_to_byte_index(pos)
rshift_bytes(shpos, clen)
it.set_char_at(shpos, c)
length += 1
byte_length += clen
end
redef fun add(c)
do
if written then reset
var clen = c.u8char_len
var bt = _byte_length
enlarge(bt + clen)
_items.set_char_at(bt, c)
_byte_length += clen
_length += 1
end
redef fun clear do
_byte_length = 0
_length = 0
if written then
_capacity = 16
reset
end
end
redef fun empty do return new Buffer
redef fun enlarge(cap)
do
var c = capacity
if cap <= c then return
if c <= 16 then c = 16
while c <= cap do c = c * 2
# The COW flag can be set at false here, since
# it does a copy of the current `Buffer`
written = false
var bln = _byte_length
var a = new CString(c)
if bln > 0 then
var it = _items
if bln > 0 then it.copy_to(a, bln, 0, 0)
end
_items = a
capacity = c
end
redef fun to_s
do
written = true
var bln = _byte_length
if bln == 0 then _items = new CString(1)
return new FlatString.full(_items, bln, 0, _length)
end
redef fun to_cstring
do
var bln = _byte_length
var new_native = new CString(bln + 1)
new_native[bln] = 0
if _length > 0 then _items.copy_to(new_native, bln, 0, 0)
return new_native
end
# Create a new empty string.
init do end
# Low-level creation a new buffer with given data.
#
# `_items` will be used as is, without copy, to store the characters of the buffer.
# Aliasing issues is the responsibility of the caller.
#
# 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: CString, capacity, byte_length, length: Int)
do
self._items = items
self.capacity = capacity
self._byte_length = byte_length
self._length = length
end
# Create a new string copied from `s`.
init from(s: Text)
do
_items = new CString(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 = _byte_length
end
# Create a new empty string with a given capacity.
init with_capacity(cap: Int)
do
assert cap >= 0
_items = new CString(cap)
capacity = cap
_byte_length = 0
end
redef fun append(s)
do
if s.is_empty then return
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, _byte_length)
else
for i in s.substrings do append i
return
end
_byte_length = nln
_length += s.length
end
# Copies the content of self in `dest`
fun copy(start: Int, len: Int, dest: Buffer, new_start: Int)
do
var self_chars = self.chars
var dest_chars = dest.chars
for i in [0..len-1] do
dest_chars[new_start+i] = self_chars[start+i]
end
end
redef fun substring(from, count)
do
assert count >= 0
if from < 0 then from = 0
if (from + count) > _length then count = _length - from
if count <= 0 then return new Buffer
var its = _items
var bytefrom = its.char_to_byte_index(from)
var byteto = its.char_to_byte_index(count + from - 1)
byteto += its.char_at(byteto).u8char_len - 1
var byte_length = byteto - bytefrom + 1
var r_items = new CString(byte_length)
its.copy_to(r_items, byte_length, bytefrom, 0)
return new FlatBuffer.with_infos(r_items, byte_length, byte_length, count)
end
redef fun append_substring_impl(s, from, length) do
if length <= 0 then return
if not s isa FlatText then
super
return
end
var sits = s._items
var bytest = s.char_to_byte_index(from)
var bytend = s.char_to_byte_index(from + length - 1)
var btln = bytend - bytest + sits.char_at(bytend).u8char_len
enlarge(btln + _byte_length)
sits.copy_to(_items, btln, bytest, _byte_length)
_byte_length += btln
_length += length
end
redef fun remove_at(p, len) do
if len == null then len = 1
if len == 0 then return
var its = _items
var bst = char_to_byte_index(p)
var bend = char_to_byte_index(p + len - 1)
bend += its.char_at(bend).u8char_len
var blen = bend - bst
lshift_bytes(bend, bend - bst)
byte_length -= blen
length -= len
end
redef fun reverse
do
written = false
var ns = new FlatBuffer.with_capacity(capacity)
for i in chars.reverse_iterator do ns.add i
_items = ns._items
end
redef fun times(repeats)
do
var bln = _byte_length
var x = new FlatString.full(_items, bln, 0, _length)
for i in [1 .. repeats[ do
append(x)
end
end
redef fun upper
do
if written then reset
for i in [0 .. _length[ do self[i] = self[i].to_upper
end
redef fun lower
do
if written then reset
for i in [0 .. _length[ do self[i] = self[i].to_lower
end
end
lib/core/text/flat.nit:865,1--1163,3
redef class FlatBuffer
redef fun internal_to_dot
do
return "n{object_id} [label=\"FlatBuffer\\nbyte_length = {byte_length}\\nlength = {length}\\ncapacity = {capacity}\\nText = {escape_to_dot}\"];\n"
end
end
lib/ropes_debug/ropes_debug.nit:49,1--54,3
redef class FlatBuffer
init do
sys.flatbuf_allocations += 1
end
redef fun bytepos do
sys.bytepos_call.inc "FlatBuffer"
return super
end
redef fun bytepos=(p) do
sys.bytepos_call.inc "FlatBuffer"
super
end
redef fun position do
sys.position_call.inc "FlatBuffer"
return super
end
redef fun position=(p) do
sys.position_call.inc "FlatBuffer"
super
end
redef fun byte_length do
sys.byte_length_call.inc "FlatBuffer"
return super
end
redef fun length do
sys.length_calls.inc "FlatBuffer"
return super
end
redef fun [](i) do
sys.index_call.inc "FlatBuffer"
return super
end
redef fun char_to_byte_index(i) do
sys.index_call.inc "FlatBuffer"
return super
end
end
lib/text_stat/text_stat.nit:215,1--260,3
redef class FlatBuffer
super Receptacle
redef fun recv(mpi, at, count, source, tag, comm)
do
var min_capacity = at + count
if capacity < min_capacity then enlarge min_capacity
var array
if at != 0 then
array = items + at
else array = items
mpi.native_recv(array, count, new DataType.char,
source, tag, new Comm.world, new Status.ignore)
length = capacity
end
redef fun recv_fill(mpi, dest, tag, comm) do recv(mpi, 0, capacity, dest, tag, comm)
end
lib/mpi/mpi.nit:436,1--456,3