next up previous index
Next: Options Up: Basic data types and Previous: Floating-point numbers   Index

Characters

In character.diesel:

Diesel characters are pretty standard. The parse_char_as_int methods convert digits (such as '0' ... '9') to integer equivalents.

extend module Stdlib;
module Character;
character is the abstract ancestor of all character-like objects. we assume that all characters can be put into a common integer coding sequence and compared based on the corresponding integer codes. this is true at least of ascii chars and unicode chars, which are the only two kinds currently supported.

abstract class character isa ordered_hashable[character];
char_code returns the integer code for the character in the ascii/unicode character set.

fun char_code(:character):int;
``Downcasters'': test whether the character is a specific kind, and/or convert down to that kind, and/or invoke a second closure (or error) if not that kind:

fun if_char(c:character, if_yes:&(char):`T, if_no:&():`T):T;
fun if_char(c:character, if_yes:&(char):void):void;
fun as_char(c:character):char;
fun is_char(c:character):bool;
end module Character;
module Char;
char represents an ASCII character.

abstract class char isa character;
Convert between characters and ascii codes:

fun from_ascii(i:int):char;  - convert from ascii code to char
fun from_ascii(i:int, if_error:&():char):char;
fun ascii_code(c:char):int;  - convert from char to ascii code (same as char_code)
Character testing behavior:

fun is_lower_case(c:char):bool;
fun is_upper_case(c:char):bool;
fun is_letter(c:char):bool;
fun is_digit(c:char):bool;
fun is_digit(c:char, base:int):bool;
fun is_octal_digit(c:char):bool;
fun is_hex_digit(c:char):bool;
fun is_alphanumeric(c:char):bool;
fun is_white(c:char):bool;
fun is_printable(c:char):bool;
Character conversion behavior:

fun as_string(c:char):string;  - convert to a string of a single character
fun to_lower_case(c:char):char;
fun to_upper_case(c:char):char;
Parsing operations to convert a digit character to the corresponding int:

fun parse_char_as_int(c:char):int;
fun parse_char_as_int(c:char, base:int | &():int):int;
fun parse_char_as_int(c:char, base:int, fail:&():int):int;
end module Char;
module Unicode;
Representation and operations for UNICODE 2-byte characters.

class unicode_char isa character;
Convert between characters and unicode codes:

  fun from_unicode(code:int):character;  - convert from unicode code to character
end module Unicode;


next up previous index
Next: Options Up: Basic data types and Previous: Floating-point numbers   Index

Cecil/Vortex Project