Skip to main content

DA.Text

Functions for working with Text.

Module Snapshot

Lifecycle

Stable.

Notices

Status: active Introduced in: 3.4.9 Removed in: - Warnings: 0 Deprecations: 0 Deprecated since: -

Functions

explode

explode : Text -> [Text]

implode

implode : [Text] -> Text

isEmpty

isEmpty : Text -> Bool Test for emptiness.

isNotEmpty

isNotEmpty : Text -> Bool Test for non-emptiness.

length

length : Text -> Int Compute the number of symbols in the text.

trim

trim : Text -> Text Remove spaces from either side of the given text.

replace

replace : Text -> Text -> Text -> Text Replace a subsequence everywhere it occurs. The first argument must not be empty.

lines

lines : Text -> [Text] Breaks a Text value up into a list of Text’s at newline symbols. The resulting texts do not contain newline symbols.

unlines

unlines : [Text] -> Text Joins lines, after appending a terminating newline to each.

words

words : Text -> [Text] Breaks a ‘Text’ up into a list of words, delimited by symbols representing white space.

unwords

unwords : [Text] -> Text Joins words using single space symbols.

linesBy

linesBy : (Text -> Bool) -> Text -> [Text] A variant of lines with a custom test. In particular, if there is a trailing separator it will be discarded.

wordsBy

wordsBy : (Text -> Bool) -> Text -> [Text] A variant of words with a custom test. In particular, adjacent separators are discarded, as are leading or trailing separators.

intercalate

intercalate : Text -> [Text] -> Text intercalate inserts the text argument t in between the items in ts and concatenates the result.

dropPrefix

dropPrefix : Text -> Text -> Text dropPrefix drops the given prefix from the argument. It returns the original text if the text doesn’t start with the given prefix.

dropSuffix

dropSuffix : Text -> Text -> Text Drops the given suffix from the argument. It returns the original text if the text doesn’t end with the given suffix. Examples:

stripSuffix

stripSuffix : Text -> Text -> Optional Text Return the prefix of the second text if its suffix matches the entire first text. Examples:

stripPrefix

stripPrefix : Text -> Text -> Optional Text The stripPrefix function drops the given prefix from the argument text. It returns None if the text did not start with the prefix.

isPrefixOf

isPrefixOf : Text -> Text -> Bool The isPrefixOf function takes two text arguments and returns True if and only if the first is a prefix of the second.

isSuffixOf

isSuffixOf : Text -> Text -> Bool The isSuffixOf function takes two text arguments and returns True if and only if the first is a suffix of the second.

isInfixOf

isInfixOf : Text -> Text -> Bool The isInfixOf function takes two text arguments and returns True if and only if the first is contained, wholly and intact, anywhere within the second.

takeWhile

takeWhile : (Text -> Bool) -> Text -> Text The function takeWhile, applied to a predicate p and a text, returns the longest prefix (possibly empty) of symbols that satisfy p.

takeWhileEnd

takeWhileEnd : (Text -> Bool) -> Text -> Text The function ‘takeWhileEnd’, applied to a predicate p and a ‘Text’, returns the longest suffix (possibly empty) of elements that satisfy p.

dropWhile

dropWhile : (Text -> Bool) -> Text -> Text dropWhile p t returns the suffix remaining after takeWhile p t.

dropWhileEnd

dropWhileEnd : (Text -> Bool) -> Text -> Text dropWhileEnd p t returns the prefix remaining after dropping symbols that satisfy the predicate p from the end of t.

splitOn

splitOn : Text -> Text -> [Text] Break a text into pieces separated by the first text argument (which cannot be empty), consuming the delimiter.

splitAt

splitAt : Int -> Text -> (Text, Text) Split a text before a given position so that for 0 <= n <= length t, length (fst (splitAt n t)) == n.

take

take : Int -> Text -> Text take n, applied to a text t, returns the prefix of t of length n, or t itself if n is greater than the length of t.

drop

drop : Int -> Text -> Text drop n, applied to a text t, returns the suffix of t after the first n characters, or the empty Text if n is greater than the length of t.

substring

substring : Int -> Int -> Text -> Text Compute the sequence of symbols of length l in the argument text starting at s.

isPred

isPred : (Text -> Bool) -> Text -> Bool isPred f t returns True if t is not empty and f is True for all symbols in t.

isSpace

isSpace : Text -> Bool isSpace t is True if t is not empty and consists only of spaces.

isNewLine

isNewLine : Text -> Bool isSpace t is True if t is not empty and consists only of newlines.

isUpper

isUpper : Text -> Bool isUpper t is True if t is not empty and consists only of uppercase symbols.

isLower

isLower : Text -> Bool isLower t is True if t is not empty and consists only of lowercase symbols.

isDigit

isDigit : Text -> Bool isDigit t is True if t is not empty and consists only of digit symbols.

isAlpha

isAlpha : Text -> Bool isAlpha t is True if t is not empty and consists only of alphabet symbols.

isAlphaNum

isAlphaNum : Text -> Bool isAlphaNum t is True if t is not empty and consists only of alphanumeric symbols.

parseInt

parseInt : Text -> Optional Int Attempt to parse an Int value from a given Text.

parseNumeric

parseNumeric : NumericScale n => Text -> Optional (Numeric n) Attempt to parse a Numeric value from a given Text. To get Some value, the text must follow the regex (-|\+)?[0-9]+(\.[0-9]+)? In particular, the shorthands ".12" and "12." do not work, but the value can be prefixed with +. Leading and trailing zeros are fine, however spaces are not. Examples:

parseDecimal

parseDecimal : Text -> Optional Decimal Attempt to parse a Decimal value from a given Text. To get Some value, the text must follow the regex (-|\+)?[0-9]+(\.[0-9]+)? In particular, the shorthands ".12" and "12." do not work, but the value can be prefixed with +. Leading and trailing zeros are fine, however spaces are not. Examples:

sha256

sha256 : Text -> Text Computes the SHA256 hash of the UTF8 bytes of the Text, and returns it in its hex-encoded form. The hex encoding uses lowercase letters. This function will crash at runtime if you compile Daml to Daml-LF < 1.2.

reverse

reverse : Text -> Text Reverse some Text.

toCodePoints

toCodePoints : Text -> [Int] Convert a Text into a sequence of unicode code points.

fromCodePoints

fromCodePoints : [Int] -> Text Convert a sequence of unicode code points into a Text. Raises an exception if any of the code points is invalid.

asciiToLower

asciiToLower : Text -> Text Convert the uppercase ASCII characters of a Text to lowercase; all other characters remain unchanged.

asciiToUpper

asciiToUpper : Text -> Text Convert the lowercase ASCII characters of a Text to uppercase; all other characters remain unchanged.