core :: FlatString
core :: FlatString :: defaultinit
core :: FlatString :: first_byte=
Index at whichself
begins in _items
, inclusively
core $ FlatString :: SELF
Type of this instance, automatically specialized in every classtext_stat :: text_stat $ FlatString :: byte_length
Number of bytes inself
core $ FlatString :: bytes
Gets a view on the bytes of the Text objecttext_stat :: text_stat $ FlatString :: char_to_byte_index
Index of the characterindex
in _items
core $ FlatString :: chars
Gets a view on the chars of the Text objectcore $ FlatString :: fast_cstring
Returns a char* starting at positionfirst_byte
core :: file $ FlatString :: file_extension
Return right-most extension (without the dot)core $ FlatString :: first_byte
Index at whichself
begins in _items
, inclusively
text_stat :: text_stat $ FlatString :: first_byte
First byte of the CStringtext_stat :: text_stat $ FlatString :: first_byte=
Index at whichself
begins in _items
, inclusively
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 :: binarydigest_to_bytes
Return aBytes
by reading 0 and 1.
core :: FlatText :: byte_length=
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 :: String :: defaultinit
core :: Pattern :: defaultinit
core :: Writable :: defaultinit
mpi :: Sendable :: defaultinit
core :: Object :: defaultinit
core :: Comparable :: defaultinit
core :: Cloneable :: defaultinit
core :: Text :: defaultinit
core :: FlatText :: defaultinit
core :: FlatString :: defaultinit
sqlite3 :: Sqlite3Data :: 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).core :: FlatString :: first_byte=
Index at whichself
begins in _items
, inclusively
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 :: 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 :: 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 :: 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 :: 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
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 :: String :: program_is_in_path
Search for the programself
in all directories from PATH
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 :: 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 :: 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 :: 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
# Immutable strings of characters.
abstract class FlatString
super FlatText
super String
# Index at which `self` begins in `_items`, inclusively
redef var first_byte is noinit
redef fun chars do return new FlatStringCharView(self)
redef fun bytes do return new FlatStringByteView(self)
redef fun to_cstring do
var blen = _byte_length
var new_items = new CString(blen + 1)
_items.copy_to(new_items, blen, _first_byte, 0)
new_items[blen] = 0
return new_items
end
redef fun reversed do
var b = new FlatBuffer.with_capacity(_byte_length + 1)
var i = _length - 1
while i >= 0 do
b.add self.fetch_char_at(i)
i -= 1
end
var s = b.to_s.as(FlatString)
s._length = self._length
return s
end
redef fun fast_cstring do return _items.fast_cstring(_first_byte)
redef fun substring(from, count)
do
if count <= 0 then return ""
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
return substring_impl(from, count, end_index)
end
private fun substring_impl(from, count, end_index: Int): String do
var cache = _position
var dfrom = (cache - from).abs
var dend = (end_index - from).abs
var bytefrom: Int
var byteto: Int
if dfrom < dend then
bytefrom = char_to_byte_index(from)
byteto = char_to_byte_index(end_index)
else
byteto = char_to_byte_index(end_index)
bytefrom = char_to_byte_index(from)
end
var its = _items
byteto += its.length_of_char_at(byteto) - 1
var s = new FlatString.full(its, byteto - bytefrom + 1, bytefrom, count)
return s
end
redef fun empty do return "".as(FlatString)
redef fun to_upper
do
var outstr = new FlatBuffer.with_capacity(self._byte_length + 1)
var mylen = _length
var pos = 0
while pos < mylen do
outstr.add(chars[pos].to_upper)
pos += 1
end
return outstr.to_s
end
redef fun to_lower
do
var outstr = new FlatBuffer.with_capacity(self._byte_length + 1)
var mylen = _length
var pos = 0
while pos < mylen do
outstr.add(chars[pos].to_lower)
pos += 1
end
return outstr.to_s
end
redef fun output
do
for i in chars do i.output
end
##################################################
# String Specific Methods #
##################################################
# Low-level creation of a new string with minimal 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 with_infos(items: CString, byte_length, from: Int)
do
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: CString, byte_length, from, length: Int)
do
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)
do
if not other isa FlatText then return super
if self.object_id == other.object_id then return true
var my_length = _byte_length
if other._byte_length != my_length then return false
var my_index = _first_byte
var its_index = other.first_byte
var last_iteration = my_index + my_length
var its_items = other._items
var my_items = self._items
while my_index < last_iteration do
if my_items[my_index] != its_items[its_index] then return false
my_index += 1
its_index += 1
end
return true
end
redef fun <(other)
do
if not other isa FlatText then return super
if self.object_id == other.object_id then return false
var myits = _items
var itsits = other._items
var mbt = _byte_length
var obt = other.byte_length
var minln = if mbt < obt then mbt else obt
var mst = _first_byte
var ost = other.first_byte
for i in [0 .. minln[ do
var my_curr_char = myits[mst]
var its_curr_char = itsits[ost]
if my_curr_char > its_curr_char then return false
if my_curr_char < its_curr_char then return true
mst += 1
ost += 1
end
return mbt < obt
end
redef fun +(o) do
var s = o.to_s
var slen = s.byte_length
var mlen = _byte_length
var nlen = mlen + slen
var mits = _items
var mifrom = _first_byte
if s isa FlatText then
var sits = s._items
var sifrom = s.first_byte
var ns = new CString(nlen + 1)
mits.copy_to(ns, mlen, mifrom, 0)
sits.copy_to(ns, slen, sifrom, mlen)
return new FlatString.full(ns, nlen, 0, _length + o.length)
else
abort
end
end
redef fun *(i) do
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 CString(new_byte_length + 1)
ns[new_byte_length] = 0
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_byte_length, 0, newlen)
end
redef fun hash
do
if hash_cache == null then
# djb2 hash algorithm
var h = 5381
var i = _first_byte
var my_items = _items
var max = last_byte
while i <= max do
h = (h << 5) + h + my_items[i].to_i
i += 1
end
hash_cache = h
end
return hash_cache.as(not null)
end
redef fun substrings do return new FlatSubstringsIter(self)
end
lib/core/text/flat.nit:408,1--659,3
redef class FlatString
redef fun insert_at(s, pos) do
var l = substring(0, pos)
var r = substring_from(pos)
return l + s + r
end
redef fun +(o) do
var s = o.to_s
var slen = s.byte_length
var mlen = _byte_length
if slen == 0 then return self
if mlen == 0 then return s
var nlen = slen + mlen
if s isa FlatString then
if nlen > maxlen then return new Concat(self, s)
var mits = _items
var sifrom = s._first_byte
var mifrom = _first_byte
var sits = s._items
var ns = new CString(nlen + 1)
mits.copy_to(ns, mlen, mifrom, 0)
sits.copy_to(ns, slen, sifrom, mlen)
return new FlatString.full(ns, nlen, 0, length + s.length)
else if s isa Concat then
var sl = s._left
var sllen = sl.byte_length
if sllen + mlen > maxlen then return new Concat(self, s)
return new Concat(self + sl, s._right)
else
abort
end
end
end
lib/core/text/ropes.nit:284,1--318,3
redef class FlatString
redef fun write_native_to(s)
do
s.write_native(items, first_byte, byte_length)
end
redef fun file_extension do
var its = _items
var p = last_byte
var c = its[p]
var st = _first_byte
while p >= st and c != u'.' do
p -= 1
c = its[p]
end
if p <= st then return null
var ls = last_byte
return new FlatString.with_infos(its, ls - p, p + 1)
end
redef fun basename(extension) do
var s = self
if is_windows then s = s.replace("\\", "/").as(FlatString)
var bname
var l = s.last_byte
var its = s._items
var min = s._first_byte
var sl = u'/'
while l > min and its[l] == sl do l -= 1
if l == min then return "/"
var ns = l
while ns >= min and its[ns] != sl do ns -= 1
bname = new FlatString.with_infos(its, l - ns, ns + 1)
return if extension != null then bname.strip_extension(extension) else bname
end
end
lib/core/file.nit:1357,1--1394,3
redef class FlatString
redef fun internal_to_dot
do
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
lib/ropes_debug/ropes_debug.nit:42,1--47,3
redef class FlatString
redef fun bytepos do
sys.bytepos_call.inc "FlatString"
return super
end
redef fun bytepos=(p) do
sys.bytepos_call.inc "FlatString"
super
end
redef fun position do
sys.position_call.inc "FlatString"
return super
end
redef fun position=(p) do
sys.position_call.inc "FlatString"
super
end
redef fun byte_length do
sys.byte_length_call.inc "FlatString"
return super
end
redef fun first_byte do
sys.first_byte_call += 1
return super
end
redef fun first_byte=(v) do
sys.first_byte_call += 1
super
end
redef fun last_byte do
sys.last_byte_call += 1
return super
end
private var length_cache: nullable Int = null
redef fun length do
sys.length_calls.inc "FlatString"
var l = length_cache
if l != null then return l
sys.length_cache_miss.inc "FlatString"
if byte_length == 0 then return 0
var st = first_byte
var its = items
var ln = 0
var lst = last_byte
while st <= lst do
st += its.length_of_char_at(st)
ln += 1
end
length_cache = ln
return ln
end
redef fun char_to_byte_index(i) do
sys.index_call.inc "FlatString"
return super
end
end
lib/text_stat/text_stat.nit:262,1--328,3