String objects may be created using literals.
assert "Hello World!" isa String
core :: String :: defaultinit
core :: String :: get_translation
Gets the translation ofself
via gettext from dir
using domain
core :: String :: is_valid_macro_name
Isself
a valid macro identifier?
core :: String :: md_to_html
Parseself
as markdown and return the HTML representation
core :: String :: md_to_html2
core :: String :: program_is_in_path
Search for the programself
in all directories from PATH
core :: String :: strip_start_slashes
Returns aString
copy of self
without any of the prefixed '/'s
android :: bundle $ String :: add_to_bundle
Called by[]=
to dynamically choose the appropriate method according
serialization :: engine_tools $ String :: is_same_serialized
Isself
the same as other
in a serialization context?
serialization :: engine_tools $ String :: serialization_hash
Hash value use for serializationcore $ String :: to_camel_case
Takes a snake caseself
and converts it to camel case
core $ String :: to_snake_case
Takes a camel caseself
and converts it to snake case
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 :: Text :: capitalized
Returns a capitalizedself
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
mpi :: Sendable :: defaultinit
sqlite3 :: Sqlite3Data :: defaultinit
core :: Object :: defaultinit
core :: Comparable :: defaultinit
core :: Text :: defaultinit
core :: Writable :: defaultinit
core :: Pattern :: defaultinit
core :: Cloneable :: 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 :: 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 :: 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 sequence of characters.
#
# String objects may be created using literals.
#
# ~~~
# assert "Hello World!" isa String
# ~~~
abstract class String
super Text
redef type SELFTYPE: String is fixed
redef fun to_s do return self
redef fun clone do return self
redef fun to_buffer do return new Buffer.from_text(self)
redef fun to_camel_case do
if self.is_upper then return self
var new_str = new Buffer.with_cap(length)
new_str.append self
new_str.camel_case
return new_str.to_s
end
redef fun to_snake_case do
if self.is_lower then return self
var new_str = new Buffer.with_cap(self.length)
new_str.append self
new_str.snake_case
return new_str.to_s
end
end
lib/core/text/abstract_text.nit:1481,1--1516,3
redef class String
# Return environment value for the symbol.
# If there is no such environment variable, then return ""
#
# assert "PATH".environ != ""
# assert "NIT %\n".environ == ""
fun environ: String
do
var res = self.to_cstring.get_environ
# FIXME: There is no proper way to handle NULL C string yet. What a pitty.
var nulstr = once ("".to_cstring.get_environ)
if res != nulstr then
return res.to_s
else
return ""
end
end
# Set the enviroment value of a variable.
#
# "NITis".setenv("fun")
# assert "NITis".environ == "fun"
fun setenv(v: String) do to_cstring.setenv( v.to_cstring )
# Search for the program `self` in all directories from `PATH`
fun program_is_in_path: Bool
do
var sep = if is_windows then ";" else ":"
var full_path = "PATH".environ
var paths = full_path.split(sep)
for path in paths do if path.file_exists then
if path.join_path(self).file_exists then return true
if is_windows and (path / self + ".exe").file_exists then return true
end
return false
end
end
lib/core/environ.nit:22,1--59,3
redef class String
# Returns a UTF-16 encoded version of `self`
fun to_u16string: U16String do return new U16String.from_string(self)
# Returns the number of UTF-16 code units in `self`
fun u16_length: Int do
var n = 0
for c in chars do
if c.to_i > 0xFFFF then n += 2 else n += 1
end
return n
end
end
lib/core/text/u16_string.nit:233,1--245,3
redef class String
# Gets the translation of `self` via gettext from `dir` using `domain`
#
# `domain`: Gettext domain, i.e. file/module name
# `dir`: Where the locale/LC_MESSAGES folder for this domain is located
fun get_translation(domain, dir: String): String do
bindtextdomain(domain, dir)
return dgettext(domain)
end
# Gettext `gettext`, SEE gettext manual for further info
fun gettext: String
import String.to_cstring, CString.to_s `{
return CString_to_s(gettext(String_to_cstring(self)));
`}
# Gettext `dgettext`, SEE gettext manual for further info
fun dgettext(domain: String): String
import String.to_cstring, CString.to_s `{
return CString_to_s(dgettext(String_to_cstring(domain), String_to_cstring(self)));
`}
end
lib/gettext/gettext.nit:45,1--66,3
redef class String
# Get the unique corresponding to the string
fun to_symbol: Symbol
do
var symbol_dictionary = once new HashMap[String, Symbol]
if symbol_dictionary.has_key(self) then
return symbol_dictionary[self]
else
var symbol = new Symbol(self)
symbol_dictionary[self] = symbol
return symbol
end
end
end
lib/symbol/symbol.nit:16,1--29,3
redef class String
# Remove escape backslash from string
fun unescape_string: String do
if not has(re_escaped) then return self
var buffer = new Buffer
var match = search(re_escaped)
var last_end = 0
while match != null do
buffer.append substring(last_end, match.from - last_end)
buffer.append substring(match.from + 1, 1)
last_end = match.after
match = search_from(re_escaped, last_end)
end
if last_end < length then
buffer.append substring(last_end, length - last_end)
end
return buffer.to_s
end
# Normalize link reference names
private fun normalize_reference: String do
var stripped = self.substring(1, length - 2).trim
var lowercase = stripped.to_lower # TODO utf-8
return lowercase.replace(re_whitespace, " ")
end
end
lib/markdown2/markdown_inline_parsing.nit:1368,1--1395,3
redef class String
# Reads `self` from pos `from` to pos `to` and store result in `buffer`.
private fun read_until_pos(from, to: Int, buffer: Buffer): Int do
if from < 0 or from >= length or
to < 0 or to >= length or
from >= to then return -1
var pos = from
while pos < to do
buffer.add self[pos]
pos += 1
end
return pos
end
# Reads `self` until `to` is encountered and store result in `buffer`.
#
# Returns `to` position or `-1` if not found.
private fun read_until_char(from: Int, char: Char, buffer: Buffer): Int do
if from < 0 or from >= length then return -1
var pos = from
while pos > -1 and pos < length do
var c = self[pos]
if c == char then return pos
buffer.add c
pos += 1
end
return -1
end
# Is `self` a valid macro identifier?
#
# A macro identifier is valid if:
#
# * starts with an uppercase letter
# * contains only numers, uppercase letters or '_'
#
# # valid
# assert "NAME".is_valid_macro_name
# assert "FIRST_NAME".is_valid_macro_name
# assert "BLOCK1".is_valid_macro_name
# # invalid
# assert not "1BLOCK".is_valid_macro_name
# assert not "_BLOCK".is_valid_macro_name
# assert not "FIRST NAME".is_valid_macro_name
# assert not "name".is_valid_macro_name
fun is_valid_macro_name: Bool do
if not first.is_upper then return false
for c in self do
if not c.is_upper and c != '_' and not c.is_digit then return false
end
return true
end
end
lib/template/macro.nit:307,1--359,3
redef class String
# Parse `self` as markdown and return the HTML representation
#.
# var md = "**Hello World!**"
# var html = md.md_to_html
# assert html == "<p><strong>Hello World!</strong></p>\n"
fun md_to_html: Writable do
var processor = new MarkdownProcessor
return processor.process(self)
end
end
lib/markdown/markdown.nit:2603,1--2614,3
redef class String
# Is this string blank?
#
# i.e. contains only spacing characters.
private fun is_blank: Bool do
for i in [0 .. length[ do
var c = chars[i]
if c == ' ' or c == '\t' or c == '\n' or c == '\r' then
continue
else
return false
end
end
return true
end
# Is the character at `index` a space or a tab
#
# Return false if `index > self.length`.
private fun is_space_or_tab(index: Int): Bool do
if index >= length then return false
var c = chars[index]
return c == ' ' or c == '\t'
end
end
lib/markdown2/markdown_block_parsing.nit:1478,1--1503,3
redef class String super Sqlite3Data end
lib/sqlite3/sqlite3.nit:321,1--40
redef class String
redef fun serialization_hash do return hash
redef fun is_same_serialized(o) do return self == o
end
lib/serialization/engine_tools.nit:62,1--65,3
redef class String
# Returns a `String` copy of `self` without any of the prefixed '/'s
#
# Examples:
#
# assert "/home/".strip_start_slashes == "home/"
# assert "////home/".strip_start_slashes == "home/"
# assert "../home/".strip_start_slashes == "../home/"
fun strip_start_slashes: String
do
for i in chars.length.times do if chars[i] != '/' then return substring_from(i)
return ""
end
end
lib/nitcorn/file_server.nit:26,1--39,3
redef class String
redef fun add_to_bundle(bundle, key)
do
bundle.put_string(key, self.to_java_string)
end
end
lib/android/bundle/bundle.nit:714,1--719,3