Skip to main content

Char

Reference for mo:core/Char in the core library.

Char provides Unicode scalar conversion helpers, trusted classification predicates, and inline comparison wrappers. fromNat32 requires the input to be a valid scalar value, excluding surrogate code points.

Import​

mo:core/Char

Status​

  • Runtime module

Public API​

Types​

  • Char

Functions​

toNat32(char : Char) : Nat32​

Converts between the module type and the target representation.

Use when: crossing between this module's value and another representation.

fromNat32(nat32 : Nat32) : Char​

Converts between the module type and the target representation.

Contract

requires nat32 < (0xD800 : Nat32) or ((0xE000 : Nat32) <= nat32 and nat32 <= (0x10FFFF : Nat32));

Use when: crossing between this module's value and another representation.

toText(char : Char) : Text​

Converts between the module type and the target representation.

Use when: crossing between this module's value and another representation.

isDigit(char : Char) : Bool​

Checks the predicate described by the return contract.

Contract

ensures result == (char >= '0' and char <= '9');

Use when: a branch condition or contract needs this predicate as a named fact.

isWhitespace(char : Char) : Bool​

Checks the predicate described by the return contract.

Use when: a branch condition or contract needs this predicate as a named fact.

isLower(char : Char) : Bool​

Checks the predicate described by the return contract.

Use when: a branch condition or contract needs this predicate as a named fact.

isUpper(char : Char) : Bool​

Checks the predicate described by the return contract.

Use when: a branch condition or contract needs this predicate as a named fact.

isAlphabetic(char : Char) : Bool​

Checks the predicate described by the return contract.

Use when: a branch condition or contract needs this predicate as a named fact.

equal(a : Char, b : Char) : Bool​

Compares the supplied values and relates the result to the underlying order.

Contract

ensures result == (a == b);

Use when: code or contracts need an explicit comparison helper instead of an operator.

notEqual(a : Char, b : Char) : Bool​

Compares the supplied values and relates the result to the underlying order.

Contract

ensures result == (a != b);

Use when: code or contracts need an explicit comparison helper instead of an operator.

less(a : Char, b : Char) : Bool​

Compares the supplied values and relates the result to the underlying order.

Contract

ensures result == (a < b);

Use when: code or contracts need an explicit comparison helper instead of an operator.

lessOrEqual(a : Char, b : Char) : Bool​

Compares the supplied values and relates the result to the underlying order.

Contract

ensures result == (a <= b);

Use when: code or contracts need an explicit comparison helper instead of an operator.

greater(a : Char, b : Char) : Bool​

Compares the supplied values and relates the result to the underlying order.

Contract

ensures result == (a > b);

Use when: code or contracts need an explicit comparison helper instead of an operator.

greaterOrEqual(a : Char, b : Char) : Bool​

Compares the supplied values and relates the result to the underlying order.

Contract

ensures result == (a >= b);

Use when: code or contracts need an explicit comparison helper instead of an operator.

compare(a : Char, b : Char) : Types.Order​

Compares the supplied values and relates the result to the underlying order.

Contract

ensures result == #less ==> a < b;
ensures result == #equal ==> a == b;
ensures result == #greater ==> a > b;
ensures a < b ==> result == #less;
ensures a == b ==> result == #equal;
ensures a > b ==> result == #greater;

Use when: code or contracts need an explicit comparison helper instead of an operator.

Summary​

  • Runtime module under mo:core/Char.
  • Exposes 15 public functions.