string¶
Strings in Minilang can contain any sequence of bytes, including 0
bytes.
Index and find methods however work on UTF-8
characters, byte sequences that are not valid UTF-8
are handled gracefully but the results are probably not very useful.
Every string
is also an address
so address methods can also be used to work at the byte level if necessary.
Indexing a string starts at 1
, with the last character at String:length
. Negative indices are counted form the end, -1
is the last character and -String:length
is the first character.
When creating a substring, the first index is inclusive and second index is exclusive. The index 0
refers to just beyond the last character and can be used to take a substring to the end of a string.
fun mlstringbuffercount()
TBD
meth (Arg₁: string::buffer):append(Arg₂: any, Arg₃: function, ...)
TBD
type byte::order < enum
::LittleEndian
::BigEndian
meth (N: integer) * (String: string): string
Returns
String
concatentatedN
times.5 * "abc" :> "abcabcabcabcabc"
meth (Codepoint: integer):char: string
Returns a UTF-8 string containing the character with unicode codepoint
Codepoint
.meth (Codepoint: integer):utf8: string
Returns a UTF-8 string containing the character with unicode codepoint
Codepoint
.type regex < function
A regular expression.
fun regex(String: string): regex | error
Compiles
String
as a regular expression. Returns an error ifString
is not a valid regular expression.regex("[0-9]+") :> /[0-9]+/ regex("[0-9") :> error("RegexError", "Missing ']'")
meth (Arg₁: regex) != (Arg₂: regex): regex | nil
Returns
Arg₂
ifArg₁ != Arg₂
andnil
otherwise.r"[0-9]+" != r"[A-Za-z0-9_]+" :> /[A-Za-z0-9_]+/ r"[A-Za-z0-9_]+" != r"[0-9]+" :> /[0-9]+/ r"[0-9]+" != r"[0-9]+" :> nil
meth (Arg₁: regex) < (Arg₂: regex): regex | nil
Returns
Arg₂
ifArg₁ < Arg₂
andnil
otherwise.r"[0-9]+" < r"[A-Za-z0-9_]+" :> /[A-Za-z0-9_]+/ r"[A-Za-z0-9_]+" < r"[0-9]+" :> nil r"[0-9]+" < r"[0-9]+" :> nil
meth (Arg₁: regex) <= (Arg₂: regex): regex | nil
Returns
Arg₂
ifArg₁ <= Arg₂
andnil
otherwise.r"[0-9]+" <= r"[A-Za-z0-9_]+" :> /[A-Za-z0-9_]+/ r"[A-Za-z0-9_]+" <= r"[0-9]+" :> nil r"[0-9]+" <= r"[0-9]+" :> /[0-9]+/
meth (A: regex) <> (B: regex): integer
Compares
A
andB
lexicographically and returns-1
,0
or1
respectively. Mainly for using regular expressions as keys in maps.r"[0-9]+" <> r"[A-Za-z0-9_]+" :> -1 r"[A-Za-z0-9_]+" <> r"[0-9]+" :> 1 r"[0-9]+" <> r"[0-9]+" :> 0
meth (Arg₁: regex) = (Arg₂: regex): regex | nil
Returns
Arg₂
ifArg₁ = Arg₂
andnil
otherwise.r"[0-9]+" = r"[A-Za-z0-9_]+" :> nil r"[A-Za-z0-9_]+" = r"[0-9]+" :> nil r"[0-9]+" = r"[0-9]+" :> /[0-9]+/
meth (Arg₁: regex) > (Arg₂: regex): regex | nil
Returns
Arg₂
ifArg₁ > Arg₂
andnil
otherwise.r"[0-9]+" > r"[A-Za-z0-9_]+" :> nil r"[A-Za-z0-9_]+" > r"[0-9]+" :> /[0-9]+/ r"[0-9]+" > r"[0-9]+" :> nil
meth (Arg₁: regex) >= (Arg₂: regex): regex | nil
Returns
Arg₂
ifArg₁ >= Arg₂
andnil
otherwise.r"[0-9]+" >= r"[A-Za-z0-9_]+" :> nil r"[A-Za-z0-9_]+" >= r"[0-9]+" :> /[0-9]+/ r"[0-9]+" >= r"[0-9]+" :> /[0-9]+/
meth (Regex: regex):pattern: string
Returns the pattern used to create
Regex
.r"[0-9]+":pattern :> "[0-9]+"
meth (Buffer: string::buffer):append(Value: regex)
Appends a representation of
Value
toBuffer
.type string < address, sequence
A string of characters in UTF-8 encoding.
fun string(Value: any): string
Returns a representation of
Value
as a string.string(100) :> "100" string(nil) :> "nil" string("Hello world!\n") :> "Hello world!\n" string([1, 2, 3]) :> "[1, 2, 3]"
fun regex::escape(String: string): string
Escapes characters in
String
that are treated specially in regular expressions.regex::escape("Word (?)\n") :> "Word \\(\\?\\)\\n"
fun string::escape(String: string): string
Escapes characters in
String
.string::escape("\'Hello\nworld!\'") :> "\\\'Hello\\nworld!\\\'"
meth (Arg₁: string) != (Arg₂: string): string | nil
Returns
Arg₂
ifArg₁ != Arg₂
andnil
otherwise."Hello" != "World" :> "World" "World" != "Hello" :> "Hello" "Hello" != "Hello" :> nil "abcd" != "abc" :> "abc" "abc" != "abcd" :> "abcd"
meth (String: string) !? (Pattern: regex): string | nil
Returns
String
if it does not matchPattern
andnil
otherwise."2022-03-08" !? r"([0-9]+)[/-]([0-9]+)[/-]([0-9]+)" :> nil "Not a date" !? r"([0-9]+)[/-]([0-9]+)[/-]([0-9]+)" :> "Not a date"
meth (String: string) % (Pattern: regex): tuple[string] | nil
Matches
String
withPattern
returning a tuple of the matched components, ornil
if the pattern does not match."2022-03-08" % r"([0-9]+)[/-]([0-9]+)[/-]([0-9]+)" :> (2022-03-08, 2022, 03, 08) "Not a date" % r"([0-9]+)[/-]([0-9]+)[/-]([0-9]+)" :> nil
meth (String: string) */ (Pattern: regex): tuple[string, string]
Splits
String
at the last occurence ofPattern
and returns the two substrings in a tuple."2022/03/08" */ r"[/-]" :> (2022/03, 08) "2022-03-08" */ r"[/-]" :> (2022-03, 08)
meth (String: string) */ (Pattern: string): tuple[string, string]
Splits
String
at the last occurence ofPattern
and returns the two substrings in a tuple."2022/03/08" */ "/" :> (2022/03, 08)
meth (A: string) + (B: string): string
Returns
A
andB
concatentated."Hello" + " " + "world" :> "Hello world"
meth (String: string) / (Pattern: regex): list
Returns a list of substrings from
String
by splitting around occurences ofPattern
. IfPattern
contains subgroups then only the subgroup matches are removed from the output substrings."2022/03/08" / r"[/-]" :> ["2022", "03", "08"] "2022-03-08" / r"[/-]" :> ["2022", "03", "08"]
meth (String: string) / (Pattern: regex, Index: integer): list
Returns a list of substrings from
String
by splitting around occurences ofPattern
. Only theIndex
subgroup matches are removed from the output substrings."<A>-<B>-<C>" / (r">(-)<", 1) :> ["<A>", "<B>", "<C>"]
meth (String: string) / (Pattern: string): list
Returns a list of substrings from
String
by splitting around occurences ofPattern
. Adjacent occurences ofPattern
do not create empty strings."The cat snored as he slept" / " " :> ["The", "cat", "snored", "as", "he", "slept"] "2022/03/08" / "/" :> ["2022", "03", "08"]
meth (String: string) /* (Pattern: regex): tuple[string, string]
Splits
String
at the first occurence ofPattern
and returns the two substrings in a tuple."2022/03/08" /* r"[/-]" :> (2022, 03/08) "2022-03-08" /* r"[/-]" :> (2022, 03-08)
meth (String: string) /* (Pattern: string): tuple[string, string]
Splits
String
at the first occurence ofPattern
and returns the two substrings in a tuple."2022/03/08" /* "/" :> (2022, 03/08)
meth (Arg₁: string) < (Arg₂: string): string | nil
Returns
Arg₂
ifArg₁ < Arg₂
andnil
otherwise."Hello" < "World" :> "World" "World" < "Hello" :> nil "Hello" < "Hello" :> nil "abcd" < "abc" :> nil "abc" < "abcd" :> "abcd"
meth (Arg₁: string) <= (Arg₂: string): string | nil
Returns
Arg₂
ifArg₁ <= Arg₂
andnil
otherwise."Hello" <= "World" :> "World" "World" <= "Hello" :> nil "Hello" <= "Hello" :> "Hello" "abcd" <= "abc" :> nil "abc" <= "abcd" :> "abcd"
meth (A: string) <> (B: string): integer
Compares
A
andB
lexicographically and returns-1
,0
or1
respectively."Hello" <> "World" :> -1 "World" <> "Hello" :> 1 "Hello" <> "Hello" :> 0 "abcd" <> "abc" :> 1 "abc" <> "abcd" :> -1
meth (Arg₁: string) = (Arg₂: string): string | nil
Returns
Arg₂
ifArg₁ = Arg₂
andnil
otherwise."Hello" = "World" :> nil "World" = "Hello" :> nil "Hello" = "Hello" :> "Hello" "abcd" = "abc" :> nil "abc" = "abcd" :> nil
meth (Arg₁: string) > (Arg₂: string): string | nil
Returns
Arg₂
ifArg₁ > Arg₂
andnil
otherwise."Hello" > "World" :> nil "World" > "Hello" :> "Hello" "Hello" > "Hello" :> nil "abcd" > "abc" :> "abc" "abc" > "abcd" :> nil
meth (Arg₁: string) >= (Arg₂: string): string | nil
Returns
Arg₂
ifArg₁ >= Arg₂
andnil
otherwise."Hello" >= "World" :> nil "World" >= "Hello" :> "Hello" "Hello" >= "Hello" :> "Hello" "abcd" >= "abc" :> "abc" "abc" >= "abcd" :> nil
meth (String: string) ? (Pattern: regex): string | nil
Returns
String
if it matchesPattern
andnil
otherwise."2022-03-08" ? r"([0-9]+)[/-]([0-9]+)[/-]([0-9]+)" :> "2022-03-08" "Not a date" ? r"([0-9]+)[/-]([0-9]+)[/-]([0-9]+)" :> nil
meth (String: string)[Interval: integer::interval]: string
Returns the substring of
String
corresponding toInterval
inclusively.meth (String: string)[Index: integer]: string | nil
Returns the substring of
String
of length 1 atIndex
.let S := "λ:😀 → 😺" map(-7 .. 7 => (2, 2 -> S[_])) :> {-7 is "λ", -6 is ":", -5 is "😀", -4 is " ", -3 is "→", -2 is " ", -1 is "😺", 0, 1 is "λ", 2 is ":", 3 is "😀", 4 is " ", 5 is "→", 6 is " ", 7 is "😺"}
meth (String: string)[Start: integer, End: integer]: string | nil
Returns the substring of
String
fromStart
toEnd - 1
inclusively.meth (String: string):after(Delimiter: string): string | nil
Returns the portion of
String
after the 1st occurence ofDelimiter
, ornil
if no occurence if found."2022/03/08":after("/") :> "03/08"
meth (String: string):after(Delimiter: string, N: integer): string | nil
Returns the portion of
String
after theN
-th occurence ofDelimiter
, ornil
if noN
-th occurence if found. IfN < 0
then occurences are counted from the end ofString
."2022/03/08":after("/", 2) :> "08"
meth (String: string):before(Delimiter: string): string | nil
Returns the portion of
String
before the 1st occurence ofDelimiter
, ornil
if no occurence if found."2022/03/08":before("/") :> "2022"
meth (String: string):before(Delimiter: string, N: integer): string | nil
Returns the portion of
String
before theN
-th occurence ofDelimiter
, ornil
if noN
-th occurence if found. IfN < 0
then occurences are counted from the end ofString
."2022/03/08":before("/", 2) :> "2022/03"
meth (Arg₁: string):cname
TBD
meth (String: string):code: integer
Returns the unicode codepoint of the first UTF-8 character of
String
."A":code :> 65 "😀️":code :> 128512
meth (Haystack: string):contains(Pattern: regex): string | nil
Returns the
Haystack
if it containsPattern
ornil
otherwise."The cat snored as he slept":contains(r"[a-z]{3}") :> "The cat snored as he slept" "The cat snored as he slept":contains(r"[0-9]+") :> nil
meth (Haystack: string):contains(Needle: string): string | nil
Returns the
Haystack
if it containsPattern
ornil
otherwise."The cat snored as he slept":contains("cat") :> "The cat snored as he slept" "The cat snored as he slept":contains("dog") :> nil
meth (String: string):count: integer
Returns the number of UTF-8 characters in
String
. Use:size
to get the number of bytes."Hello world":count :> 11 "Hello world":size :> 11 "λ:😀 → 😺":count :> 7 "λ:😀 → 😺":size :> 16
meth (String: string):ctype: string::ctype
Returns the unicode type of the first character of
String
.map("To €2 á\n" => (2, 2 -> :ctype)) :> {"T" is Lu, "o" is Ll, " " is Zs, "€" is Sc, "2" is Nd, "á" is Ll, "\n" is Cc}
meth (String: string):ends(Suffix: string): string | nil
Returns
String
if it ends withSuffix
andnil
otherwise."Hello world":ends("world") :> "Hello world" "Hello world":ends("cake") :> nil
meth (String: string):escape: string
Returns
String
with white space, quotes and backslashes replaced by escape sequences."\t\"Text\"\r\n":escape :> "\\t\\\"Text\\\"\\r\\n"
meth (Haystack: string):find(Pattern: regex): integer | nil
Returns the index of the first occurence of
Pattern
inHaystack
, ornil
if no occurence is found."The cat snored as he slept":find(r"[a-z]{3}") :> 5 "The cat snored as he slept":find(r"[0-9]+") :> nil
meth (Haystack: string):find(Pattern: regex, Start: integer): integer | nil
Returns the index of the first occurence of
Pattern
inHaystack
at or afterStart
, ornil
if no occurence is found."The cat snored as he slept":find(r"s[a-z]+", 1) :> 9 "The cat snored as he slept":find(r"s[a-z]+", 10) :> 22 "The cat snored as he slept":find(r"s[a-z]+", -6) :> 22
meth (Haystack: string):find(Needle: string): integer | nil
Returns the index of the first occurence of
Needle
inHaystack
, ornil
if no occurence is found."The cat snored as he slept":find("cat") :> 5 "The cat snored as he slept":find("dog") :> nil
meth (Haystack: string):find(Needle: string, Start: integer): integer | nil
Returns the index of the first occurence of
Needle
inHaystack
at or afterStart
, ornil
if no occurence is found."The cat snored as he slept":find("s", 1) :> 9 "The cat snored as he slept":find("s", 10) :> 17 "The cat snored as he slept":find("s", -6) :> 22
meth (Haystack: string):find2(Pattern: regex): tuple[integer, string] | nil
Returns
(Index, Match)
whereIndex
is the first occurence ofPattern
inHaystack
, ornil
if no occurence is found."The cat snored as he slept":find2(r"[a-z]{3}") :> (5, cat) "The cat snored as he slept":find2(r"[0-9]+") :> nil
meth (Haystack: string):find2(Pattern: regex, Start: integer): tuple[integer, string] | nil
Returns
(Index, Match)
whereIndex
is the first occurence ofPattern
inHaystack
at or afterStart
, ornil
if no occurence is found."The cat snored as he slept":find2(r"s[a-z]+", 1) :> (9, snored) "The cat snored as he slept":find2(r"s[a-z]+", 10) :> (22, slept) "The cat snored as he slept":find2(r"s[a-z]+", -6) :> (22, slept)
meth (Haystack: string):find2(Pattern: regex, Start: tuple::integer::string): tuple[integer, string] | nil
Returns
(Index, Match)
whereIndex
is the first occurence ofPattern
inHaystack
at or afterStart
, ornil
if no occurence is found."The cat snored as he slept":find2(r"s[a-z]+", 1) :> (9, snored) "The cat snored as he slept":find2(r"s[a-z]+", 10) :> (22, slept) "The cat snored as he slept":find2(r"s[a-z]+", -6) :> (22, slept)
meth (Haystack: string):find2(Needle: string): tuple[integer, string] | nil
Returns
(Index, Needle)
whereIndex
is the first occurence ofNeedle
inHaystack
, ornil
if no occurence is found."The cat snored as he slept":find2("cat") :> (5, cat) "The cat snored as he slept":find2("dog") :> nil
meth (Haystack: string):find2(Needle: string, Start: integer): tuple[integer, string] | nil
Returns
(Index, Needle)
whereIndex
is the first occurence ofNeedle
inHaystack
at or afterStart
, ornil
if no occurence is found."The cat snored as he slept":find2("s", 1) :> (9, s) "The cat snored as he slept":find2("s", 10) :> (17, s) "The cat snored as he slept":find2("s", -6) :> (22, s)
meth (Haystack: string):find2(Needle: string, Start: tuple::integer::string): tuple[integer, string] | nil
Returns
(Index, Needle)
whereIndex
is the first occurence ofNeedle
inHaystack
at or afterStart
, ornil
if no occurence is found."The cat snored as he slept":find2("s", 1) :> (9, s) "The cat snored as he slept":find2("s", 10) :> (17, s) "The cat snored as he slept":find2("s", -6) :> (22, s)
meth (String: string):length: integer
Returns the number of UTF-8 characters in
String
. Use:size
to get the number of bytes."Hello world":length :> 11 "Hello world":size :> 11 "λ:😀 → 😺":length :> 7 "λ:😀 → 😺":size :> 16
meth (String: string):limit(Length: integer): string
Returns the prefix of
String
limited toLength
."Hello world":limit(5) :> "Hello" "Cake":limit(5) :> "Cake"
meth (String: string):lower: string
Returns
String
with each character converted to lower case."Hello World":lower :> "hello world"
meth (String: string):ltrim: string
Returns a copy of
String
with characters inChars
removed from the start." \t Hello \n":ltrim :> "Hello \n"
meth (String: string):ltrim(Chars: string): string
Returns a copy of
String
with characters inChars
removed from the start." \t Hello \n":trim(" \n") :> "\t Hello"
meth (A: string):max(B: string): integer
Returns
max(A, B)
"Hello":max("World") :> "World" "World":max("Hello") :> "World" "abcd":max("abc") :> "abcd" "abc":max("abcd") :> "abcd"
meth (A: string):min(B: string): integer
Returns
min(A, B)
"Hello":min("World") :> "Hello" "World":min("Hello") :> "Hello" "abcd":min("abc") :> "abc" "abc":min("abcd") :> "abc"
meth (String: string):normalize(Norm: string::norm): string
Returns a normalized copy of
String
using the normalizer specified byNorm
.let S := "𝕥𝕖𝕩𝕥" :> "𝕥𝕖𝕩𝕥" S:normalize(string::norm::NFD) :> "𝕥𝕖𝕩𝕥"
meth (String: string):offset(Index: integer): integer
Returns the byte position of the
Index
-th character ofString
.let S := "λ:😀 → 😺" list(1 .. S:length, S:offset(_)) :> [0, 2, 3, 7, 8, 11, 12]
meth (String: string):precount: integer
Returns the number of UTF-8 characters in
String
. Use:size
to get the number of bytes."Hello world":count :> 11 "Hello world":size :> 11 "λ:😀 → 😺":count :> 7 "λ:😀 → 😺":size :> 16
meth (String: string):replace(I: integer, Fn: function): string
Returns a copy of
String
with theString[I]
is replaced byFn(String[I])
."hello world":replace(1, :upper) :> "Hello world"
meth (String: string):replace(I: integer, Fn: integer, Arg₄: function): string
Returns a copy of
String
with theString[I, J]
is replaced byFn(String[I, J])
."hello world":replace(1, 6, :upper) :> "HELLO world"
meth (String: string):replace(I: integer, J: integer, Replacement: string): string
Returns a copy of
String
with theString[I, J]
is replaced byReplacement
."Hello world":replace(1, 6, "Goodbye") :> "Goodbye world" "Hello world":replace(-6, 0, ", how are you?") :> "Hello, how are you?"
meth (String: string):replace(I: integer, Replacement: string): string
Returns a copy of
String
with theString[I]
is replaced byReplacement
."Hello world":replace(6, "_") :> "Hello_world"
meth (String: string):replace(Replacements: map): string
Each key in
Replacements
can be either a string or a regex. Each value inReplacements
can be either a string or a function. Returns a copy ofString
with each matching string or regex fromReplacements
replaced with the corresponding value. Functions are called with the matched string or regex subpatterns."the dog snored as he slept":replace({ r" ([a-z])" is fun(Match, A) '-{A:upper}', "nor" is "narl" }) :> "the-Dog-Snarled-As-He-Slept"
meth (String: string):replace(Pattern: regex, Fn: function): string
Returns a copy of
String
with each occurence ofPattern
replaced byFn(Match, Sub₁, ..., Subₙ)
whereMatch
is the actual matched text andSubᵢ
are the matched subpatterns."the cat snored as he slept":replace(r" ([a-z])", fun(Match, A) '-{A:upper}') :> "the-Cat-Snored-As-He-Slept"
meth (String: string):replace(Pattern: regex, Replacement: string): string
Returns a copy of
String
with each occurence ofPattern
replaced byReplacement
."Hello world":replace(r"l+", "bb") :> "Hebbo worbbd"
meth (String: string):replace(Pattern: string, Replacement: string): string
Returns a copy of
String
with each occurence ofPattern
replaced byReplacement
."Hello world":replace("l", "bb") :> "Hebbbbo worbbd"
meth (String: string):replace2(Replacements: map): string
Each key in
Replacements
can be either a string or a regex. Each value inReplacements
can be either a string or a function. Returns a copy ofString
with each matching string or regex fromReplacements
replaced with the corresponding value. Functions are called with the matched string or regex subpatterns."the dog snored as he slept":replace2({ r" ([a-z])" is fun(Match, A) '-{A:upper}', "nor" is "narl" }) :> (the-Dog-Snarled-As-He-Slept, 6)
meth (String: string):replace2(Pattern: regex, Replacement: string): string
Returns a copy of
String
with each occurence ofPattern
replaced byReplacement
."Hello world":replace2(r"l+", "bb") :> (Hebbo worbbd, 2)
meth (String: string):replace2(Pattern: string, Replacement: string): string
Returns a copy of
String
with each occurence ofPattern
replaced byReplacement
."Hello world":replace2("l", "bb") :> (Hebbbbo worbbd, 3)
meth (String: string):reverse: string
Returns a string with the characters in
String
reversed."Hello world":reverse :> "dlrow olleH"
meth (String: string):rtrim: string
Returns a copy of
String
with characters inChars
removed from the end." \t Hello \n":rtrim :> " \t Hello"
meth (String: string):rtrim(Chars: string): string
Returns a copy of
String
with characters inChars
removed from the end." \t Hello \n":rtrim(" \n") :> " \t Hello"
meth (String: string):starts(Pattern: regex): string | nil
Returns
String
if it starts withPattern
andnil
otherwise."Hello world":starts(r"[A-Z]") :> "Hello world" "Hello world":starts(r"[0-9]") :> nil
meth (String: string):starts(Prefix: string): string | nil
Returns
String
if it starts withPrefix
andnil
otherwise."Hello world":starts("Hello") :> "Hello world" "Hello world":starts("cake") :> nil
meth (String: string):title: string
Returns
String
with the first character and each character after whitespace converted to upper case and each other case converted to lower case."hello world":title :> "Hello World" "HELLO WORLD":title :> "Hello World"
meth (String: string):trim: string
Returns a copy of
String
with whitespace removed from both ends." \t Hello \n":trim :> "Hello"
meth (String: string):trim(Chars: string): string
Returns a copy of
String
with characters inChars
removed from both ends." \t Hello \n":trim(" \n") :> "\t Hello"
meth (String: string):upper: string
Returns
String
with each character converted to upper case."Hello World":upper :> "HELLO WORLD"
meth (Arg₁: string):utf8
TBD
meth (A: string) ~ (B: string): integer
Returns the edit distance between
A
andB
."cake" ~ "cat" :> 2 "yell" ~ "hello" :> 2 "say" ~ "goodbye" :> 6 "goodbye" ~ "say" :> 6 "λ:😀 → Y" ~ "λ:X → 😺" :> 2
meth (A: string) ~> (B: string): integer
Returns an asymmetric edit distance from
A
toB
."cake" ~> "cat" :> 1 "yell" ~> "hello" :> 2 "say" ~> "goodbye" :> 6 "goodbye" ~> "say" :> 3 "λ:😀 → Y" ~> "λ:X → 😺" :> 4
meth (Buffer: string::buffer):append(Value: string)
Appends
Value
toBuffer
.meth (Arg₁: string::buffer):append(Arg₂: string, Arg₃: string)
TBD
type string::buffer < stream
A string buffer that automatically grows and shrinks as required.
type string::buffer
A string buffer that automatically grows and shrinks as required.
fun string::buffer(): string::buffer
Returns a new
string::buffer
meth (Buffer: string::buffer):get: string
Returns the contents of
Buffer
as a string and clearsBuffer
. .. deprecated:: 2.5.0Use
Buffer:rest
instead.let B := string::buffer() B:write("Hello world") B:get :> "Hello world" B:get :> ""
meth (Arg₁: string::buffer):grow(Arg₂: sequence)
TBD
meth (Buffer: string::buffer):length: integer
Returns the number of bytes currently available in
Buffer
.let B := string::buffer() B:write("Hello world") B:length :> 11
meth (Buffer: string::buffer):rest: string
Returns the contents of
Buffer
as a string and clearsBuffer
.let B := string::buffer() B:write("Hello world") B:rest :> "Hello world" B:rest :> ""
meth (Buffer: string::buffer):write(Value₁, : any, ...): integer
Writes each
Valueᵢ
in turn toBuffer
.let B := string::buffer() B:write("1 + 1 = ", 1 + 1) B:rest :> "1 + 1 = 2"
type string::ctype < enum
::Cn
- General Other Types::Lu
- Uppercase Letter::Ll
- Lowercase Letter::Lt
- Titlecase Letter::Lm
- Modifier Letter::Lo
- Other Letter::Mn
- Non Spacing Mark::Me
- Enclosing Mark::Mc
- Combining Spacing Mark::Nd
- Decimal Digit Number::Nl
- Letter Number::No
- Other Number::Zs
- Space Separator::Zl
- Line Separator::Zp
- Paragraph Separator::Cc
- Control Char::Cf
- Format Char::Co
- Private Use Char::Cs
- Surrogate::Pd
- Dash Punctuation::Ps
- Start Punctuation::Pe
- End Punctuation::Pc
- Connector Punctuation::Po
- Other Punctuation::Sm
- Math Symbol::Sc
- Currency Symbol::Sk
- Modifier Symbol::So
- Other Symbol::Pi
- Initial Punctuation::Pf
- Final Punctuation
type string::norm < enum
::NFC
::NFD
::NFKC
::NFKD
fun string::switch(Cases: string|regex, ...)
Implements
switch
for string values. Case values must be strings or regular expressions.for Pet in ["cat", "dog", "mouse", "fox"] do switch Pet: string case "cat" do print("Meow!\n") case "dog" do print("Woof!\n") case "mouse" do print("Squeak!\n") else print("???!") end end :> nil
Meow! Woof! Squeak! ???!
meth (Arg₁: visitor):const(Arg₂: buffer)
TBD
meth (Arg₁: visitor):copy(Arg₂: buffer)
TBD