String
Definitions
def
abbreviateLeft
(
w :
Int32
s :
String
)
: String
\ Pure
Abbreviate the string s if it exceeds the width w.
If the length of s exceeds w and w >= 3 then s is truncated and the first
three characters are replaced with ellipses.
If the length of s exceeds w and w < 3 then the empty string is returned.
def
abbreviateRight
(
w :
Int32
s :
String
)
: String
\ Pure
Abbreviate the string s if it exceeds the width w.
If the length of s exceeds w and w >= 3 then s is truncated and the last
three characters are replaced with ellipses.
If the length of s exceeds w and w < 3 then the empty string is returned.
def
breakOnLeft
(
substr :
{ substr = String }
s :
String
)
: (String, String)
\ Pure
Find the first instance of substr in string s, return a pair of the
prefix of string s up to substr and the rest of string s including substr.
def
breakOnRight
(
substr :
{ substr = String }
s :
String
)
: (String, String)
\ Pure
Find the last instance of substr in string s, return a pair of the
initial string including substr and suffix from substr.
def
center
(
w :
Int32
c :
Char
s :
String
)
: String
\ Pure
Center the string s by padding with the supplied char c on both sides to fit the width w.
If the length of the string exceeds the given width, the string will be returned unchanged.
Requiring an uneven number of spaces, the string will be left biased,
e.g String.center(4, '_', "a") -> "_a__".
def
charAt
(
i :
Int32
s :
String
)
: Char
\ Pure
def
codePointAt
(
i :
Int32
s :
String
)
: Int32
\ Pure
Returns the code point at position i in the string s.
def
commonPrefix
(
s1 :
String
s2 :
String
)
: String
\ Pure
Return the common prefix of strings s1 and s2.
Returns the empty string if s1 and s2 do not share a common prefix.
def
commonSuffix
(
s1 :
String
s2 :
String
)
: String
\ Pure
Return the common suffix of strings s1 and s2.
Returns the empty string if s1 and s2 do not share a common suffix.
def
concat
(
s1 :
String
s2 :
String
)
: String
\ Pure
Returns the string s1 followed by the string s2.
def
contains
(
substr :
{ substr = String }
s :
String
)
: Bool
\ Pure
Returns true if and only if substr is an infix of s.
def
countSubstring
(
substr :
{ substr = String }
s :
String
)
: Int32
\ Pure
Count the occurrences of substr in string s.
def
drop
(
n :
Int32
s :
String
)
: String
\ Pure
Alias for dropLeft.
def
dropLeft
(
n :
Int32
s :
String
)
: String
\ Pure
Drop the first n characters of string s from the left.
If n extends past the end of string s, return the empty string.
def
dropRight
(
n :
Int32
s :
String
)
: String
\ Pure
Drop the last n characters of string s from the right.
If n is greater than the length of string s, return the empty string.
def
dropWhile
(
f :
Char -> Bool
s :
String
)
: String
\ Pure
Alias for dropWhileLeft.
def
dropWhileAround
(
f :
Char -> Bool
s :
String
)
: String
\ Pure
Returns the middle of string s after dropping all the characters
from both ends that satisfy the predicate f.
The function f must be pure.
def
dropWhileLeft
(
f :
Char -> Bool
s :
String
)
: String
\ Pure
Returns the tail of string s after dropping all the initial chars
that satisfy the predicate f.
The function f must be pure.
def
dropWhileRight
(
f :
Char -> Bool
s :
String
)
: String
\ Pure
Returns the front of string s after dropping all the characters
from the right end that satisfy the predicate f.
The function f must be pure.
def
endsWith
(
suffix :
{ suffix = String }
s :
String
)
: Bool
\ Pure
Returns true if the string s ends with the string suffix.
def
enumerator
[r]
(
rc :
Region[r]
s :
String
)
: Iterator[(Int32, Char), r, r]
\ r
Returns an iterator over l zipped with the indices of the elements.
def
exists
[ef]
(
f :
Char -> Bool \ ef
s :
String
)
: Bool
\ ef
Returns true if and only if at least one char in s satisfies the predicate f.
Returns false if a is empty.
def
findIndexOfLeft
[ef]
(
f :
Char -> Bool \ ef
s :
String
)
: Option[Int32]
\ ef
Optionally returns the position of the first character in x satisfying f.
Returns None if no character in s satisfies f.
def
findIndexOfRight
(
f :
Char -> Bool
s :
String
)
: Option[Int32]
\ Pure
Optionally return the position of the first character in s satisfying f, reading right to left.
If nothing satisfies f return None.
def
findIndices
(
f :
Char -> Bool
s :
String
)
: List[Int32]
\ Pure
Returns the positions of the all the elements in s satisfying f.
The function f must be pure.
def
flatten
(
xs :
List[String]
)
: String
\ Pure
Concatenate a list of strings into a single string.
def
foldLeft
[bef]
(
f :
b -> (Char -> b \ ef)
x :
b
s :
String
)
: b
\ ef
Applies f to a start value x and all elements in s going from left to right.
def
foldLeft2
[bef]
(
f :
b -> (Char -> (Char -> b \ ef))
x :
b
s :
String
t :
String
)
: b
\ ef
Accumulates the result of applying f pairwise to the elements of s and t
starting with the initial value x and going from left to right.
def
foldRight
[bef]
(
f :
Char -> (b -> b \ ef)
x :
b
s :
String
)
: b
\ ef
Applies f to a start value x and all elements in s` going from right to left.
def
foldRight2
[bef]
(
f :
Char -> (Char -> (b -> b \ ef))
x :
b
s :
String
t :
String
)
: b
\ ef
Accumulates the result of applying f pairwise to the elements of s and t
starting with the initial value x and going from right to left.
def
forAll
[ef]
(
f :
Char -> Bool \ ef
s :
String
)
: Bool
\ ef
Returns true if and only if all chars in s satisfy the predicate f.
Returns true if s is empty.
def
indent
(
n :
Int32
s :
String
)
: String
\ Pure
Indent every line in string s by n spaces. n must be greater than 0.
If the string s in nonempty, the returned string normalizes line
termination characters and adds a line terminator to the last line
of the string if it does not already end with a newline.
If the string s is empty, then the empty string is returned.
def
indexOf
(
substr :
{ substr = String }
s :
String
)
: Option[Int32]
\ Pure
Alias for indexOfLeft.
def
indexOfLeft
(
substr :
{ substr = String }
s :
String
)
: Option[Int32]
\ Pure
Return the index of the first occurrence of substr in s from the left.
If substr is not present in s return None.
If substr is the empty string return None.
def
indexOfLeftWithOffset
(
substr :
{ substr = String }
offset :
{ offset = Int32 }
s :
String
)
: Option[Int32]
\ Pure
This is indexOfLeft with a start offset.
Returns None if substr is the empty string.
def
indexOfRight
(
substr :
{ substr = String }
s :
String
)
: Option[Int32]
\ Pure
Return the index of the first occurrence of substr in s from the right.
If substr is not present in s return None.
If substr is the empty string return None.
def
indexOfRightWithOffset
(
substr :
{ substr = String }
offset :
{ offset = Int32 }
s :
String
)
: Option[Int32]
\ Pure
This is indexOfRight with a start offset.
Returns None if substr is the empty string.
def
indices
(
substr :
{ substr = String }
s :
String
)
: List[Int32]
\ Pure
Returns the positions of the all the occurrences of substr in s.
Returns Nil if substr is the empty string.
def
init
[ef]
(
f :
Int32 -> Char \ ef
len :
Int32
)
: String
\ ef
Build a string of length len by applying f to the successive indices.
def
intercalate
(
sep :
String
xs :
List[String]
)
: String
\ Pure
Concatenate a list of strings into a single string, inserting the separator sep between
each pair of strings.
def
intercalateChar
(
sep :
Char
xs :
List[String]
)
: String
\ Pure
Concatenate a list of strings into a single string, inserting the separator sep between
each pair of strings.
def
isAscii
(
s :
String
)
: Bool
\ Pure
Returns true if and only if all chars in s are ascii characters.
Returns true if s is empty.
def
isEmpty
(
s :
String
)
: Bool
\ Pure
Returns true if the string s is the empty string.
def
isMatch
(
regex :
{ regex = String }
s :
String
)
: Bool
\ Pure
Returns true if the entire string s is matched by the regular expression regex.
Note - use isSubmatch to search for a substring.
def
isSubmatch
(
regex :
{ regex = String }
s :
String
)
: Bool
\ Pure
Returns true if the string s is matched by the regular expression regex at any point.
def
isWhiteSpace
(
s :
String
)
: Bool
\ Pure
Returns true if and only if all chars in s are white space characters.
Returns true if s is empty.
def
iterator
[r]
(
rc :
Region[r]
s :
String
)
: Iterator[Char, r, r]
\ r
Returns an iterator over s.
def
length
(
s :
String
)
: Int32
\ Pure
Returns the length of the string s.
def
levenshteinDistance
(
s :
String
t :
String
)
: Int32
\ Pure
Calculate the Levenshtein distance between the strings s and t.
The answer is the number deletions, insertions or substitutions needed to turn
string s into string t.
def
lineSeparator
: String
\ Pure
Get the system line separator.
def
lines
(
s :
String
)
: List[String]
\ Pure
Split the string s into an array of lines, breaking on newline.
Newline is recognized as any Unicode linebreak sequence including Windows (carriage return, line feed) or Unix (line feed).
def
map
[ef]
(
f :
Char -> Char \ ef
s :
String
)
: String
\ ef
Returns the result of applying f to every character in s.
def
mapWithIndex
[ef]
(
f :
Int32 -> (Char -> Char \ ef)
s :
String
)
: String
\ ef
Returns the result of applying f to every character in s along with that character's index.
def
nth
(
i :
Int32
s :
String
)
: Option[Char]
\ Pure
Optionally return the character at position i in the string s.
def
nthCodePoint
(
i :
Int32
s :
String
)
: Option[Int32]
\ Pure
Optionally returns the code point at position i in the string s.
def
padLeft
(
w :
Int32
c :
Char
s :
String
)
: String
\ Pure
Pad the string s at the left with the supplied char c to fit the width w.
def
padRight
(
w :
Int32
c :
Char
s :
String
)
: String
\ Pure
Pad the string s at the right with the supplied char c to fit the width w.
def
patch
(
i :
Int32
n :
Int32
sub :
String
s :
String
)
: String
\ Pure
Returns s with the n elements starting at index i replaced with the elements of sub.
If any of the indices i, i+1, i+2, ... , i+n-1 are out of range in s then no patching is done at these indices.
If s becomes depleted then no further patching is done.
If patching occurs at index i+j in s, then the element at index j in sub is used.
def
repeat
(
n :
Int32
s :
String
)
: String
\ Pure
Returns a string with the string s repeated n times.
Returns the empty string if n < 0.
def
replace
(
from :
{ from = String }
to :
{ to = String }
s :
String
)
: String
\ Pure
Returns s with every match of the substring from replaced by the string to.
def
replaceChar
(
from :
{ from = Char }
to :
{ to = Char }
s :
String
)
: String
\ Pure
Returns s with every match of the character target replaced by the character rep.
def
replaceFirstMatch
(
regex :
{ regex = String }
to :
{ to = String }
s :
String
)
: String
\ Pure
Returns s with the first match of the regular expression regex replaced by the string to.
def
replaceMatches
(
regex :
{ regex = String }
to :
{ to = String }
s :
String
)
: String
\ Pure
Returns s with every match of the regular expression regex replaced by the string to.
def
reverse
(
s :
String
)
: String
\ Pure
Returns the reverse of s.
def
rotateLeft
(
n :
Int32
s :
String
)
: String
\ Pure
Rotate the contents of string s by n steps to the left.
def
rotateRight
(
n :
Int32
s :
String
)
: String
\ Pure
Rotate the contents of string s by n steps to the right.
def
slice
(
start :
{ start = Int32 }
end :
{ end = Int32 }
s :
String
)
: String
\ Pure
Returns the substring of s from index b (inclusive) to index e (exclusive).
If b or e are out-of-bounds, return the empty string.
def
sliceLeft
(
end :
{ end = Int32 }
s :
String
)
: String
\ Pure
Get the substring of s to the left of index end (exclusive).
sliceLeft == slice(0 , e, s)
def
sliceRight
(
start :
{ start = Int32 }
s :
String
)
: String
\ Pure
Get the substring of s to the right starting at index start (inclusive).
sliceRight == slice(start , length(s), s)
def
split
(
regex :
{ regex = String }
s :
String
)
: List[String]
\ Pure
Splits the string s around matches of the regular expression regex.
def
splitAt
(
n :
Int32
s :
String
)
: (String, String)
\ Pure
Split the string s at the position n returning the left and
right (inclusive n) parts.
If n exceeds the length of string s, return the whole string
paired with the empty string. Symmetrically for n less than 0.
def
splitOn
(
substr :
{ substr = String }
s :
String
)
: List[String]
\ Pure
Split the string s on matches of substr.
def
startsWith
(
prefix :
{ prefix = String }
s :
String
)
: Bool
\ Pure
Returns true if the string s starts with the string prefix.
def
stripIndent
(
n :
Int32
s :
String
)
: String
\ Pure
Strip every indented line in string s by n spaces. n must be greater than 0.
Note, tabs are counted as a single space.
If the string s in nonempty, the returned string normalizes line
termination characters and adds a line terminator to the last line
of the string if it does not already end with a newline.
If the string s is empty, then the empty string is returned.
def
stripMargin
(
s :
String
)
: String
\ Pure
For every line in string s, strip a leading prefix consisting of
blanks or control characters followed by | from the line, if
such a prefix exists.
def
stripMarginWith
(
margin :
{ margin = String }
s :
String
)
: String
\ Pure
For every line in string s, strip a leading prefix consisting of
blanks or control characters followed by margin from the line, if
such a prefix exists.
def
stripPrefix
(
substr :
{ substr = String }
s :
String
)
: Option[String]
\ Pure
Returns Some(suffix) of string s if its prefix matches substr.
def
stripSuffix
(
substr :
{ substr = String }
s :
String
)
: Option[String]
\ Pure
Returns Some(prefix) of string s if its suffix matches substr.
def
take
(
n :
Int32
s :
String
)
: String
\ Pure
Alias for takeLeft.
def
takeLeft
(
n :
Int32
s :
String
)
: String
\ Pure
Take the first n characters of string s from the left.
If n extends past the end of string s, return all the characters
of s.
def
takeRight
(
n :
Int32
s :
String
)
: String
\ Pure
Take the last n characters of string s from the right.
If n is greater than the length of string s, return all the characters
of s.
def
takeWhile
(
f :
Char -> Bool
s :
String
)
: String
\ Pure
Alias for takeWileLeft.
def
takeWhileLeft
(
f :
Char -> Bool
s :
String
)
: String
\ Pure
Returns the initial prefix of string s where all the chars satisfy
the predicate f.
The function f must be pure.
def
takeWhileRight
(
f :
Char -> Bool
s :
String
)
: String
\ Pure
Returns the suffix of string s where all the characters satisfy
the predicate f.
The function f must be pure.
def
toArray
[r]
(
rc :
Region[r]
s :
String
)
: Array[Char, r]
\ r
Returns the given string s as an array of characters.
def
toChunks
(
k :
Int32
s :
String
)
: List[String]
\ Pure
Split the string s into chunks of length k, the last chunk may be smaller than k.
k should be greater than 0.
def
toList
(
s :
String
)
: List[Char]
\ Pure
Returns the given string s as a list of characters.
def
toLowerCase
(
s :
String
)
: String
\ Pure
Returns the lower case version of the string s.
def
toRegex
(
regex :
String
)
: Result[String, Regex]
\ Pure
Compile the regular expression regex into a Regex object (internally
a Regex is java.util.regex.Pattern).
Returns Err if the regex is ill-formed and cannot be compiled.
The syntax of regular expressions is the same as Java, see the JDK Javadocs
of the class util.regex.Pattern for reference.
Warning: It is strongly recommended to use a Regex literal instead of toRegex.
Regex literals are checked at compile time.
def
toRegexWithFlags
(
flags :
Set[Flag]
regex :
String
)
: Result[String, Regex]
\ Pure
Compile the regular expression regex into a Regex with the supplied flags.
Returns Err if the regex is ill-formed and cannot be compiled.
Warning: It is strongly recommended to use a Regex literal instead of toRegexWithFlags.
Regex literals are checked at compile time. See the JDK documentation of
java.util.regex.Pattern for guidance on enabling flags with embedded flag expressions.
def
toUpperCase
(
s :
String
)
: String
\ Pure
Returns the upper case version of the string s.
def
toVector
(
s :
String
)
: Vector[Char]
\ Pure
Returns the given string s as a vector of characters.
def
trim
(
s :
String
)
: String
\ Pure
Returns a copy of the string s without trailing and leading whitespaces.
Returns a new empty string if there is no characters in s.
def
trimLeft
(
s :
String
)
: String
\ Pure
Returns string s with all leading space characters removed.
def
trimRight
(
s :
String
)
: String
\ Pure
Returns string s with all trailing space characters removed.
def
unfold
[bef]
(
f :
b -> Option[(Char, b)] \ ef
x :
b
)
: String
\ ef
Build a string from the seed value x applying the function f until f returns None.
def
unfoldString
[bef]
(
f :
b -> Option[(String, b)] \ ef
x :
b
)
: String
\ ef
Build a string from the seed value x applying the function f until f returns None.
This is a version of unfold where f generates substrings rather than chars.
def
unfoldStringWithIter
[ef]
(
f :
Unit -> Option[String] \ ef
)
: String
\ ef
Build a string by applying the function next to (). next is expected to encapsulate
a stateful resource such as a file handle that can be iterated.
next should return Some(s) to signal a new substring s.
next should return None to signal the end of building the string.
def
unfoldWithIter
[ef]
(
f :
Unit -> Option[Char] \ ef
)
: String
\ ef
Build a string by applying the function next to (). next is expected to encapsulate
a stateful resource such as a file handle that can be iterated.
next should return Some(c) to signal a new char c.
next should return None to signal the end of building the string.
def
unlines
(
a :
List[String]
)
: String
\ Pure
Join the list of strings a separating each pair of strings and
ending the result string with the system dependent line separator.
def
unwords
(
l :
List[String]
)
: String
\ Pure
Join the array of strings l separating each pair of strings with a
single space character.
def
unwrap
(
s :
String
)
: String
\ Pure
Unwrap the string, replacing every newline with a space
def
update
(
i :
Int32
a :
Char
s :
String
)
: String
\ Pure
Returns s with the element at index i replaced by a.
Returns s if i < 0 or i > length(xs)-1.
def
words
(
s :
String
)
: List[String]
\ Pure
Split the string s into an list of words, dividing on one or more white space characters.
Leading and trailing spaces are trimmed.
def
wrap
(
w :
Int32
s :
String
)
: String
\ Pure
Wrap the string s into lines that are each at most as long as w, breaking on whitespace.
If a line contains a single word that exceeds the length of w, the word will be broken.
def
zip
(
a :
String
b :
String
)
: List[(Char, Char)]
\ Pure
Returns an array where the element at index i is (x, y) where
x is the element at index i in a and y is the element at index i in b.
If either a or b becomes depleted, then no further elements are added to the resulting array.
def
zipWith
[ef]
(
f :
Char -> (Char -> Char \ ef)
a :
String
b :
String
)
: String
\ ef
Returns a string where the element at index i is f(x, y) where
x is the element at index i in a and y is the element at index i in b.
If either a or b becomes depleted, then no further elements are added to the resulting array.