Data.String.CodeUnits
- Package
- strings
- Repository
- purerl/purescript-strings
#stripPrefix Source
stripPrefix :: Pattern -> String -> Maybe StringIf the string starts with the given prefix, return the portion of the string left after removing it, as a Just value. Otherwise, return Nothing.
stripPrefix (Pattern "http:") "http://purescript.org" == Just "//purescript.org"
stripPrefix (Pattern "http:") "https://purescript.org" == Nothing
#stripSuffix Source
stripSuffix :: Pattern -> String -> Maybe StringIf the string ends with the given suffix, return the portion of the
string left after removing it, as a Just value. Otherwise, return
Nothing.
stripSuffix (Pattern ".exe") "psc.exe" == Just "psc"
stripSuffix (Pattern ".exe") "psc" == Nothing
#fromCharArray Source
fromCharArray :: Array Char -> StringConverts an array of characters into a string.
fromCharArray ['H', 'e', 'l', 'l', 'o'] == "Hello"
#toCharArray Source
toCharArray :: String -> Array CharConverts the string into an array of characters.
toCharArray "Hello☺\n" == ['H','e','l','l','o','☺','\n']
#countPrefix Source
countPrefix :: (Char -> Boolean) -> String -> IntReturns the number of contiguous characters at the beginning of the string for which the predicate holds.
countPrefix (_ /= ' ') "Hello World" == 5 -- since length "Hello" == 5
#lastIndexOf Source
lastIndexOf :: Pattern -> String -> Maybe IntReturns the index of the last occurrence of the pattern in the
given string. Returns Nothing if there is no match.
lastIndexOf (Pattern "c") "abcdc" == Just 4
lastIndexOf (Pattern "c") "aaa" == Nothing
#lastIndexOf' Source
lastIndexOf' :: Pattern -> Int -> String -> Maybe IntReturns the index of the last occurrence of the pattern in the given string, starting at the specified index and searching backwards towards the beginning of the string.
Starting at a negative index is equivalent to starting at 0 and starting at an index greater than the string length is equivalent to searching in the whole string.
Returns Nothing if there is no match.
lastIndexOf' (Pattern "a") (-1) "ababa" == Just 0
lastIndexOf' (Pattern "a") 1 "ababa" == Just 0
lastIndexOf' (Pattern "a") 3 "ababa" == Just 2
lastIndexOf' (Pattern "a") 4 "ababa" == Just 4
lastIndexOf' (Pattern "a") 5 "ababa" == Just 4
#slice Source
slice :: Int -> Int -> String -> Maybe StringReturns the substring at indices [begin, end).
If either index is negative, it is normalised to length s - index,
where s is the input string. Nothing is returned if either
index is out of bounds or if begin > end after normalisation.
slice 0 0 "purescript" == Just ""
slice 0 1 "purescript" == Just "p"
slice 3 6 "purescript" == Just "esc"
slice (-4) (-1) "purescript" == Just "rip"
slice (-4) 3 "purescript" == Nothing
#splitAt Source
splitAt :: Int -> String -> { after :: String, before :: String }Splits a string into two substrings, where before contains the
characters up to (but not including) the given index, and after contains
the rest of the string, from that index on.
splitAt 2 "Hello World" == { before: "He", after: "llo World"}
splitAt 10 "Hi" == { before: "Hi", after: ""}
Thus the length of (splitAt i s).before will equal either i or
length s, if that is shorter. (Or if i is negative the length will be
0.)
In code:
length (splitAt i s).before == min (max i 0) (length s)
(splitAt i s).before <> (splitAt i s).after == s
splitAt i s == {before: take i s, after: drop i s}
- Modules
- Data.
Char - Data.
Char. Gen - Data.
String - Data.
String. CaseInsensitive - Data.
String. CodePoints - Data.
String. CodeUnits - Data.
String. Common - Data.
String. Gen - Data.
String. NonEmpty - Data.
String. NonEmpty. CaseInsensitive - Data.
String. NonEmpty. CodePoints - Data.
String. NonEmpty. CodeUnits - Data.
String. NonEmpty. Internal - Data.
String. Pattern - Data.
String. Regex - Data.
String. Regex. Flags - Data.
String. Regex. Unsafe - Data.
String. Unsafe