String
This type holds a null terminated byte array in memory that represents an ASCII encoded text in Gambol. The underlying byte array can actually have any encoding however all functions and methods within this types assume ASCII encoding.
String is an immutable value type that points to a byte array. The memory referred to by this type is not owned by String. The assignment operator only copies the variable not the byte array it points to and therefore passing variables of type String around is efficient.
graph BT
N1["String"] -->|inherits| N2["StringAT"];
N1["String"] -->|inherits| N3["Hashable"];
N1["String"] -->|inherits| N4["Stringable"];
N1["String"] -->|inherits| N5["Length"];
N1["String"] -->|inherits| N6["RandomIterable[Char]"];
N6["RandomIterable[Char]"] -->|inherits| N7["ReverseIterable[Char]"];
N6["RandomIterable[Char]"] -->|inherits| N8["Unpackable[Char]"];
N8["Unpackable[Char]"] -->|inherits| N9["Iterable[Char]"];
N8["Unpackable[Char]"] -->|inherits| N10["UnpackableAT"];
N10["UnpackableAT"] -->|inherits| N5["Length"];
N10["UnpackableAT"] -->|inherits| N11["IterableAT"];
N10["UnpackableAT"] -->|inherits| N12["CollectionAT"];
N12["CollectionAT"] -->|inherits| N13["Any"];
N11["IterableAT"] -->|inherits| N13["Any"];
N5["Length"] -->|inherits| N13["Any"];
N9["Iterable[Char]"] -->|inherits| N11["IterableAT"];
N11["IterableAT"] -->|inherits| N13["Any"];
N7["ReverseIterable[Char]"] -->|inherits| N14["BidirectionalIterable[Char]"];
N14["BidirectionalIterable[Char]"] -->|inherits| N9["Iterable[Char]"];
N9["Iterable[Char]"] -->|inherits| N11["IterableAT"];
N11["IterableAT"] -->|inherits| N13["Any"];
N5["Length"] -->|inherits| N13["Any"];
N4["Stringable"] -->|inherits| N13["Any"];
N3["Hashable"] -->|inherits| N13["Any"];
N2["StringAT"] -->|inherits| N13["Any"];
Characteristics
Quality | Value |
---|---|
Inherits | StringAT, Hashable, Stringable, Length, RandomIterable[Char] |
Extends | N/A |
Decorators | #Gambol.layout.c; |
Is enum | false |
Is sealed | false |
Is extern | false |
Is abstract | false |
Is generator | false |
Has value semantics | true |
Has stored properties | true |
Should register destructor | false |
Has atomic memory | false |
Is copy assignable | true |
Is zero initializable | true |
Type Aliases
DType
DType = Char
Const Expressions
kAsciiLetters
const! kAsciiLetters = `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`
String representing all alphabetical ASCII characters.
kAsciiLowercase
const! kAsciiLowercase = `abcdefghijklmnopqrstuvwxyz`
String representing all lower-case alphabetical ASCII characters.
kAsciiUppercase
const! kAsciiUppercase = `ABCDEFGHIJKLMNOPQRSTUVWXYZ`
String representing all upper-case alphabetical ASCII characters.
kDigits
const! kDigits = `0123456789`
String representing all decimal digits in the ASCII character set.
kHexDigits
const! kHexDigits = `0123456789abcdefABCDEF`
String representing all hexadecimal digits in the ASCII character set.
kOctDigits
const! kOctDigits = `01234567`
String representing all octal digits in the ASCII character set.
kPunctuation
const! kPunctuation = `!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~`
String representing all punctuation ASCII characters.
kWhitespace
const! kWhitespace = `
`
String representing all white space characters in the ASCII character set.
kPrintable
const! kPrintable = `
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~`
String representing all printable characters in the ASCII character set.
Functions
from_char
from_char (c Char) -> String
from_c_str
from_c_str (cstr Pointer, len Len = -1, make_copy: Bool = true) -> String
len
is < 0 then the length of the String will be computed from cstr
first otherwise the correct len
must be provided or it will result in undefined behavior. Whether the array pointed to by cstr
is copied or not is determined by make_copy
.
full
full (len Len = 0, with_char Char = 32) -> String
len
with all characters set to with_char
join
join [T] (container T, delimiter String = ``) -> String
str
on all items in the container
and concatenate all the resultant strings into one string delimited by delimiter
.
translate
translate [T] (s SelfType, table T) -> SelfType
__kmp_compute_lps
__kmp_compute_lps (pattern String) -> List[Len]
__kmp_compute_reverse_lps
__kmp_compute_reverse_lps (pattern String) -> List[Len]
Methods
construct
#default
#Gambol.function.alwaysinline
construct (s @Self) -> Self
allocate
allocate (s @Self, len Len) -> Nil
len + 1
and insert the null character at the end.
reallocate
reallocate (s @Self, len Len) -> Nil
len + 1
and insert the null character at the end
get_raw_string
get_raw_string (s @Self) -> String
str
#Gambol.function.alwaysinline
str (s @Self) -> String
hash
#Gambol.function.alwaysinline
#strict
hash (s @Self, hasher strictly @ (Pointer, Len) -> Nil) -> Nil
len
#strict
#Gambol.function.alwaysinline
len (s @Self) -> Len
get_iterator
get_iterator (s @Self) -> StringIterator
get_reverse_iterator
get_reverse_iterator (s @Self) -> StringIterator[-1]
get_random_iterator
get_random_iterator (s @Self) -> StringRandomIterator
c_str
#Gambol.function.alwaysinline
c_str (s @Self) -> PointerToVariable[Char]
char_unchecked
#Gambol.function.alwaysinline
char_unchecked (s @Self, index ULen) -> Char
index
without doing any bounds checking
char
char (s @Self, index Len) -> Char
index
and raise IndexOutOfRangeException
if index is out of bounds
slice
slice (s @Self, range IndexRange) -> SelfType
range
.
find_first
find_first (s @Self, pattern SelfType, range IndexRange?) -> Len
pattern
in the given range
and return the index of the first charater.
range
must have a step size of 1 otherwise the function will raise a WrongArgumentException
find_last
find_last (s @Self, pattern SelfType, range IndexRange?) -> Len
pattern
in the given range
and return the index of the first charater.
range
must have a step size of 1 otherwise the function will raise a WrongArgumentException
find
find (s @Self, pattern SelfType, range IndexRange?, overlapping: Bool = true, count: Len = 0) -> List[Len]
pattern
in the given range
up to count
items starting from the beginning of the range and returns a list of the first character indices. You can use overlapping
to indicate if you want overlapping results or not.
range
must have a step size of 1 otherwise the function will raise a WrongArgumentException
replace
replace (s @Self, old SelfType, new SelfType, range IndexRange?, count: Len = 0, reverse: Bool = false) -> SelfType
old
with new
in the given range
up to count
items. You can start either from the beginning of the range or the end using reverse
.
range
must have a step size of 1 otherwise the function will raise a WrongArgumentException
count
count (s @Self, pattern SelfType, range IndexRange?, overlapping: Bool = true) -> Len
pattern
appears in the given range
. You can use overlapping
to indicate if overlapping instances are acceptable.
range
must have a step size of 1 otherwise the function will raise a WrongArgumentException
rfind
rfind (s @Self, pattern SelfType, range IndexRange?, overlapping: Bool = true, count: Len = 0) -> List[Len]
pattern
in the given range
up to count
items starting from the end of the range and returns a list of the first character indices. You can use overlapping
to indicate if you want overlapping results or not.
range
must have a step size of 1 otherwise the function will raise a WrongArgumentException
remove_prefix
remove_prefix (s @Self, prefix SelfType) -> SelfType
remove_suffix
remove_suffix (s @Self, suffix SelfType) -> SelfType
split
split (s @Self, delimiter SelfType, range IndexRange?, count: Len = 0, reverse: Bool = false) -> List[SelfType]
delimiter
in the given range
up to count
items starting from the beginning or the end if reverse
.
capitalize
capitalize (s @Self) -> SelfType
center
center (s @Self, width Len, fill_char Char = 32) -> SelfType
width
to the center using fill_char
as filler chraracters.
rjust
rjust (s @Self, width Len, fill_char Char = 32) -> SelfType
width
to the right using fill_char
as filler chraracters.
ljust
ljust (s @Self, width Len, fill_char Char = 32) -> SelfType
width
to the left using fill_char
as filler chraracters.
starts_with
starts_with (s @Self, prefix String, range IndexRange?) -> Bool
prefix
.
range
must have a step size of 1 or a WrongArgumentException
will be raised.
ends_with
ends_with (s @Self, suffix String, range IndexRange?) -> Bool
suffix
.
range
must have a step size of 1 or a WrongArgumentException
will be raised.
map
map (s @Self, update strictly (Char) -> Char, range IndexRange?, count: Len = 0, reverse: Bool = false) -> SelfType
update
function on each character in the given range
up to count
characters starting from the beginning of the range or the end if reverse
lower
lower (s @Self, range IndexRange?, count: Len = 0, reverse: Bool = false) -> SelfType
range
to lower case up to count
characters starting from the beginning of the range or the end if reverse
.
upper
upper (s @Self, range IndexRange?, count: Len = 0, reverse: Bool = false) -> SelfType
range
to upper case up to count
characters starting from the beginning of the range or the end if reverse
.
swapcase
swapcase (s @Self, range IndexRange?, count: Len = 0, reverse: Bool = false) -> SelfType
range
to the opposite case up to count
characters starting from the beginning of the range or the end if reverse
.
lstrip
lstrip (s @Self, chars SelfType = kWhitespace) -> SelfType
char
removed from the beginning of the string
rstrip
rstrip (s @Self, chars SelfType = kWhitespace) -> SelfType
char
removed from the end of the string
strip
strip (s @Self, chars SelfType = kWhitespace) -> SelfType
char
removed from the beginning and the end of the string
is_lower
is_lower (s @Self, range IndexRange?) -> Bool
range
are lower case, false otherwise
is_upper
is_upper (s @Self, range IndexRange?) -> Bool
range
are upper case, false otherwise
is_digit
is_digit (s @Self, range IndexRange?) -> Bool
range
are digits, false otherwise
is_alpha
is_alpha (s @Self, range IndexRange?) -> Bool
range
are alphabetical, false otherwise
is_alphanum
is_alphanum (s @Self, range IndexRange?) -> Bool
range
are alphanumeric, false otherwise
is_punctuation
is_punctuation (s @Self, range IndexRange?) -> Bool
range
are punctuations, false otherwise
is_space
is_space (s @Self, range IndexRange?) -> Bool
range
are space, false otherwise
is_null
is_null (s @Self, range IndexRange?) -> Bool
range
are null, false otherwise
is_printable
is_printable (s @Self, range IndexRange?) -> Bool
range
are printable, false otherwise
is_extended_ascii
is_extended_ascii (s @Self, range IndexRange?) -> Bool
range
are extended ascii characters, false otherwise
__set_char_unchecked
#Gambol.function.alwaysinline
__set_char_unchecked (s @Self, val Char, index ULen) -> Char
index
to val
without doing any bounds checking
__set_char
__set_char (s @Self, val Char, index Len) -> Char
index
to val
and raise IndexOutOfRangeException
if index is out of bounds
Binary Operators
=
#default
= (s @Self, o @Self) -> Self
==
== (s @Self, o @Self) -> Bool
is in
is in (s @Self, pattern String) -> Bool
pattern
>
#Gambol.function.alwaysinline
> (s @Self, o @Self) -> Bool
>=
#Gambol.function.alwaysinline
>= (s @Self, o @Self) -> Bool
<
#Gambol.function.alwaysinline
< (s @Self, o @Self) -> Bool
<=
#Gambol.function.alwaysinline
<= (s @Self, o @Self) -> Bool
Properties
__ptr
__ptr PointerToVariable[Char]
__len
__len Len