跳到內容

string

本頁內容尚未翻譯。

def Pos.equal (p : Pos) (q : Pos) : Bool

Whether two binary positive numbers are equal, compared bit by bit.

def Bin.equal (a : Bin) (b : Bin) : Bool

Whether two binary natural numbers are equal.

def Pos.toNat (p : Pos) : Nat

A binary positive number as a natural number.

def Pos.ofNat (bits : Nat) (n : Nat) : Pos

A positive natural number in binary, the least significant bit outermost; bits bounds the number of bits.

def code (c : Char) : Nat

The code point of a character.

def ofCode (n : Nat) : Char

The character of a code point (64 bits are enough for any code point).

def equal (c : Char) (d : Char) : Bool

Whether two characters are the same code point.

def ofDigit (d : Nat) : Char

The digit character of a number from 0 to 9.

def positionIn (c : Char) (cs : List Char) (i : Nat) : Option Nat

The position of a character in a list, counting from i.

def digit (c : Char) : Option Nat

The value of a decimal digit character, or none for any other character.

def inRange (low : Nat) (high : Nat) (c : Char) : Bool

Whether a character’s code point is from low to high.

def isDigit (c : Char) : Bool

Whether a character is an ASCII decimal digit.

def isUpper (c : Char) : Bool

Whether a character is an ASCII uppercase letter.

def isLower (c : Char) : Bool

Whether a character is an ASCII lowercase letter.

def isAlpha (c : Char) : Bool

Whether a character is an ASCII letter.

def isAlphanumeric (c : Char) : Bool

Whether a character is an ASCII letter or digit.

def isSpace (c : Char) : Bool

Whether a character is whitespace: a space, a tab, a carriage return or a newline.

def toUpper (c : Char) : Char

An ASCII lowercase letter in uppercase; any other character as it is.

def toLower (c : Char) : Char

An ASCII uppercase letter in lowercase; any other character as it is.

def Nat.hexDigit (d : Nat) : Char

The lowercase hexadecimal digit of a number from 0 to 15.

def lastDigit (n : Nat) : Char

The last decimal digit of a number, as a character.

def digits (fuel : Nat) (n : Nat) (rest : List Char) : List Char

The decimal digits of n in front of rest, by repeated division by 10; fuel only bounds the recursion (it stops when n < 10).

def read (cs : List Char) (read : Nat) : Option Nat

The number decimal digits give, read onto read; none at a character that is not a digit.

def Nat.decimal (n : Nat) : String

The decimal digits of a natural number (toString n is the same).

def chars (s : String) : List Char

The characters of a string.

def append (a : String) (b : String) : String

Two strings one after the other.

def length (s : String) : Nat

The number of characters of a string (not of bytes).

def sameChars (cs : List Char) (ds : List Char) : Bool

Whether two lists of characters are the same, character by character.

def equal (a : String) (b : String) : Bool

Whether two strings have the same characters.

def concat (xs : List String) : String

The strings of a list one after the other; f"..." expands to it.

def charsAfter (start : List Char) (cs : List Char) : Option (List Char)

The characters after a prefix, if the characters start with it.

def cutAt (sep : List Char) (fuel : Nat) (cs : List Char) (piece : List Char) : List (List Char)

Characters cut at every occurrence of a separator (not empty), the piece so far in reverse; fuel bounds the recursion.

def split (s : String) (sep : String) : List String

A string cut at every occurrence of a separator, left to right; an empty separator gives the whole string.

def join (sep : String) (xs : List String) : String

The strings of a list with a separator between each two.

def isEmpty (s : String) : Bool

Whether a string has no characters.

def lines (s : String) : List String

The lines of a string, cut at each newline.

def words (s : String) : List String

The words of a string: the pieces between spaces that are not empty.

def toNat (s : String) : Option Nat

The number a non-empty string of decimal digits writes, or none.

def startsWith (s : String) (start : String) : Bool

Whether a string starts with a prefix.

def reversed (s : String) : String

A string’s characters in reverse order.

def endsWith (s : String) (ending : String) : Bool

Whether a string ends with a suffix.

def take (n : Nat) (s : String) : String

The first n characters of a string.

def drop (n : Nat) (s : String) : String

A string without its first n characters.

def dropSpaces (cs : List Char) : List Char

Characters without the whitespace at their start.

def trim (s : String) : String

A string without the whitespace at its start and end.

def positionIn (part : List Char) (cs : List Char) (i : Nat) : Option Nat

The position of the first occurrence of a part in characters, counting from i.

def indexOf (s : String) (part : String) : Option Nat

The character position of the first occurrence of a part in a string, if it occurs.

def contains (s : String) (part : String) : Bool

Whether a part occurs in a string.

def replacedIn (part : List Char) (replacement : List Char) (fuel : Nat) (cs : List Char) : List Char

Characters with every occurrence of a part (not empty) replaced, left to right; fuel bounds the recursion.

def replace (s : String) (part : String) (replacement : String) : String

A string with every occurrence of a part replaced, left to right and not overlapping; an empty part changes nothing.

def toUpper (s : String) : String

A string with its ASCII letters in uppercase.

def toLower (s : String) : String

A string with its ASCII letters in lowercase.

def repeat (n : Nat) (s : String) : String

A string n times.

def padding (n : Nat) (pad : String) : List Char

The first n characters of a padding repeated.

def padStart (n : Nat) (pad : String) (s : String) : String

A string padded at its start up to n characters (a longer one as it is).

def padEnd (n : Nat) (pad : String) (s : String) : String

A string padded at its end up to n characters (a longer one as it is).

def nonEmptyLines (s : String) : List String

The lines of a string that are not empty after trimming, trimmed.

class ToString (A : Type)

Types whose values can be shown as a string.

instance toStringNat : ToString Nat

A natural number in decimal.

instance toStringBool : ToString Bool

true and false.

instance toStringString : ToString String

A string as itself.

instance toStringList {A : Type} {{d : ToString A}} : ToString (List A)

A list as [a, b, c].

instance toStringOption {A : Type} {{d : ToString A}} : ToString (Option A)

An option as none or some a.

def hasDigits (cs : List Char) : Bool

Whether there is at least one digit.

def bltAddLeft (x : Nat) (n : Nat) (k : Nat) (h : Nat.blt x n = true) : Nat.blt x (add k n) = true

bltSuccR k times: x < n implies x < k + n.

def bltOfAddLeft (m : Nat) (n : Nat) (k : Nat) (h : Nat.blt (add k m) n = true) : Nat.blt m n = true

bltPredL k times: k + m < n implies m < n.

def timesTenPlus (d : Nat) (r : Nat) : Nat

d * 10 + r.

def shifted (v : Nat) (n : Nat) : Nat

A value with the last digit of n appended: v * 10 + n mod 10.

def belowTimesTen (d : Nat) (r : Nat) : Nat.blt d (succ (Decimal.timesTenPlus d r)) = true

d < d * 10 + r + 1.

def quotientBelow (D : Nat) (R : Nat) (k : Nat) (h : Nat.blt (Decimal.timesTenPlus D R) (succ k) = true) (hr : Nat.blt R 10 = true) (e : Nat.blt (Decimal.timesTenPlus D R) 10 = false) : Nat.blt D k = true

The next digit has fuel: from D * 10 + R < k + 1, R < 10 and D * 10 + R not below 10, D < k.

def quotientHasFuel (n : Nat) (k : Nat) (h : Nat.blt n (succ k) = true) (e : Nat.blt n 10 = false) : Nat.blt (Nat.div n 10) k = true

Dropping the last decimal digit of n (at least 10) leaves fuel: n < k + 1 implies n / 10 < k.

def digitOfDigit (d : Nat) (h : Nat.blt d 10 = true) : Char.digit (Char.ofDigit d) = some d

Reading back one digit: the digit of Char.ofDigit d is d, for d < 10.

def value (fuel : Nat) (read : Nat) (n : Nat) : Nat

The value read back from Decimal.digits, with the same fuel and recursion, onto read.

def digitsAfter (small : Bool) (fewer : Nat) (n : Nat) (rest : List Char) : List Char

Decimal.digits after its comparison with 10.

def valueAfter (small : Bool) (fewer : Nat) (read : Nat) (n : Nat) : Nat

Decimal.value after its comparison with 10.

def readDigit (m : Option Nat) (rest : List Char) (read : Nat) : Option Nat

Decimal.read of a looked-up digit.

def readOne (d : Nat) (h : Nat.blt d 10 = true) (rest : List Char) (read : Nat) : Decimal.read (cons (Char.ofDigit d) rest) read = Decimal.read rest (add (mul read 10) d)

Reading a digit d < 10 multiplies the value by ten and adds d.

def ReadsAfter (small : Bool) (fewer : Nat) (n : Nat) (rest : List Char) (read : Nat) : Type

The statement of Decimal.readDigits after the comparison with 10.

def readDigits (fuel : Nat) : (n : Nat) -> (rest : List Char) -> (read : Nat) -> Decimal.read (Decimal.digits fuel n rest) read = Decimal.read rest (Decimal.value fuel read n)

Reading what Decimal.digits writes is reading on with the value of n, for any fuel.

def ValueAfter (small : Bool) (fewer : Nat) (n : Nat) : Type

The statement of Decimal.valueOfDigits after the comparison with 10.

def valueOfDigits (fuel : Nat) : (n : Nat) -> Nat.blt n fuel = true -> Decimal.value fuel 0 n = n

With enough fuel (n < fuel), the value read back is n.

def digitsNotEmpty (fuel : Nat) : (n : Nat) -> (c : Char) -> (rest : List Char) -> Decimal.hasDigits (Decimal.digits fuel n (cons c rest)) = true

Decimal.digits onto a non-empty list is not empty.

def decimalNotEmpty (n : Nat) : Decimal.hasDigits (Decimal.digits (succ n) n nil) = true

The decimal digits of a number are not empty.

def toNatOf (cs : List Char) : Option Nat

String.toNat of characters.

def toNatOfNotEmpty (cs : List Char) (h : Decimal.hasDigits cs = true) : Decimal.toNatOf cs = Decimal.read cs 0

On characters that are not empty, String.toNat reads them.

def String.toNatDecimal (n : Nat) : String.toNat (Nat.decimal n) = some n

Reading back the decimal digits gives the number.