Text
Text values
This type represents human-readable text as sequences of characters of type Char.
If t is a value of type Text, then:
-
t.chars()returns an iterator of typeIter<Char>enumerating its characters from first to last. -
t.size()returns the size (or length) oft(andt.chars()) as aNat. -
t1 # t2concatenates textst1andt2.
Represented as ropes of UTF-8 character sequences with O(1) concatenation.
This module defines additional operations on Text values.
fromChar
let fromChar : (c : Char) -> Text
Conversion.
Returns the text value of size 1 containing the single character c.
size
func size(t : Text) : Nat
Returns t.size(), the number of characters in t (and t.chars()).
hash
Returns a hash obtained by using the djb2 algorithm from http://www.cse.yorku.ca/~oz/hash.html
This function is good enough for use in a hash-table but it’s not a cryptographic hash function!
Pattern
type Pattern = {#char : Char; #text : Text; #predicate : (Char -> Bool)}
A pattern p describes a sequence of characters. A pattern has one of the following forms:
-
#char cmatches the single character sequence,c. -
#predicate pmatches any single character sequencecsatisfying predicatep(c). -
#text tmatches multi-character text sequencet.
A match for p is any sequence of characters matching the pattern p.
encodeUtf8
let encodeUtf8 : Text -> Blob
Returns the UTF-8 encoding of the given text
decodeUtf8
let decodeUtf8 : Blob -> ?Text
Tries to decode the given Blob as UTF-8.
Returns null if the blob is not valid UTF-8.