rune
Rune: a code point of Unicode, a 32-bit value, as Go’s rune is.
A literal is written in quotes — 'a', 'é', '😀', a string’s
escapes ('\n', '\'', '\\') or '\u{1F600}' — and is a Unicode
scalar value: from U+0000 to U+10FFFF, but the surrogates, U+D800 to
U+DFFF. A rune made of an integer may be any 32-bit value (fromInt,
as Go’s rune(n)); one that is no scalar value is U+FFFD,
replacement, in a string made of it (the prelude’s fromRunes), as
what is not UTF-8 is where a string’s runes are read (runes).
Import it by a name, import rune as Rune, as its names are the
prelude’s: Rune.compare, Rune.max. Its operators, == to >=, are
these too, for a module that imports it as it is and the prelude by a
name. Its classes and cases are ASCII’s: isAlpha 'é' is False.
runeLt
runeLt : Rune -> Rune -> BoolruneLe
runeLe : Rune -> Rune -> BoolstrRuneCount
strRuneCount : String -> InttoInt
toInt : Rune -> IntIts code point.
fromInt
fromInt : Int -> RuneThe rune of an integer, wrapped around to 32 bits as an Int32 is:
fromInt 233 is 'é'.
replacement
replacement : RuneU+FFFD, what a string has for a rune that is none (Go’s
utf8.RuneError).
maxRune
maxRune : RuneThe last code point, U+10FFFF.
>>> List.map toInt ['a', 'é', '😀', maxRune, fromInt 4294967361][97, 233, 128512, 1114111, 65]validCode
validCode : Int -> BoolisValid
isValid : Rune -> BoolWhether it is a Unicode scalar value: what a literal is, and what a
string keeps as it is (Go’s utf8.ValidRune).
>>> List.map isValid [fromInt 55296, fromInt 1114112, fromInt -1, 'a'][False, False, False, True]width
width : Rune -> IntHow many bytes it is in a string: 1 to 4 (one that is no scalar
value 3, as U+FFFD is; Go’s utf8.RuneLen).
>>> List.map width ['a', 'é', '中', '😀', fromInt 55296][1, 2, 3, 4, 3]count
count : String -> IntHow many runes a string has, List.length (runes s) (Go’s
utf8.RuneCountInString).
>>> List.map count ["", "héllo", "a😀", "\xffa"][0, 5, 2, 2]foldl
foldl : {a : Type} -> (a -> Int -> Rune -> a) -> a -> String -> aIts runes, each with where its bytes start, from the first (Go’s
for i, r := range s).
>>> foldl (\acc i c -> acc ^ debug i ^ show c) "" "aé😀""0a1é3😀"foldr
foldr : {a : Type} -> (Int -> Rune -> a -> a) -> a -> String -> aIts runes, each with where its bytes start, from the last: f i1 r1 (f i2 r2 (… z)), as List.foldr goes.
>>> foldr (\i c acc -> acc ^ debug i ^ show c) "" "a\u{e9}\u{1F600}""3\u{1F600}1\u{e9}0a"validString
validString : String -> BoolWhether a string is UTF-8, each of its runes’ bytes (Go’s
utf8.ValidString).
>>> List.map validString ["", "héllo", "\u{FFFD}", "\xe9", "\xc3"][True, True, True, False, False]toValid
toValid : String -> StringThe string, what is not UTF-8 in it U+FFFD, as runes reads it:
fromRunes (runes s).
>>> runes (toValid "a\xffb")['a', '\u{FFFD}', 'b']eq
eq : Rune -> Rune -> Boollt
lt : Rune -> Rune -> Boolle
le : Rune -> Rune -> Boolcompare
compare : Rune -> Rune -> Orderingmin
min : Rune -> Rune -> Runemax
max : Rune -> Rune -> Runewithin
within : Rune -> Rune -> Rune -> BoolisAscii
isAscii : Rune -> BoolisDigit
isDigit : Rune -> Bool'0' to '9'.
isHexDigit
isHexDigit : Rune -> BoolA digit, or 'a' to 'f', 'A' to 'F'.
isUpper
isUpper : Rune -> BoolisLower
isLower : Rune -> BoolisAlpha
isAlpha : Rune -> BoolA letter of ASCII’s, upper or lower case.
isAlphaNum
isAlphaNum : Rune -> BoolisSpace
isSpace : Rune -> BoolA space, a tab, a line feed, a carriage return, a vertical tab or a form feed.
>>> List.map isSpace (runes " \t\nx")[True, True, True, False]isControl
isControl : Rune -> BoolA control character: C0’s, DEL, C1’s.
toUpper
toUpper : Rune -> Rune'a' to 'z' in upper case; any other as it is.
>>> fromRunes (List.map toUpper (runes "héllo, wörld"))"HéLLO, WöRLD"toLower
toLower : Rune -> Rune'A' to 'Z' in lower case; any other as it is.