Std.Char (Cure Standard Library v0.37.2)

View Source

The Unicode code point — Cure's character type.

A Char is a Unicode scalar, represented by its code point. It is a nominal opaque carrier rather than an alias for Bounded(0x110000), so APIs cannot accidentally accept arbitrary bounded values as characters. @builtin(:char) names the kernel rule that introduces its values: a character literal is a compact code point, so the runtime representation is one machine integer and no constructor is needed (or allowed). Character literals ('a', '\n') elaborate to Char values, and a String stores its text as a List(Char) behind its own nominal boundary. This module gives the type its visible, documented home, mirroring Std.Int/Std.Float/Std.Binary/Std.Atom.

Construction is confined to literals and the checked from_code_point boundary below, which excludes values outside Unicode scalar space.

This module is the floor of the text layer: Std.Literal describes the literal syntax that produces a Char, and Std.String stores its text as a List(Char), so both sit above it. Std.Char therefore names neither — the ExpressibleByCharacterLiteral instance lives with the interface in Std.Literal, and the String-shaped case conversions live with the type in Std.String.

Examples

use Std.Char

code_point('a')                        # => 97
is_letter('a')                         # => true
is_hex_digit('f')                      # => true
hex_digit_value('f')                   # => Some(15)

Summary

Functions

ASCII-only one-to-one fold for protocols (such as non-Unicode regex caseless matching) that explicitly require ASCII semantics.

Return Some(code) if c is an ASCII character, or None() otherwise.

Return true if c lies within the inclusive code-point range first..last.

The Unicode code point of c as an Int. A Char already erases to its code point, so the runtime bridge is the identity; this names the Char -> Int coercion so Std.Comparable's Char/String instances can compare code points. Named code_point (not to_int) because Std.String also exposes a to_int and the dependent pipeline resolves globals by bare name.

Checked inverse of code_point. JSON and other text decoders use this for escaped Unicode scalars; invalid values and UTF-16 surrogate code points are rejected rather than wrapped into Bounded(0x110000).

Compile-time Unicode character-name lookup for syntax macros. The name arrives as a List(Char); successful macro expansion emits the resulting Char literal, so no name table or parser reaches runtime regex code.

Construct from a code point the caller has already proved is a Unicode scalar. Parsers use this only after checking range and surrogate rules.

Return Some(n) in 0..15 if c is an ASCII hexadecimal digit, or None() otherwise.

Return true if c is an ASCII character (0x00..0x7F).

Return true if c is a Unicode cased character (uppercase, lowercase, or titlecase).

Return true if c is a Unicode currency symbol (Sc).

Return true if c is an ASCII hexadecimal digit (0–9, a–f, or A–F).

Return true if c is a horizontal whitespace character (such as space or tab).

Return true if c belongs to a Unicode letter category (L*).

Return true if c is a lowercase Unicode character (Ll).

Return true if c is a Unicode math symbol (Sm).

Return true if c is a Unicode line-break character.

Return true if c belongs to a Unicode number category (N*).

Return true if c belongs to a Unicode punctuation category (P*).

Return true if c belongs to a Unicode symbol category (S*).

Named scalar-boundary predicates keep parsers from duplicating Unicode's numeric ceiling or the reserved UTF-16 surrogate interval.

Unicode property predicates used by pure Cure text parsers. These expose immutable Unicode tables only; no regex engine or compiled handle crosses the boundary.

Return true if value is a valid Unicode scalar value (in 0..0x10FFFF and not a UTF-16 surrogate).

Return true if c is a Unicode space or whitespace character.

Return true if c is a Unicode word character (letter, mark, number, or connector punctuation).

Return true if c is an uppercase Unicode character (Lu).

Return true if value lies in the reserved UTF-16 surrogate range (0xD800..0xDFFF).

Return true if c is a vertical whitespace character (such as newline or carriage return).

Return true if c is a Unicode whitespace character.

Return true if c represents a whole-number numeric character.

Return true if a has a strictly smaller Unicode code point than b.

Return the full Unicode lowercase mapping of c as a List(Char).

Scalar equality and ordering. Keeping these operations here prevents consumers from unpacking Char into implementation-level integers.

Unicode General_Category as its stable two-letter atom (:Lu, :Nd, …). Regex property matching consumes this immutable classification; no host regex engine or compiled pattern crosses the boundary.

Case conversion answers a List(Char) because Unicode mappings may expand one scalar into several (uppercasing 'ß' yields SS). The shim returns a bare code-point list and an @extern performs no marshalling, so this is the shape the boundary really has; Std.String.uppercased_character/1 and Std.String.lowercased_character/1 assemble the nominal String form, which erases to {String, chars} and belongs with the type that owns it.

Return Some(n) with the integer value of a whole-number character, or None() otherwise.

Functions

ascii_lowercased(c: Char) -> Char

 fn ascii_lowercased(c: Char) -> Char

ASCII-only one-to-one fold for protocols (such as non-Unicode regex caseless matching) that explicitly require ASCII semantics.

ascii_value(c: Char) -> Option(Int)

 fn ascii_value(c: Char) -> Option(Int)

Return Some(code) if c is an ASCII character, or None() otherwise.

between(c: Char, first: Char, last: Char) -> Bool

 fn between(c: Char, first: Char, last: Char) -> Bool

Return true if c lies within the inclusive code-point range first..last.

code_point(c: Char) -> Int

 fn code_point(c: Char) -> Int

The Unicode code point of c as an Int. A Char already erases to its code point, so the runtime bridge is the identity; this names the Char -> Int coercion so Std.Comparable's Char/String instances can compare code points. Named code_point (not to_int) because Std.String also exposes a to_int and the dependent pipeline resolves globals by bare name.

from_code_point(value: Int) -> Option(Char)

 fn from_code_point(value: Int) -> Option(Char)

Checked inverse of code_point. JSON and other text decoders use this for escaped Unicode scalars; invalid values and UTF-16 surrogate code points are rejected rather than wrapped into Bounded(0x110000).

from_unicode_name(name: List(Char)) -> Option(Char)

 fn from_unicode_name(name: List(Char)) -> Option(Char)

Compile-time Unicode character-name lookup for syntax macros. The name arrives as a List(Char); successful macro expansion emits the resulting Char literal, so no name table or parser reaches runtime regex code.

from_valid_code_point(value: Int) -> Char

 fn from_valid_code_point(value: Int) -> Char

Construct from a code point the caller has already proved is a Unicode scalar. Parsers use this only after checking range and surrogate rules.

hex_digit_value(c: Char) -> Option(Int)

 fn hex_digit_value(c: Char) -> Option(Int)

Return Some(n) in 0..15 if c is an ASCII hexadecimal digit, or None() otherwise.

is_ascii(c: Char) -> Bool

 fn is_ascii(c: Char) -> Bool

Return true if c is an ASCII character (0x00..0x7F).

is_cased(c: Char) -> Bool

 fn is_cased(c: Char) -> Bool

Return true if c is a Unicode cased character (uppercase, lowercase, or titlecase).

is_currency_symbol(c: Char) -> Bool

 fn is_currency_symbol(c: Char) -> Bool

Return true if c is a Unicode currency symbol (Sc).

is_hex_digit(c: Char) -> Bool

 fn is_hex_digit(c: Char) -> Bool

Return true if c is an ASCII hexadecimal digit (0–9, a–f, or A–F).

is_horizontal_space(c: Char) -> Bool

 fn is_horizontal_space(c: Char) -> Bool

Return true if c is a horizontal whitespace character (such as space or tab).

is_letter(c: Char) -> Bool

 fn is_letter(c: Char) -> Bool

Return true if c belongs to a Unicode letter category (L*).

is_lowercase(c: Char) -> Bool

 fn is_lowercase(c: Char) -> Bool

Return true if c is a lowercase Unicode character (Ll).

is_math_symbol(c: Char) -> Bool

 fn is_math_symbol(c: Char) -> Bool

Return true if c is a Unicode math symbol (Sm).

is_newline(c: Char) -> Bool

 fn is_newline(c: Char) -> Bool

Return true if c is a Unicode line-break character.

is_number(c: Char) -> Bool

 fn is_number(c: Char) -> Bool

Return true if c belongs to a Unicode number category (N*).

is_punctuation(c: Char) -> Bool

 fn is_punctuation(c: Char) -> Bool

Return true if c belongs to a Unicode punctuation category (P*).

is_symbol(c: Char) -> Bool

 fn is_symbol(c: Char) -> Bool

Return true if c belongs to a Unicode symbol category (S*).

is_unicode_code_point(value: Int) -> Bool

 fn is_unicode_code_point(value: Int) -> Bool

Named scalar-boundary predicates keep parsers from duplicating Unicode's numeric ceiling or the reserved UTF-16 surrogate interval.

is_unicode_digit(c: Char) -> Bool

 fn is_unicode_digit(c: Char) -> Bool

Unicode property predicates used by pure Cure text parsers. These expose immutable Unicode tables only; no regex engine or compiled handle crosses the boundary.

is_unicode_scalar_code_point(value: Int) -> Bool

 fn is_unicode_scalar_code_point(value: Int) -> Bool

Return true if value is a valid Unicode scalar value (in 0..0x10FFFF and not a UTF-16 surrogate).

is_unicode_space(c: Char) -> Bool

 fn is_unicode_space(c: Char) -> Bool

Return true if c is a Unicode space or whitespace character.

is_unicode_word(c: Char) -> Bool

 fn is_unicode_word(c: Char) -> Bool

Return true if c is a Unicode word character (letter, mark, number, or connector punctuation).

is_uppercase(c: Char) -> Bool

 fn is_uppercase(c: Char) -> Bool

Return true if c is an uppercase Unicode character (Lu).

is_utf16_surrogate_code_point(value: Int) -> Bool

 fn is_utf16_surrogate_code_point(value: Int) -> Bool

Return true if value lies in the reserved UTF-16 surrogate range (0xD800..0xDFFF).

is_vertical_space(c: Char) -> Bool

 fn is_vertical_space(c: Char) -> Bool

Return true if c is a vertical whitespace character (such as newline or carriage return).

is_whitespace(c: Char) -> Bool

 fn is_whitespace(c: Char) -> Bool

Return true if c is a Unicode whitespace character.

is_whole_number(c: Char) -> Bool

 fn is_whole_number(c: Char) -> Bool

Return true if c represents a whole-number numeric character.

less_than(a: Char, b: Char) -> Bool

 fn less_than(a: Char, b: Char) -> Bool

Return true if a has a strictly smaller Unicode code point than b.

lowercased_characters(c: Char) -> List(Char)

 fn lowercased_characters(c: Char) -> List(Char)

Return the full Unicode lowercase mapping of c as a List(Char).

same(a: Char, b: Char) -> Bool

 fn same(a: Char, b: Char) -> Bool

Scalar equality and ordering. Keeping these operations here prevents consumers from unpacking Char into implementation-level integers.

unicode_category(c: Char) -> Atom

 fn unicode_category(c: Char) -> Atom

Unicode General_Category as its stable two-letter atom (:Lu, :Nd, …). Regex property matching consumes this immutable classification; no host regex engine or compiled pattern crosses the boundary.

uppercased_characters(c: Char) -> List(Char)

 fn uppercased_characters(c: Char) -> List(Char)

Case conversion answers a List(Char) because Unicode mappings may expand one scalar into several (uppercasing 'ß' yields SS). The shim returns a bare code-point list and an @extern performs no marshalling, so this is the shape the boundary really has; Std.String.uppercased_character/1 and Std.String.lowercased_character/1 assemble the nominal String form, which erases to {String, chars} and belongs with the type that owns it.

whole_number_value(c: Char) -> Option(Int)

 fn whole_number_value(c: Char) -> Option(Int)

Return Some(n) with the integer value of a whole-number character, or None() otherwise.