Libraries
Char Source Code
 previous   up   next 

Types
char
The type char describes Unicode characters encoded with UTF-32.

char

const type: char

The type char describes Unicode characters encoded with UTF-32. A char can also contain values, which are not Unicode, like EOF.


Constant Summary
char
EOF
Character representing end-of-file.

Operator Summary
char
(attr char) . value
Default value of char (' ').
char
(attr char) . first
Minimum value of char.
char
(attr char) . last
Maximum value of an Unicode character.
boolean
(in char: ch1) = (in char: ch2)
Check if two characters are equal.
boolean
(in char: ch1) <> (in char: ch2)
Check if two characters are not equal.
boolean
(in char: ch1) < (in char: ch2)
Check if ch1 is less than ch2.
boolean
(in char: ch1) > (in char: ch2)
Check if ch1 is greater than ch2.
boolean
(in char: ch1) <= (in char: ch2)
Check if ch1 is less than or equal to ch2.
boolean
(in char: ch1) >= (in char: ch2)
Check if ch1 is greater than or equal to ch2.
char
(attr char) conv (in integer: number)
Convert an integer number to a character.
char
(attr char) parse (in string: stri)
Convert a string with a length of 1 to a character.

Function Summary
integer
compare (in char: ch1, in char: ch2)
Compare two characters.
integer
hashCode (in char: ch)
Compute the hash value of a character.
integer
ord (in char: ch)
Get the ordinal number of a character.
integer
integer (in char: ch)
Get the ordinal number of a character.
char
chr (in integer: number)
Convert an integer number to a character.
char
char (in integer: number)
Convert an integer number to a character.
char
succ (in char: ch)
Successor of a character.
char
pred (in char: ch)
Predecessor of a character.
string
str (in char: ch)
Create a string with one character.
char
upper (in char: ch)
Convert a character to upper case.
char
lower (in char: ch)
Convert a character to lower case.
boolean
isLetter (in char: ch)
Determines if the specified character ch is a letter.
integer
width (in char: ch)
Number of screen columns occupied by the Unicode character ch.
void
incr (inout char: ch)
Increment a character.
void
decr (inout char: ch)
Decrement a character.
char
rand (in char: low, in char: high)
Compute pseudo-random character in the range [low, high].
char
char (in string: stri)
Convert a string with a length of 1 to a character.
string
trimValue (attr char, in string: stri)
Trim a string such that it can be converted to char.
string
literal (in char: ch)
Conversion to a char literal.

Constant Detail

EOF

const char: EOF

Character representing end-of-file. EOF is not an Unicode character.


Operator Detail

. value

const char: (attr char) . value

Default value of char (' ').


. first

const char: (attr char) . first

Minimum value of char.


. last

const char: (attr char) . last

Maximum value of an Unicode character.


=

const func boolean: (in char: ch1) = (in char: ch2)

Check if two characters are equal.

Returns:
TRUE if both characters are equal, FALSE otherwise.

<>

const func boolean: (in char: ch1) <> (in char: ch2)

Check if two characters are not equal.

Returns:
FALSE if both characters are equal, TRUE otherwise.

<

const func boolean: (in char: ch1) < (in char: ch2)

Check if ch1 is less than ch2.

Returns:
TRUE if ch1 is less than than ch2, FALSE otherwise.

>

const func boolean: (in char: ch1) > (in char: ch2)

Check if ch1 is greater than ch2.

Returns:
TRUE if ch1 is greater than ch2, FALSE otherwise.

<=

const func boolean: (in char: ch1) <= (in char: ch2)

Check if ch1 is less than or equal to ch2.

Returns:
TRUE if ch1 is less than or equal to ch2, FALSE otherwise.

>=

const func boolean: (in char: ch1) >= (in char: ch2)

Check if ch1 is greater than or equal to ch2.

Returns:
TRUE if ch1 is greater than or equal to ch2, FALSE otherwise.

conv

const func char: (attr char) conv (in integer: number)

Convert an integer number to a character. For values between 0 and 1114111 a Unicode character is returned. For values between 1114112 and 1114500 a cursor or function key is returned. For -1 the value EOF is returned.

Returns:
a character which corresponds to the given integer.
Raises:
RANGE_ERROR - If the number does not fit into a 32-bit char.

parse

const func char: (attr char) parse (in string: stri)

Convert a string with a length of 1 to a character.

char parse "a"   returns 'a'
char parse " "   returns ' '
char parse "aa"  raises RANGE_ERROR
char parse "  "  raises RANGE_ERROR
char parse ""    raises RANGE_ERROR
Returns:
the first character of the string.
Raises:
RANGE_ERROR - If the length of the string is not 1.

Function Detail

compare

const func integer: compare (in char: ch1, in char: ch2)

Compare two characters.

Returns:
-1, 0 or 1 if the first argument is considered to be respectively less than, equal to, or greater than the second.

hashCode

const func integer: hashCode (in char: ch)

Compute the hash value of a character.

Returns:
the hash value.

ord

const func integer: ord (in char: ch)

Get the ordinal number of a character. For Unicode characters a value between 0 and 1114111 is returned. For cursor and function keys a value between 1114112 and 1114500 is returned. For EOF the value -1 is returned.

Returns:
the ordinal number of a character.

integer

const func integer: integer (in char: ch)

Get the ordinal number of a character. For Unicode characters a value between 0 and 1114111 is returned. For cursor and function keys a value between 1114112 and 1114500 is returned. For EOF the value -1 is returned.

Returns:
the ordinal number of a character.

chr

const func char: chr (in integer: number)

Convert an integer number to a character. For values between 0 and 1114111 a Unicode character is returned. For values between 1114112 and 1114500 a cursor or function key is returned. For -1 the value EOF is returned.

Returns:
a character which corresponds to the given integer.
Raises:
RANGE_ERROR - If the number does not fit into a 32-bit char.

char

const func char: char (in integer: number)

Convert an integer number to a character. For values between 0 and 1114111 a Unicode character is returned. For values between 1114112 and 1114500 a cursor or function key is returned. For -1 the value EOF is returned.

Returns:
a character which corresponds to the given integer.
Raises:
RANGE_ERROR - If the number does not fit into a 32-bit char.

succ

const func char: succ (in char: ch)

Successor of a character.

Returns:
chr(ord(ch) + 1)

pred

const func char: pred (in char: ch)

Predecessor of a character.

Returns:
chr(ord(ch) - 1)

str

const func string: str (in char: ch)

Create a string with one character.

Returns:
a string with the character ch.

upper

const func char: upper (in char: ch)

Convert a character to upper case. The conversion uses the default Unicode case mapping, where each character is considered in isolation. Characters without case mapping are left unchanged. The mapping is independent from the locale. Individual character case mappings cannot be reversed, because some characters have multiple characters that map to them.

Returns:
the character converted to upper case.

lower

const func char: lower (in char: ch)

Convert a character to lower case. The conversion uses the default Unicode case mapping, where each character is considered in isolation. Characters without case mapping are left unchanged. The mapping is independent from the locale. Individual character case mappings cannot be reversed, because some characters have multiple characters that map to them.

Returns:
the character converted to lower case.

isLetter

const func boolean: isLetter (in char: ch)

Determines if the specified character ch is a letter. A character is considered to be a letter if the category from the Unicode specification is any of the following:

  • UPPERCASE_LETTER (Lu)
  • LOWERCASE_LETTER (Ll)
  • TITLECASE_LETTER (Lt)
  • MODIFIER_LETTER (Lm)
  • OTHER_LETTER (Lo)

Examples:

isLetter('A')          returns TRUE
isLetter('\16#4e2d;')  returns TRUE
isLetter('4')          returns FALSE
isLetter('+')          returns FALSE
isLetter('\t')         returns FALSE
isLetter(KEY_LEFT)     returns FALSE
isLetter(EOF)          returns FALSE
Returns:
TRUE if ch is a letter, FALSE otherwise.

width

const func integer: width (in char: ch)

Number of screen columns occupied by the Unicode character ch. Non-spacing characters and control characters have width of 0.

width('\n')         returns 0
width('\t')         returns 0
width(KEY_LEFT)     returns 0
width(EOF)          returns 0
width('A')          returns 1
width('\16#4e2d;')  returns 2
Returns:
0,1 or 2 depending on the width occupied on a terminal.

incr

const proc: incr (inout char: ch)

Increment a character. This is equivalent to:

ch := succ(ch);

decr

const proc: decr (inout char: ch)

Decrement a character. This is equivalent to:

ch := pred(ch);

rand

const func char: rand (in char: low, in char: high)

Compute pseudo-random character in the range [low, high]. The random values are uniform distributed.

Returns:
a random character such that low <= rand(low, high) and rand(low, high) <= high holds.
Raises:
RANGE_ERROR - The range is empty (low > high holds).

char

const func char: char (in string: stri)

Convert a string with a length of 1 to a character.

char("a")   returns 'a'
char(" ")   returns ' '
char("aa")  raises RANGE_ERROR
char("  ")  raises RANGE_ERROR
char("")    raises RANGE_ERROR
Returns:
the first character of the string.
Raises:
RANGE_ERROR - If the length of the string is not 1.

trimValue

const func string: trimValue (attr char, in string: stri)

Trim a string such that it can be converted to char.

trimValue(char, " 1 ")             returns "1"
trimValue(char, "   ")             returns " "
trimValue(char, "\t ")             returns "\t"
trimValue(char, "")                returns ""
char parse trimValue(char, " 1 ")  returns '1'
char parse trimValue(char, "   ")  returns ' '
char parse trimValue(char, "\t ")  returns '\t'
char parse trimValue(char, "")     raises RANGE_ERROR
Returns:
the trimmed string.

literal

const func string: literal (in char: ch)

Conversion to a char literal.

Returns:
the character literal of ch.


 previous   up   next