String
core :: Concat :: _byte_length
core :: Concat :: _flat_cache
Cache for the latest accessed FlatString inself
core :: Concat :: _flat_last_pos_start
Position of the beginning offlat_cache
in self
core :: Concat :: byte_length=
core :: Concat :: defaultinit
core :: Concat :: flat_cache
Cache for the latest accessed FlatString inself
core :: Concat :: flat_cache=
Cache for the latest accessed FlatString inself
core :: Concat :: flat_last_pos_start
Position of the beginning offlat_cache
in self
core :: Concat :: flat_last_pos_start=
Position of the beginning offlat_cache
in self
core :: Concat :: get_leaf_at
core :: Concat :: recurse_balance
core $ Concat :: copy_to_native
Copiesn
bytes from self
at src_offset
into dest
starting at dest_offset
ropes_debug :: ropes_debug $ Concat :: internal_to_dot
Writes self as a dot file on the hard drivecore $ Concat :: substrings
Iterates on the substrings of self if anycore :: Concat :: _byte_length
core :: Concat :: _flat_cache
Cache for the latest accessed FlatString inself
core :: Concat :: _flat_last_pos_start
Position of the beginning offlat_cache
in self
core :: Text :: _hash_cache
serialization :: Serializable :: accept_inspect_serializer_core
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 :: Text :: apply_format
core :: Text :: binarydigest_to_bytes
Return aBytes
by reading 0 and 1.
core :: Concat :: byte_length=
core :: Text :: capitalized
Returns a capitalizedself
core :: Text :: chars_to_escape_csv
How many more bytes should be allocated for CSV escaping ?core :: Text :: chars_to_unescape_csv
How many bytes should be removed for CSV unescaping ?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 :: Rope :: defaultinit
core :: Cloneable :: defaultinit
core :: Text :: defaultinit
nitc :: JsonRef :: defaultinit
core :: Pattern :: defaultinit
core :: Writable :: defaultinit
core :: Concat :: defaultinit
core :: Comparable :: defaultinit
sqlite3 :: Sqlite3Data :: defaultinit
mpi :: Sendable :: defaultinit
core :: Object :: defaultinit
core :: String :: 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_csv
Escape the content ofself
for inclusion in a CSV document
core :: Text :: escape_to_gettext
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 :: 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).core :: String :: filter_nonprintable
Use a special notation for whitespace characters that are not'\n'
(LFD) or ' '
(space).
core :: Concat :: flat_cache
Cache for the latest accessed FlatString inself
core :: Concat :: flat_cache=
Cache for the latest accessed FlatString inself
core :: Concat :: flat_last_pos_start
Position of the beginning offlat_cache
in self
core :: Concat :: flat_last_pos_start=
Position of the beginning offlat_cache
in self
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 :: Concat :: get_leaf_at
core :: Text :: get_numext
Gets the numeric extension (i/u 8/16/32) inself
is present
core :: String :: get_translation
Gets the translation ofself
via gettext from dir
using domain
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 :: hash_cache
core :: Text :: hash_cache=
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 :: html_link_prefixes
core :: Text :: http_download
Download the file at URLself
to output_path
with a simple HTTP request
self
core :: Text :: index_of_from
Gets the index of the first occurence of ´c´ starting from ´pos´core :: Text :: internal_to_dot
Writes self as a dot file on the hard drivecore :: 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 :: String :: is_space_or_tab
Is the character atindex
a space or a tab
core :: Text :: is_valid_html_tag
core :: String :: is_valid_macro_name
Isself
a valid macro identifier?
core :: Text :: is_whitespace
Is the string non-empty but only made of whitespaces?core :: Text :: json_need_escape
Doesself
need treatment from JSON to Nit ?
core :: Text :: json_to_nit_string
Escapesself
from a JSON string to a Nit string
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.core :: String :: md_to_html
Parseself
as markdown and return the HTML representation
core :: String :: md_to_html2
core :: Text :: meta_from_fence
Extract string found at end of fence opening.serialization :: Serializable :: msgpack_extra_array_items
Hook to request a larger than usual metadata arraycore :: Object :: native_class_name
The class name of the object in CString format.core :: String :: normalize_reference
Normalize link reference namescore :: Object :: output_class_name
Display class name on stdout (debug only).core :: Text :: parse_bmfont
Parseself
as an XML BMFont description file
core :: String :: program_is_in_path
Search for the programself
in all directories from PATH
core :: Text :: read_md_link
Read a markdown link address and append it to theout
buffer.
core :: Text :: read_md_link_id
Read a markdown link text and append it to theout
buffer.
core :: Text :: read_raw_until
Readself
as raw text until nend
and append it to the out
buffer.
core :: Text :: read_until
Readself
until nend
and append it to the out
buffer.
core :: Text :: read_until
Readself
as raw text until nend
and append it to the out
buffer.
core :: String :: read_until_char
Readsself
until to
is encountered and store result in buffer
.
core :: String :: read_until_pos
Readsself
from pos from
to pos to
and store result in buffer
.
core :: Text :: read_xml_until
Readself
as XML until to
and append it to the out
buffer.
core :: Concat :: recurse_balance
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 :: run_js_native
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
serialization :: Serializable :: serialize_to_or_delay
Accept references or force direct serialization (usingserialize_to
)
core :: Text :: simplify_path
Simplify a file path by remove useless.
, removing //
, and resolving ..
core :: Text :: skip_spaces
Get the position of the next non-space character.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 :: strip_numext
Removes the numeric extension if presentcore :: Text :: strip_numhead
Removes the numeric head ofself
if present
core :: String :: strip_start_slashes
Returns aString
copy of self
without any of the prefixed '/'s
core :: Text :: substring_from
Create a substring fromself
beginning at the from
position
core :: Text :: substrings
Iterates on the substrings of self if anycore :: 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_csv
Unescape the content ofself
from CSV format to Nit String
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 :: Text :: write_native_to
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
# Node that represents a concatenation between two `String`
private class Concat
super Rope
super String
redef fun chars do return new RopeChars(self)
redef fun bytes do return new RopeBytes(self)
redef var length is noinit
redef var byte_length is noinit
redef fun substrings do return new RopeSubstrings.from(self, 0)
redef fun empty do return ""
# Cache for the latest accessed FlatString in `self`
var flat_cache: FlatString is noinit
# Position of the beginning of `flat_cache` in `self`
var flat_last_pos_start: Int is noinit
redef fun to_cstring do
var len = _byte_length
var ns = new CString(len + 1)
ns[len] = 0
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
return ns
end
# Left child of the node
var left: String
# Right child of the node
var right: String
init do
var l = _left
var r = _right
_length = l.length + r.length
_byte_length = l.byte_length + r.byte_length
_flat_last_pos_start = _length
end
redef fun is_empty do return _byte_length == 0
redef fun output do
_left.output
_right.output
end
redef fun iterator do return new RopeCharIterator.from(self, 0)
redef fun *(i) do
var x: String = self
for j in [1 .. i[ do x += self
return x
end
redef fun [](i) do
assert i >= 0 and i < _length
var flps = _flat_last_pos_start
if i >= flps then
var fc = _flat_cache
if i < flps + fc._length then return fc.fetch_char_at(i - flps)
end
var lf = get_leaf_at(i)
return lf.fetch_char_at(i - _flat_last_pos_start)
end
fun get_leaf_at(pos: Int): FlatString do
var flps = _flat_last_pos_start
if pos >= flps then
var fc = _flat_cache
if pos < flps + fc._length then return fc
end
var s: String = self
var st = pos
loop
if s isa FlatString then break
s = s.as(Concat)
var lft = s._left
var llen = lft.length
if pos >= llen then
s = s._right
pos -= llen
else
s = lft
end
end
_flat_last_pos_start = st - pos
_flat_cache = s
return s
end
redef fun substring(from, count) do
if from < 0 then
count += from
if count < 0 then return ""
from = 0
end
var ln = _length
if (count + from) > ln then count = ln - from
if count <= 0 then return ""
var end_index = from + count - 1
var flps = _flat_last_pos_start
if from >= flps then
var fc = _flat_cache
if end_index < flps + fc._length then
return fc.substring_impl(from - flps, count, end_index - flps)
end
end
var lft = _left
var llen = lft.length
if from < llen then
if from + count < llen then return lft.substring(from, count)
var lsublen = llen - from
return lft.substring_from(from) + _right.substring(0, count - lsublen)
else
return _right.substring(from - llen, count)
end
end
redef fun reversed do return new Concat(_right.reversed, _left.reversed)
redef fun insert_at(s, pos) do
var lft = _left
if pos > lft.length then
return lft + _right.insert_at(s, pos - lft.length)
end
return lft.insert_at(s, pos) + _right
end
redef fun to_upper do return new Concat(_left.to_upper, _right.to_upper)
redef fun to_lower do return new Concat(_left.to_lower, _right.to_lower)
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
var rlen = r.byte_length
if rlen + slen > maxlen then return new Concat(self, s)
return new Concat(_left, r + s)
end
end
redef fun copy_to_native(dest, n, src_offset, dest_offset) do
var l = _left
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
n -= lcopy
src_offset = 0
end
_right.copy_to_native(dest, n, src_offset, dest_offset)
end
# Returns a balanced version of `self`
fun balance: String do
var children = new Array[String]
var rnod: String
var iter: nullable RopeCharIteratorPiece = new RopeCharIteratorPiece(self, false, false, null)
loop
if iter == null then break
rnod = iter.node
if not rnod isa Concat then
children.push rnod
iter = iter.prev
continue
end
if not iter.ldone then
iter.ldone = true
iter = new RopeCharIteratorPiece(rnod._left, false, false, iter)
else if not iter.rdone then
iter.rdone = true
iter = new RopeCharIteratorPiece(rnod._right, false, false, iter)
else
iter = iter.prev
end
end
return recurse_balance(children, children.length)
end
fun recurse_balance(nodes: Array[String], len: Int): String do
var finpos = 0
var stpos = 0
while stpos < len do
if len - stpos > 1 then
nodes[finpos] = new Concat(nodes[stpos], nodes[stpos + 1])
stpos += 2
else
nodes[finpos] = nodes[stpos]
stpos += 1
end
finpos += 1
end
if finpos == 1 then return nodes[0]
return recurse_balance(nodes, finpos)
end
end
lib/core/text/ropes.nit:68,1--282,3
redef class Concat
redef fun internal_to_dot
do
var s = "n{object_id} [label = {length}];\n"
s += "n{object_id} -> n{left.object_id} [label = \"left\"];\n"
s += left.internal_to_dot
s += "n{object_id} -> n{right.object_id} [label = \"right\"];\n"
s += right.internal_to_dot
return s
end
end
lib/ropes_debug/ropes_debug.nit:30,1--40,3
redef class Concat
init do
sys.concat_allocations += 1
end
redef fun byte_length do
sys.byte_length_call.inc "Concat"
return super
end
redef fun [](i) do
sys.index_call.inc "Concat"
if flat_last_pos_start != -1 then
var fsp = i - flat_last_pos_start
if fsp >= 0 and fsp < flat_cache.length then return flat_cache[fsp]
end
sys.concat_cache_miss += 1
var s: String = self
var st = i
loop
if s isa FlatString then break
s = s.as(Concat)
var lft = s.left
var llen = lft.length
if i >= llen then
s = s.right
i -= llen
else
s = s.left
end
end
flat_last_pos_start = st - i
flat_cache = s
return s[i]
end
end
lib/text_stat/text_stat.nit:133,1--168,3