Char structure

June 6, 2026 · View on GitHub

Up to index

The Char structure provides the character type and associated operations for examining and converting characters. Characters are identified by their Unicode code points.

Specified by the Standard ML Basis Library.

Synopsis

type char
type string

val minChar : char
val maxChar : char
val maxOrd : int
val ord : char -> int
val chr : int -> char
val succ : char -> char
val pred : char -> char
val compare : char * char -> order
val < : char * char -> bool
val <= : char * char -> bool
val > : char * char -> bool
val >= : char * char -> bool
val = : char * char -> bool
val <> : char * char -> bool
val contains : string -> char -> bool
val notContains : string -> char -> bool
val isAscii : char -> bool
val toLower : char -> char
val toUpper : char -> char
val isAlpha : char -> bool
val isAlphaNum : char -> bool
val isCntrl : char -> bool
val isDigit : char -> bool
val isGraph : char -> bool
val isHexDigit : char -> bool
val isOctDigit : char -> bool
val isLower : char -> bool
val isPrint : char -> bool
val isSpace : char -> bool
val isPunct : char -> bool
val isUpper : char -> bool
val toString : char -> string
val fromString : string -> char option
val fromInt : int -> char option
val toCString : char -> string
val fromCString : string -> char option
val scan : (Char.char, 'a) StringCvt.reader -> (char, 'a) StringCvt.reader

type char

is the type of characters.

type string

minChar

minChar is the minimal (most negative) character representable by char. If a value is NONE, char can represent all negative integers, within the limits of the heap size. If precision is SOME (n), then we have minChar = -2(n-1).

maxChar

maxChar is the greatest character in the ordering <.

maxOrd

maxOrd is the greatest character code; it equals ord maxChar.

ord

ord c (or c.ord ()) returns the code of character c.

chr

chr i returns the character whose code is i. Raises Chr if i < 0 or i > maxOrd.

succ

succ c (or c.succ ()) returns the character immediately following c, or raises Chr if c = maxChar

pred

pred c (or c.pred ()) returns the predecessor of c. Raises Subscript if c is minOrd.

compare

compare (c1, c2) (or c1.compare c2) returns LESS, EQUAL, or GREATER according to whether its first argument is less than, equal to, or greater than the second.

<

c1 < c2 returns true if c1 is less than c2 in the character ordering.

<=

c1 <= c2 returns true if c1 is less than or equal to c2 in the character ordering.

>

c1 > c2 returns true if c1 is greater than c2 in the character ordering.

>=

c1 >= c2 returns true if c1 is greater than or equal to c2 in the character ordering.

=

c1 = c2 returns true if c1 and c2 are the same character.

<>

c1 <> c2 returns true if c1 and c2 are different characters.

contains

contains s c returns true if character c occurs in the string s; false otherwise. The function, when applied to s, builds a table and returns a function which uses table lookup to decide whether a given character is in the string or not. Hence it is relatively expensive to compute val p = contains s but very fast to compute p(c) for any given character.

notContains

notContains s c returns true if character c does not occur in the string s; false otherwise. Works by construction of a lookup table in the same way as Char.contains.

isAscii

isAscii c (or c.isAscii ()) returns true if 0 ≤ ord c ≤ 127 c.

toLower

toLower c (or c.toLower ()) returns the lowercase letter corresponding to c, if c is a letter (a to z or A to Z); otherwise returns c.

toUpper

toUpper c (or c.toUpper ()) returns the uppercase letter corresponding to c, if c is a letter (a to z or A to Z); otherwise returns c.

isAlpha

isAlpha c (or c.isAlpha ()) returns true if c is a letter (lowercase or uppercase).

isAlphaNum

isAlphaNum c (or c.isAlphaNum ()) returns true if c is alphanumeric (a letter or a decimal digit).

isCntrl

isCntrl c (or c.isCntrl ()) returns true if c is a control character, that is, if not (isPrint c).

isDigit

isDigit c (or c.isDigit ()) returns true if c is a decimal digit (0 to 9).

isGraph

isGraph c (or c.isGraph ()) returns true if c is a graphical character, that is, it is printable and not a whitespace character.

isHexDigit

isHexDigit c (or c.isHexDigit ()) returns true if c is a hexadecimal digit.

isOctDigit

isOctDigit c (or c.isOctDigit ()) returns true if c is an octal digit (0 to 7).

isLower

isLower c (or c.isLower ()) returns true if c is a hexadecimal digit (0 to 9 or a to f or A to F).

isPrint

isPrint c (or c.isPrint ()) returns true if c is a printable character (space or visible).

isSpace

isSpace c (or c.isSpace ()) returns true if c is a whitespace character (blank, newline, tab, vertical tab, new page).

isPunct

isPunct c (or c.isPunct ()) returns true if c is a punctuation character, that is, graphical but not alphanumeric.

isUpper

isUpper c (or c.isUpper ()) returns true if c is an uppercase letter (A to Z).

toString

toString c (or c.toString ())

fromString

fromString s

fromInt

fromInt i returns SOME c, the character with code i, or NONE if i is not in the range 0 to maxOrd.

toCString

toCString c (or c.toCString ())

fromCString

fromCString s

scan

``

Not yet implemented.