On this page:
Char
Char.to_  int
Char.from_  int
Char.upcase
Char.downcase
Char.foldcase
Char.titlecase
Char.is_  alphabetic
Char.is_  lowercase
Char.is_  uppercase
Char.is_  titlecase
Char.is_  numeric
Char.is_  symbolic
Char.is_  punctuation
Char.is_  graphic
Char.is_  whitespace
Char.is_  blank
Char.is_  extended_  pictographic
Char.general_  category
Char.grapheme_  break_  property
Char.grapheme_  step
Char  CI
8.14.0.2

6.25 Characters🔗ℹ

A character is Unicode code point.

Characters are comparable, which means that generic operations like < and > work on characters.

The . operator can be used on a character expression as equivalent to calling Char functions:

ch.to_int()

 is 

Char.to_int(ch)

ch.upcase()

 is 

Char.upcase(ch)

ch.downcase()

 is 

Char.downcase(ch)

ch.foldcase()

 is 

Char.foldcase(ch)

ch.titlecase()

 is 

Char.titlecase(ch)

ch.is_alphabetic()

 is 

Char.is_alphabetic(ch)

ch.is_lowercase()

 is 

Char.is_lowercase(ch)

ch.is_uppercase()

 is 

Char.is_uppercase(ch)

ch.is_titlecase()

 is 

Char.is_titlecase(ch)

ch.is_numeric()

 is 

Char.is_numeric(ch)

ch.is_symbolic()

 is 

Char.is_symbolic(ch)

ch.is_punctuation()

 is 

Char.is_punctuation(ch)

ch.is_graphic()

 is 

Char.is_graphic(ch)

ch.is_whitespace()

 is 

Char.is_whitespace(ch)

ch.is_blank()

 is 

Char.is_blank(ch)

ch.is_extended_pictographic()

 is 

Char.is_extended_pictographic(ch)

ch.general_category()

 is 

Char.general_category(ch)

ch.grapheme_break_property()

 is 

Char.grapheme_break_property(ch)

ch.grapheme_step(state)

 is 

Char.grapheme_step(ch, state)

annotation

Char

Matches characters.

function

fun Char.to_int(ch :: Char) :: NonnegInt

Returns the Unicode value of a character.

Returns the character corresponding to a Unicode value. The given i must be in the range 0x0 to 0x10FFFF, (inclusive), and not in the range 0xD800 to 0xDFFF (inclusive).

function

fun Char.upcase(ch :: Char) :: Char

 

function

fun Char.downcase(ch :: Char) :: Char

 

function

fun Char.foldcase(ch :: Char) :: Char

 

function

fun Char.titlecase(ch :: Char) :: Char

Unicode case conversions.

Character Unicode classifications:

function

fun Char.grapheme_step(ch :: Char, state :: Int)

  :: (Boolean, Int)

Encodes a state machine for Unicode’s grapheme-cluster specification on a sequence of code points. It accepts a character for the next code point in a sequence, and it returns two values: whether a (single) grapheme cluster has terminated since the most recently reported termination (or the start of the stream), and a new state to be used with Char.grapheme_step and the next character.

A value of 0 for state represents the initial state or a state where no characters are pending toward a new boundary. Thus, if a sequence of characters is exhausted and accumulated state is not 0, then the end of the stream creates one last grapheme-cluster boundary. When Char.grapheme_step produces a true value as its first result and a non-0 value as its second result, then the given ch must be the only character pending toward the next grapheme cluster (by the rules of Unicode grapheme clustering).

The Char.grapheme_step procedure will produce a result for any fixnum state, but the meaning of a non-0 state is specified only in that providing such a state produced by Char.grapheme_step in another call to Char.grapheme_step continues detecting grapheme-cluster boundaries in the sequence.

See also String.grapheme_span and String.grapheme_count.

annotation

CharCI

A veneer for a character that redirects comparable operations like < and > to case-insensitive comparisons, equivalent to using Char.foldcase on each character before comparing.

As always for a veneer, CharCI works only in static mode (see use_static) to help ensure that it has the intended effect.

> "a"[0] < "B"[0]

#false

> ("a"[0] :: CharCI) < ("B"[0] :: CharCI)

#true