Skip to content

text

def Text.within (c : Nat) (ranges : List (Nat * Nat)) : Bool

Whether the code point c is in one of the ranges (both ends included).

def Text.isSpace (c : Nat) : Bool

Whether the code point c is whitespace (CPython’s str.isspace: every code point that is).

def Text.isDigit (c : Nat) : Bool

Whether the code point c is a decimal digit 0-9.

def Text.isUpper (c : Nat) : Bool

Whether the code point c is an ASCII capital letter.

def Text.isLower (c : Nat) : Bool

Whether the code point c is an ASCII small letter.

def Text.isCased (c : Nat) : Bool

Whether the code point c is an ASCII letter (a letter with case).

data Character

What the model knows of a code point: a letter with case (an ASCII letter), a code point without case (whether it is a letter, a decimal digit, whitespace), or one past what the model classifies.

def Text.caselessLetters : List (Nat * Nat)

The letters without case the model knows (CPython’s str.isalpha): iteration marks, kana, bopomofo, CJK ideographs, Hangul syllables, halfwidth kana and Hangul.

def Text.caselessBlocks : List (Nat * Nat)

The blocks whose other code points are known to be without case and neither letters, digits nor whitespace: general punctuation, CJK symbols, kana, bopomofo, halfwidth and fullwidth forms (but the fullwidth Latin letters, which have case).

def Text.character (c : Nat) : Character

What the model knows of the code point c.

def Text.classified (cs : Codes) : Bool

Whether the model knows the class of every code point of the text cs.

def Text.asciiDigit (c : Nat) : Nat

The code point c as CPython reads numbers: a fullwidth digit as its ASCII digit, whitespace as a space.

def Text.upper (c : Nat) : Nat

The code point c in capitals (ASCII only).

def Text.lower (c : Nat) : Nat

The code point c in small letters (ASCII only).

def Text.dropWhile (p : Nat -> Bool) (cs : Codes) : Codes

The code points of cs after the leading ones that p holds for.

def Text.takeWhile (p : Nat -> Bool) (cs : Codes) : Codes

The leading code points of cs that p holds for.

def Text.dropEnd (p : Nat -> Bool) (cs : Codes) : Codes

The code points of cs without the trailing ones that p holds for.

def Text.strip (cs : Codes) : Codes

The code points of cs without whitespace at either end (s.strip()).

def Text.same (a : Codes) (b : Codes) : Bool

Whether the texts a and b are the same.

def Text.wordsWithin (fuel : Nat) (cs : Codes) : List Codes

The words of cs between whitespace (s.split(): runs of whitespace are one separator, none at either end), within fuel words.

def Text.words (cs : Codes) : List Codes

The words of cs between whitespace (s.split()).

def Text.splitWithin (fuel : Nat) (separator : Codes) (piece : Codes) (cs : Codes) : List Codes

The pieces of cs between occurrences of separator (not empty), after piece, the current piece so far, within fuel steps.

def Text.split (separator : Codes) (cs : Codes) : List Codes

The pieces of cs between occurrences of separator (s.split(sep), separator not empty).

def Text.usedUp (k : Option Nat) : Bool

Whether k, the count of replacements left, is used up (none: no limit).

def Text.oneLess (k : Option Nat) : Option Nat

One replacement fewer left than k (none stays none).

def Text.replaceWithin (fuel : Nat) (old : Codes) (new : Codes) (k : Option Nat) (cs : Codes) : Codes

s.replace(old, new, k) on cs: old (not empty) replaced by new at most k times, within fuel steps.

def Text.replaceEmpty (new : Codes) (k : Option Nat) (cs : Codes) : Codes

s.replace("", new, k) on cs: new before each code point and at the end, at most k times.

def Text.replace (old : Codes) (new : Codes) (k : Option Nat) (cs : Codes) : Codes

s.replace(old, new, k) on cs: old replaced by new at most k times (k none: every occurrence).

def Text.countWithin (fuel : Nat) (part : Codes) (cs : Codes) : Nat

How many times part (not empty) occurs in cs without overlapping, within fuel steps.

def Text.count (part : Codes) (cs : Codes) : Nat

s.count(part) on cs for a part that is not empty.

def Text.title (afterCased : Bool) (cs : Codes) : Codes

s.title() on cs: a letter with case in capitals after a code point without case, in small letters after one with case (afterCased: whether the code point before had case).

def Text.digits (value : Nat) (afterDigit : Bool) (cs : Codes) : Option Nat

The decimal digits cs with single underscores between digits as a natural (value is the value so far, afterDigit whether the code point before was a digit); none for anything else, or nothing.

def Text.digitsAfterUnderscore (value : Nat) (cs : Codes) : Option Nat

The digits cs after an underscore, with value the value so far: a digit must come next.

def Text.sign (cs : Codes) : Bool * Codes

A leading sign taken off cs: whether it was a minus, and the rest.

def Text.signedInt (negative : Bool) (n : Nat) : Int

The natural n as an int, negated when negative.

def Text.toInt (cs : Codes) : Option Int

int(s) of the decimal text cs: none when it is not one.

def Text.exponent (cs : Codes) : Option Int

A decimal exponent’s text cs after e: a sign and digits.

def Text.optionalDigits (cs : Codes) : Option Nat

The digits cs that may be absent: zero when there are none.

def Text.decimal (negative : Bool) (cs : Codes) : Option Float

A decimal float’s text cs without its sign (negative when it was a minus): digits, a fraction, an exponent (e or E), correctly rounded.

def Text.toFloat (cs : Codes) : Option Float

float(s) of the text cs: a decimal, or inf, infinity, nan in any case, with a sign; none when it is none of these.