DA.Text
Daml 模块 DA.Text 参考文档
DA.Text
DA.Text
操作 Text 的函数。
模块快照
函数
explode
explode : Text -> [Text]
implode
implode : [Text] -> Text
isEmpty
isEmpty : Text -> Bool
测试是否为空。
isNotEmpty
isNotEmpty : Text -> Bool
测试是否非空。
length
length : Text -> Int
计算文本中的符号数。
trim
trim : Text -> Text
去除给定文本两端的空格。
replace
replace : Text -> Text -> Text -> Text
在全文替换子串;第一个参数 不能为空。
lines
lines : Text -> [Text]
在换行符处将 Text 拆成 Text 列表;
结果不含换行符。
unlines
unlines : [Text] -> Text
连接各行,并在每行末尾追加换行符。
words
words : Text -> [Text]
按空白符号将 Text 拆成单词列表。
unwords
unwords : [Text] -> Text
用单个空格连接单词。
linesBy
linesBy : (Text -> Bool) -> Text -> [Text]
lines 的变体,使用自定义分隔测试;
末尾分隔符会被丢弃。
wordsBy
wordsBy : (Text -> Bool) -> Text -> [Text]
words 的变体,使用自定义分隔测试;
相邻及首尾分隔符均会被丢弃。
intercalate
intercalate : Text -> [Text] -> Text
intercalate 在 ts 各项之间插入 t 并拼接。
dropPrefix
dropPrefix : Text -> Text -> Text
dropPrefix 去掉给定前缀;若无此前缀则返回原文。
dropSuffix
dropSuffix : Text -> Text -> Text
去掉给定后缀;若无此后缀则返回原文。 示例:
dropSuffix "!" "Hello World!" == "Hello World"
dropSuffix "!" "Hello World!!" == "Hello World!"
dropSuffix "!" "Hello World." == "Hello World."
stripSuffix
stripSuffix : Text -> Text -> Optional Text
若第二段文本的后缀与第一段完全匹配,则返回其前缀。 示例:
stripSuffix "bar" "foobar" == Some "foo"
stripSuffix "" "baz" == Some "baz"
stripSuffix "foo" "quux" == None
stripPrefix
stripPrefix : Text -> Text -> Optional Text
stripPrefix 去掉给定前缀;
若文本不以该前缀开头则返回 None。
isPrefixOf
isPrefixOf : Text -> Text -> Bool
isPrefixOf 判断第一段是否为第二段的前缀。
isSuffixOf
isSuffixOf : Text -> Text -> Bool
isSuffixOf 判断第一段是否为第二段的后缀。
isInfixOf
isInfixOf : Text -> Text -> Bool
isInfixOf 判断第一段是否完整出现在第二段中。
takeWhile
takeWhile : (Text -> Bool) -> Text -> Text
takeWhile p t 返回 t 中最长前缀(可为空),
其中符号均满足 p。
takeWhileEnd
takeWhileEnd : (Text -> Bool) -> Text -> Text
takeWhileEnd p t 返回 t 中最长后缀(可为空),
其中符号均满足 p。
dropWhile
dropWhile : (Text -> Bool) -> Text -> Text
dropWhile p t 为 takeWhile p t 之后的后缀。
dropWhileEnd
dropWhileEnd : (Text -> Bool) -> Text -> Text
dropWhileEnd p t 为从末尾去掉满足 p 的符号后剩余的前缀。
splitOn
splitOn : Text -> Text -> [Text]
用第一个文本(不可为空)作分隔符拆分,并消耗分隔符。
splitAt
splitAt : Int -> Text -> (Text, Text)
在指定位置拆分,使得对 0 <= n <= length t,
length (fst (splitAt n t)) == n。
take
take : Int -> Text -> Text
take n t 返回长度为 n 的前缀;若 n 大于长度则返回 t。
drop
drop : Int -> Text -> Text
drop n t 返回去掉前 n 个字符后的后缀;
若 n 大于长度则返回空 Text。
substring
substring : Int -> Int -> Text -> Text
从参数文本的位置 s 起取长度为 l 的符号序列。
isPred
isPred : (Text -> Bool) -> Text -> Bool
isPred f t 在 t 非空且 t 中所有符号满足 f 时为 True。
isSpace
isSpace : Text -> Bool
isNewLine t 在 t 非空且仅含换行符时为 True。
isNewLine
isNewLine : Text -> Bool
isNewLine t 在 t 非空且仅含换行符时为 True。
isUpper
isUpper : Text -> Bool
isUpper t 在 t 非空且仅含大写符号时为 True。
isLower
isLower : Text -> Bool
isLower t 在 t 非空且仅含小写符号时为 True。
isDigit
isDigit : Text -> Bool
isDigit t 在 t 非空且仅含数字符号时为 True。
isAlpha
isAlpha : Text -> Bool
isAlpha t 在 t 非空且仅含字母符号时为 True。
isAlphaNum
isAlphaNum : Text -> Bool
isAlphaNum t 在 t 非空且仅含字母数字符号时为 True。
parseInt
parseInt : Text -> Optional Int
尝试从 Text 解析 Int。
parseNumeric
parseNumeric : NumericScale n => Text -> Optional (Numeric n)
尝试从 Text 解析 Numeric。
要得到 Some,文本须匹配正则
(-|\+)?[0-9]+(\.[0-9]+)?
简写 ".12"、"12." 无效,
但可用 + 前缀。
首尾零可以,但不可含空格。
示例:
parseNumeric "3.14" == Some 3.14
parseNumeric "+12.0" == Some 12
parseDecimal
parseDecimal : Text -> Optional Decimal
尝试从 Text 解析 Decimal。
要得到 Some,文本须匹配正则
(-|\+)?[0-9]+(\.[0-9]+)?
简写 ".12"、"12." 无效,
但可用 + 前缀。
首尾零可以,但不可含空格。
示例:
parseDecimal "3.14" == Some 3.14
parseDecimal "+12.0" == Some 12
sha256
sha256 : Text -> Text
对 Text 的 UTF-8 字节计算 SHA256,并以小写十六进制返回。
若编译目标为 Daml-LF < 1.2,此函数会在运行时崩溃。
reverse
reverse : Text -> Text
反转 Text。
reverse "Daml" == "lmaD"
toCodePoints
toCodePoints : Text -> [Int]
将 Text 转为 Unicode 码点序列。
fromCodePoints
fromCodePoints : [Int] -> Text
将 Unicode 码点序列转为 Text;无效码点会抛异常。
asciiToLower
asciiToLower : Text -> Text
将 Text 中的 ASCII 大写转为小写;
其他字符不变。
asciiToUpper
asciiToUpper : Text -> Text
将 Text 中的 ASCII 小写转为大写;
其他字符不变。
本文由 CC Privacy Club 根据 Canton Network 官方文档(CC-BY-4.0)整理翻译,仅供学习;实现细节以官方最新版本为准。