# Section 8.17.2.1:
CHAR

###### immutable class CHAR < $CHAR{SAME}

#### Formal Types

types
SAME = CHAR ;
CHAR = char

This class implements the notion of a logical character which has the semantics associated with such a token in the cultural environment concerned and which has a single encoding!

NOTE | For characters which require multiple encodings see the class RUNE in this section of the required library.

#### External specifications

The following feature is required to be implemented for this class in accordance with the specification given in $IS_EQ of which $CHAR{CHAR} is a sub-type :-

- is_eq(other : SAME) : BOOL

The following feature is required to be implemented for this class in accordance with the specification given in $IS_LT{CHAR} of which $CHAR{CHAR} is a sub-type :-

- is_lt(other : SAME) : BOOL

The following features are required to be implemented for this class in accordance with the specifications given by inheritance in $STR of which $CHAR{CHAR} is a sub-type :-

- str(lib : LIBCHARS) : STR
- str : STR

The following feature is required to be implemented for this class in accordance with the specification given in $HASH of which $CHAR{CHAR} is a sub-type :-

- hash : CARD

The following features are required to be implemented for this class in accordance with the specifications given in $BINARY of which $CHAR{CHAR} is a sub-type :-

- create(storage : BINSTR) : SAME
- build(cursor : BIN_CURSOR) : SAME
- read(cursor : BIN_CURSOR) : SAME
- binstr : BINSTR
- write(fyle : BIN_FILE)

The following features are required to be implemented for this class in accordance with the specifications given in $INSTR of which $CHAR{CHAR} is a sub-type :-

- build(cursor : STR_CURSOR) : SAME
- build(cursor : STR_CURSOR, lib : LIBCHARS) : SAME

The following features are required to be implemented for this class in accordance with the specifications given in $ANCHORED_FMT of which $CHAR{CHAR} is a sub-type :-

- fmt(descr : ANCHORED_DESCR) : SAME
- fmt(descr : ANCHORED_DESCR, lib : LIBCHARS) : SAME

The following features are required to be implemented for this class in accordance with the specifications given in $CHAR{CHAR} :-

- create(ch_code : CHAR_CODE) : SAME
- create(ch_code : CHAR_CODE, lib : LIBCHARS) : SAME
- char : SAME
- code(lib : LIBCHARS) : CHAR_CODE
- code : CHAR_CODE
- rune(lib : LIBCHARS) : RUNE
- rune : RUNE
- is_alpha(lib : LIBCHARS) : BOOL
- is_alpha : BOOL
- is_upper(lib : LIBCHARS) : BOOL
- is_upper : BOOL
- is_lower(lib : LIBCHARS) : BOOL
- is_lower : BOOL
- is_octal_digit(lib : LIBCHARS) : BOOL
- is_octal_digit : BOOL
- is_digit(lib : LIBCHARS) : BOOL
- is_digit : BOOL
- is_hex_digit(lib : LIBCHARS) : BOOL
- is_hex_digit : BOOL
- is_numeric(lib : LIBCHARS) : BOOL
- is_numeric : BOOL
- is_alphanum(lib : LIBCHARS) : BOOL
- is_alphanum : BOOL
- is_space(lib : LIBCHARS) : BOOL
- is_space : BOOL
- is_print(lib : LIBCHARS) : BOOL
- is_print : BOOL
- is_punct(lib : LIBCHARS) : BOOL
- is_punct : BOOL
- is_control(lib : LIBCHARS) : BOOL
- is_control : BOOL
- num_codes : CARD
- upper(lib : LIBCHARS) : SAME
- upper : SAME
- lower(lib : LIBCHARS) : SAME
- lower : SAME
- octal_digit_value(lib : LIBCHARS) : CARD
- octal_digit_value : CARD
- digit_value(lib : LIBCHARS) : CARD
- digit_value : CARD
- hex_digit_value(lib : LIBCHARS) : CARD
- hex_digit_value : CARD
- code!(lib : LIBCHARS) : CHAR_CODE
- code! : CHAR_CODE

#### valid

This predicate is provided in order that the validity of the 'number' as a bit-pattern for a code may be ascertained - in respect to the given encoding and repertoire.

valid | (
| num : CARD,
| lib : LIBCHARS
| ) : BOOL

##### Formal Signature

valid(num : CARD, lib : LIBCHARS) res : BOOL

##### Pre-condition

pre true

##### Post-condition

Note that where the code is to occupy eight bits only then all values are valid, but that for sixteen bit codes all values except the one with all bits set is valid - and for thirty-two bit codes only 31 bits are used and then the value with 31 bits set is not valid.

post res =
cases LIBCHARS.my_size(lib) :
1 -> num <= OCTET.Octet_Max,
2 -> num < HEXTET.Hextet_Max,
4 -> num <= QUADBITS.Quad_Max div 2
end

This routine returns true if and only if the value of num may be interpreted as a character bit-pattern valid in the given encoding and repertoire, otherwise false.

#### valid

This predicate is provided in order that the validity of the 'number' as a bit-pattern for a code may be ascertained - in respect to the default encoding and repertoire.

valid | (
| num : CARD
| ) : BOOL

##### Formal Signature

valid(num : CARD) res : BOOL

##### Pre-condition

pre true

##### Post-condition

Note that where the code is to occupy eight bits only then all values are valid, but that for sixteen bit codes all values except the one with all bits set is valid - and for thirty-two bit codes only 31 bits are used and then the value with 31 bits set is not valid.

post res =
cases LIBCHARS.my_size(LIBCHARS.default()) :
1 -> num <= OCTET.Octet_Max,
2 -> num < HEXTET.Hextet_Max,
4 -> num <= QUADBITS.Quad_Max div 2
end

This routine returns true if and only if the value of num may be interpreted as a character bit-pattern valid in the default execution environment encoding and repertoire, otherwise false.

#### convert

This routine attempts to convert self - in the from_lib encoding - into the to_lib encoding if this is possible, otherwise void is returned.

convert | (
| from_lib : LIBCHARS,
| to_lib : LIBCHARS
| ) : SAME

##### Formal Signature

convert(self : SAME, from_lib : LIBCHARS, to_lib : LIBCHARS) res : [SAME]

##### Pre-condition

pre true

##### Post-condition

post convert(res,to_lib,from_lib) = self
or res = nil

This routine converts self, which is assumed to be in the encoding and repertoire specified by the from_lib argument, into the encoding specified by to_lib - if this is possible, otherwise returning void.

#### convert

This routine attempts to convert self, which is presumed to be in the current default encoding into the encoding specified by the argument if this is possible, otherwise void is returned.

convert | (
| lib : LIBCHARS
| ) : SAME

##### Formal Signature

convert(self : SAME, lib : LIBCHARS) res : [SAME]

##### Pre-condition

pre true

##### Post-condition

post convert(res,LIBCHARS.default(),lib) = self
or res = nil

This routine converts self, which is assumed to be in the default execution environment encoding and repertoire, into the encoding specified by lib - if this is possible, otherwise returning void.

| Language Index |  | Library Index |  | Text Index

Comments or enquiries should be made to Keith Hopper. Page last modified: Thursday, 23 November 2000. |