Sather Home Page

Section 8.17.1.1:
$CHAR

abstract class $CHAR{TP} < $IS_EQ, $IS_LT{TP},
$HASH,$IMMUTABLE, $ANCHORED_FMT

Inheritance map $IS_EQ $IS_LT $HASH $IMMUTABLE $INSTR $ANCHORED_FMT $FMT $BINARY $STR

Formal Definitions

This abstract class defines a state component which is a set of all instantiations of objects of any class sub-typing from this class in addition to the vdm model types used wherever this class name is used. Note that SAME has to be an instantiated class, not an abstract one.

types

SAME = Object_Type ;

$CHAR_TP = set of Object_Type

Object_Type = seq1 of CHAR_CODE ;

state

multi : $CHAR_TP
inv multi_types ==
forall obj in set multi_types & sub_type($CHAR_TP,obj)
NOTES 1. See the important note about vdm state in the notes on vdm-sl usage in this specification.
2. The vdm type Object_Type is defined solely in order to be able to specify the iterators at the end of this class definition. It is otherwise not used.

This abstraction models the semantic notion of a character, ascribing to it all of those features which are not dependent upon any particular form of representation. One additional feature is, however, modelled - that a character is represented by one or more encodings - the class CHAR_CODE.


create

A character is created by this routine from the given code - which may be considered as some bit-pattern. The character, however, has all of the semantics associated with characters in human communication.

create (
ch_code : CHAR_CODE
) : SAME
Formal Signature
create(ch_code : CHAR_CODE) res : SAME
Pre-condition
pre not UNICODE.is_combining(UNICODE.create(CHAR_CODE.card(code)))
Post-condition
post code(res,CHAR_CODE.lib(ch_code)) = ch_code

This routine creates a character from a single character code - which must not be a combining code as specified in ISO/IEC 10646-1:2000.


create

A character is created by this routine from the given control function name (as a code) - which may be considered as some bit-pattern. The resultant pseudo-character, however, has semantics associated with that control function in a rendering engine dependent manner. The given repertoire and encoding is needed to convert the bit-pattern of a control code into an appropriate pattern for the culture concerned. These differ principally in the number of bits needed.

create (
function : CONTROL_CODES,
lib : LIBCHARS
) : SAME
Formal Signature
create2(function : CONTROL_CODES, lib : LIBCHARS) res : SAME
Pre-condition

Since this is a creation routine with a larger range than the domain of control codes, the pre-condition is vacuously true.

Post-condition
post CONTROL_CODES.create(CHAR_CODE.card(code(res,CHAR_CODE.lib(code)))) = function

This routine creates a 'character' from the given control function name and repertoire and encoding. The result is a pseudo-character which may be interpreted in some rendering engine specific manner.


char

Providing that self consists of only a single encoding this routine returns the corresponding single code character.

char : CHAR
Formal Signature
char(self : SAME) res : CHAR
Pre-condition
pre num_codes(self) = 1
Post-condition
post create(code(res)) = self

This routine returns the single coding character corresponding to self.


code

This is the first of two features which convert self into a character code - providing that it consists of only one encoding.

code (
lib : LIBCHARS
) : CHAR_CODE
Formal Signature
code(self : SAME, lib : LIBCHARS) res : CHAR_CODE
Pre-condition
pre num_codes(self) = 1
Post-condition
post create(res) = self

This routine returns the encoding corresponding to the single element of self, using the given encoding and repertoire.


code

This version of the conversion feature for turning self into a character code makes use of the default execution environment encoding and repertoire.

code : CHAR_CODE
Formal Signature
code2(self : SAME) res : CHAR_CODE
Pre-condition
pre num_codes(self) = 1
Post-condition
post create(res) = self

This routine returns the encoding corresponding to the single element of self, using the default execution environment encoding and repertoire.


rune

This is the first of two features which convert self into a rune (which may have multiple encodings).

rune (
lib : LIBCHARS
) : RUNE
Formal Signature
rune(self : SAME, lib : LIBCHARS) res : RUNE
Pre-condition

Since the range of the result is at least as large as the domain of self, the pre-condition is vacuously true.

Post-condition
post self = create(code(res))

This routine returns the encoding corresponding to the single element of self, using the given encoding and repertoire.


rune

This version of the conversion feature for turning self into a rune makes use of the default execution environment encoding and repertoire.

rune : RUNE
Formal Signature
rune2(self : SAME) res : RUNE
Pre-condition

Since the range of the result is at least as large as the domain of self, the pre-condition is vacuously true.

Post-condition
post create(res) = self

This routine returns the rune corresponding to the single element of self, using the default execution environment encoding and repertoire.


is_alpha

This feature returns true if and only if self is a letter as defined in the given encoding and repertoire.

is_alpha (
lib : LIBCHARS
) : BOOL
Formal Signature
is_alpha(self : SAME, lib : LIBCHARS) res : BOOL
Pre-condition

Since this feature is a predicate, the pre-condition is vacuously true.

Post-condition

Since this feature is a predicate, the post-condition also is vacuously true.

This predicate returns true if and only if self is a member of the value domain of letters as specified for the given encoding and repertoire.


is_alpha

This version of the predicate returns true if self is a letter in the default execution environment.

is_alpha : BOOL
Formal Signature
is_alpha2(self : SAME) res : BOOL
Pre-condition

Since this feature is a predicate, the pre-condition is vacuously true.

Post-condition

Since this feature is a predicate, the post-condition also is vacuously true.

This routine returns true if and only if the values of self is a member of the domain of letters as defined in the default execution environment.


is_upper

This feature returns true if and only if self is an upper case letter as defined in the given encoding and repertoire.

is_upper (
lib : LIBCHARS
) : BOOL
Formal Signature
is_upper(self : SAME, lib : LIBCHARS) res : BOOL
Pre-condition

Since this feature is a predicate, the pre-condition is vacuously true.

Post-condition

Since this feature is a predicate, the post-condition also is vacuously true.

This predicate returns true if and only if self is a member of the value domain of upper case letters as specified for the given encoding and repertoire.


is_upper

This version of the predicate returns true if self is an upper case letter in the default execution environment.

is_upper : BOOL
Formal Signature
is_upper2(self : SAME) res : BOOL
Pre-condition

Since this feature is a predicate, the pre-condition is vacuously true.

Post-condition

Since this feature is a predicate, the post-condition also is vacuously true.

This routine returns true if and only if the value of self is a member of the domain of upper case letters as defined in the default execution environment.


is_lower

This feature returns true if and only if self is a lower case letter as defined in the given encoding and repertoire.

is_lower (
lib : LIBCHARS
) : BOOL
Formal Signature
is_lower(self : SAME, lib : LIBCHARS) res : BOOL
Pre-condition

Since this feature is a predicate, the pre-condition is vacuously true.

Post-condition

Since this feature is a predicate, the post-condition also is vacuously true.

This predicate returns true if and only if self is a member of the value domain of lower case letters as specified for the given encoding and repertoire.


is_lower

This version of the predicate returns true if self is a lower case letter in the default execution environment.

is_lower : BOOL
Formal Signature
is_lower2(self : SAME) res : BOOL
Pre-condition

Since this feature is a predicate, the pre-condition is vacuously true.

Post-condition

Since this feature is a predicate, the post-condition also is vacuously true.

This routine returns true if and only if the value of self is a member of the domain of lower case letters as defined in the default execution environment.


is_octal_digit

This feature returns true if and only if self is an octal digit as defined in the given encoding and repertoire.

is_octal_digit (
lib : LIBCHARS
) : BOOL
Formal Signature
is_octal_digit(self : SAME, lib : LIBCHARS) res : BOOL
Pre-condition

Since this feature is a predicate, the pre-condition is vacuously true.

Post-condition

Since this feature is a predicate, the post-condition also is vacuously true.

This predicate returns true if and only if self is a member of the value domain of octal digit characters as specified for the given encoding and repertoire.


is_octal_digit

This version of the predicate returns true if self is an octal digit in the default execution environment.

is_octal_digit : BOOL
Formal Signature
is_octal_digit2(self : SAME) res : BOOL
Pre-condition

Since this feature is a predicate, the pre-condition is vacuously true.

Post-condition

Since this feature is a predicate, the post-condition also is vacuously true.

This routine returns true if and only if the value of self is a member of the domain of octal digit characters as defined in the default execution environment.


is_digit

This feature returns true if and only if self is a decimal digit as defined in the given encoding and repertoire.

is_digit (
lib : LIBCHARS
) : BOOL
Formal Signature
is_digit(self : SAME, lib : LIBCHARS) res : BOOL
Pre-condition

Since this feature is a predicate, the pre-condition is vacuously true.

Post-condition

Since this feature is a predicate, the post-condition also is vacuously true.

This predicate returns true if and only if self is a member of the value domain of decimal digit characters as specified for the given encoding and repertoire.


is_digit

This version of the predicate returns true if self is a decimal digit in the default execution environment.

is_digit : BOOL
Formal Signature
is_digit2(self : SAME) res : BOOL
Pre-condition

Since this feature is a predicate, the pre-condition is vacuously true.

Post-condition

Since this feature is a predicate, the post-condition also is vacuously true.

This routine returns true if and only if the value of self is a member of the domain of decimal digit characters as defined in the default execution environment.


is_hex_digit

This feature returns true if and only if self is a hexa-decimal digit as defined in the given encoding and repertoire.

is_hex_digit (
lib : LIBCHARS
) : BOOL
Formal Signature
is_hex_digit(self : SAME, lib : LIBCHARS) res : BOOL
Pre-condition

Since this feature is a predicate, the pre-condition is vacuously true.

Post-condition

Since this feature is a predicate, the post-condition also is vacuously true.

This predicate returns true if and only if self is a member of the value domain of hexadecimal digit characters as specified for the given encoding and repertoire.


is_hex_digit

This version of the predicate returns true if self is a hexadecimal digit in the default execution environment.

is_hex_digit : BOOL
Formal Signature
is_hex_digit2(self : SAME) res : BOOL
Pre-condition

Since this feature is a predicate, the pre-condition is vacuously true.

Post-condition

Since this feature is a predicate, the post-condition also is vacuously true.

This routine returns true if and only if the value of self is a member of the domain of hexadecimal digit characters as defined in the default execution environment.


is_numeric

This feature returns true if and only if self is a number character as defined in the given encoding and repertoire. Note, particularly, that while this domain will usually include decimal digits that it is not restricted to characters which may be converted directly to numbers and used in arithmetic operations.

is_numeric (
lib : LIBCHARS
) : BOOL
Formal Signature
is_numeric(self : SAME, lib : LIBCHARS) res : BOOL
Pre-condition

Since this feature is a predicate, the pre-condition is vacuously true.

Post-condition

Since this feature is a predicate, the post-condition also is vacuously true.

This predicate returns true if and only if self is a member of the value domain of number characters as specified for the given encoding and repertoire.


is_numeric

This version of the predicate returns true if self is a number character in the default execution environment. Note, particularly that characters which belong to this group will almost certainly include, but by no means be restricted to those which may take part in arithmetic operations.

is_numeric : BOOL
Formal Signature
is_numeric2(self : SAME) res : BOOL
Pre-condition

Since this feature is a predicate, the pre-condition is vacuously true.

Post-condition

Since this feature is a predicate, the post-condition also is vacuously true.

This routine returns true if and only if the value of self is a member of the domain of number characters as defined in the default execution environment.


is_alphanum

This feature returns true if and only if self is an alpha-numeric character as defined in the given encoding and repertoire. Note, particularly, that while this domain will usually include characters of the classes alpha and digits, it may not be assumed that such characters are the only members of this class domain.

is_alphanum (
lib : LIBCHARS
) : BOOL
Formal Signature
is_alphanum(self : SAME, lib : LIBCHARS) res : BOOL
Pre-condition

Since this feature is a predicate, the pre-condition is vacuously true.

Post-condition

Since this feature is a predicate, the post-condition also is vacuously true.

This predicate returns true if and only if self is a member of the value domain of alpha-numeric characters as specified for the given encoding and repertoire.


is_alphanum

This version of the predicate returns true if self is an alpha-numeric character in the default execution environment. Note, particularly that characters which belong to this group will almost certainly include, but by no means be restricted to, characters belonging to the classes alpha and digit.

is_alphanum : BOOL
Formal Signature
is_alphanum2(self : SAME) res : BOOL
Pre-condition

Since this feature is a predicate, the pre-condition is vacuously true.

Post-condition

Since this feature is a predicate, the post-condition also is vacuously true.

This routine returns true if and only if the value of self is a member of the domain of alpha-numeric characters as defined in the default execution environment.


is_space

This feature returns true if and only if self is a white space character as defined in the given encoding and repertoire. Note, particularly, that this class may include control function name codes.

is_space (
lib : LIBCHARS
) : BOOL
Formal Signature
is_space(self : SAME, lib : LIBCHARS) res : BOOL
Pre-condition

Since this feature is a predicate, the pre-condition is vacuously true.

Post-condition

Since this feature is a predicate, the post-condition also is vacuously true.

This predicate returns true if and only if self is a member of the value domain of space characters (characters which, when rendered, occupy space in the image but have no visible glyph) as specified for the given encoding and repertoire.


is_space

This version of the predicate returns true if self is a white space character which has no visible mark in the default execution environment. Note, particularly that characters which belong to this group may include control function name codes.

is_space : BOOL
Formal Signature
is_space2(self : SAME) res : BOOL
Pre-condition

Since this feature is a predicate, the pre-condition is vacuously true.

Post-condition

Since this feature is a predicate, the post-condition also is vacuously true.

This routine returns true if and only if the value of self is a member of the domain of space characters (characters which occupy space when rendered but do not have a visible glyph) as defined in the default execution environment.


is_print

This feature returns true if and only if self is a character which, when rendered is visible as defined in the given encoding and repertoire.

is_print (
lib : LIBCHARS
) : BOOL
Formal Signature
is_print(self : SAME, lib : LIBCHARS) res : BOOL
Pre-condition

Since this feature is a predicate, the pre-condition is vacuously true.

Post-condition

Since this feature is a predicate, the post-condition also is vacuously true.

This predicate returns true if and only if self is a member of the value domain of characters which, when rendered, have a visible image as specified for the given encoding and repertoire.


is_print

This version of the predicate returns true if self is a character which has a visible mark when rendered in the default execution environment.

is_print : BOOL
Formal Signature
is_print2(self : SAME) res : BOOL
Pre-condition

Since this feature is a predicate, the pre-condition is vacuously true.

Post-condition

Since this feature is a predicate, the post-condition also is vacuously true.

This routine returns true if and only if the value of self is a member of the domain of characters which, when rendered, have a visible glyph as defined in the default execution environment.


is_punct

This feature returns true if and only if self is a character which is defined as a punctuation mark in the given encoding and repertoire. Note that, while this will not includes characters detected as being letter, numbers and whitespace using the predicates above, it will not necessarily include all other visible characters.

is_punct (
lib : LIBCHARS
) : BOOL
Formal Signature
is_punct(self : SAME, lib : LIBCHARS) res : BOOL
Pre-condition

Since this feature is a predicate, the pre-condition is vacuously true.

Post-condition

Since this feature is a predicate, the post-condition also is vacuously true.

This predicate returns true if and only if self is a member of the domain of characters which are defined as punctuation marks for the given encoding and repertoire.


is_punct

This version of the predicate returns true if self is a character which is defined as a punctuation mark in the default execution environment. Note that while this will not include letters, numbers and spcae as detected using the above predicates, there may be other visible characters which are not in this domain.

is_punct : BOOL
Formal Signature
is_punct2(self : SAME) res : BOOL
Pre-condition

Since this feature is a predicate, the pre-condition is vacuously true.

Post-condition

Since this feature is a predicate, the post-condition also is vacuously true.

This routine returns true if and only if the value of self is a member of the domain of characters which are defined as punctuation marks in the default execution environment.


is_control

This routine returns true if self is the code name of a control function in the given encoding and repertoire. Note that all internationally standardised encodings have the identical code names as defined by ISO 636. (see also the library class CONTROL_CODES).

is_control (
lib : LIBCHARS
) : BOOL
Formal Signature
is_control(self : SAME, lib : LIBCHARS) res : BOOL
Pre-condition

Since this feature is a predicate, the pre-condition is vacuously true.

Post-condition

Since this feature is a predicate, the post-condition also is vacuously true.

This predicate returns true if and only if self is a member of the domain of characters which are defined as punctuation marks for the given encoding and repertoire.


is_control

This version of the predicate returns true if self is the code name of a control function in the default encoding and repertoire. Note that all internationally standardised encodings have the identical code names as defined by ISO 636.

is_control : BOOL
Formal Signature
is_control2(self : SAME) res : BOOL
Pre-condition

Since this feature is a predicate, the pre-condition is vacuously true.

Post-condition

Since this feature is a predicate, the post-condition also is vacuously true.

This routine returns true if and only if the value of self is the code name of a control function in the default execution environment.


num_codes

This routine returns the count of encodings in self. As given in ISO/IEC 10646, this will not exceed six.

num_codes : CARD
Formal Signature
num_codes(self : SAME) res : CARD
Pre-condition

Since the range of the result is greater than the range of components, the pre-condition is vacuously true.

Post-condition
post res > 0
and res <= 6

This routine returns the count of the number of encodings in self.


upper

This routine returns the upper case character corresponding to self if this exists, otherwise self. Note that there is not necessarily an upper case letter corresponding to every lower case letter (for example in the ISO 8859-1 encoding the letter "ß" is lower case but has no single character upper case equivalent).

upper (
lib : LIBCHARS
) : SAME
Formal Signature
upper(self : SAME, lib : LIBCHARS) res : SAME
Pre-condition

Since this feature is a predicate, the pre-condition is vacuously true.

Post-condition
post lower(res,lib) = self)
or res = self

This routine returns the upper case character corresponding to self if it exists, otherwise self.


upper

This routine returns the upper case character corresponding to the given lower case letter if this exists, otherwise self.

upper : SAME
Formal Signature
upper2(self : SAME) res : SAME
Pre-condition

Since the domain of self and of other are identical, the pre-condition is vacuously true.

Post-condition
post lower(res) = self)
or res = self

This routine returns the upper case character corresponding to self in the default encoding and repertoire, provided that self is a lower case letter - otherwise self is returned.


lower

This routine returns the lower case character corresponding to self if this exists, otherwise self. Note that there is not necessarily a lower case letter corresponding to every upper case letter.

lower (
lib : LIBCHARS
) : SAME
Formal Signature
lower(self : SAME, lib : LIBCHARS) res : SAME
Pre-condition

Since this feature is a predicate, the pre-condition is vacuously true.

Post-condition
post upper(res,lib) = self)
or res = self

This routine returns the lower case character corresponding to self if it exists, otherwise self.


lower

This routine returns the lower case character corresponding to the given upper case letter if this exists, otherwise self.

lower : SAME
Formal Signature
lower2(self : SAME) res : SAME
Pre-condition

Since the domain of self and of other are identical, the pre-condition is vacuously true.

Post-condition
post upper(res) = self)
or res = self

This routine returns the lower case character corresponding to self in the default encoding and repertoire, provided that self is an upper case letter and the equivalent character is mapped - otherwise self is returned.


octal_digit_value

This routine returns the numeric value represented by self as an octal digit in the given repertoire and encoding.

octal_digit_value (
lib : LIBCHARS
) : SAME
Formal Signature
octal_digit_value(self : SAME, lib : LIBCHARS) res : CARD
Pre-condition
pre true
Post-condition
post (is_octal_digit(self,lib)
and create(CHAR_CODE.create(res,lib),lib) = self)
or res = CARD.maxval

This routine returns the numeric value corresponding to self, provided that it is an octal digit, otherwise CARD::maxval.


octal_digit_value

This routine returns the numeric value represented by self, if self is an octal digit.

octal_digit_value : CARD
Formal Signature
octal_digit_value2(self : SAME) res : CARD
Pre-condition
pre true
Post-condition
post (is_octal_digit(self)
and create(CHAR_CODE.create(res)) = self)
or res = CARD.maxval

This routine returns the numeric value which is represented by the octal digit character self if this exists, otherwise CARD::maxval.


digit_value

This routine returns the numeric value represented by self as a decimal digit in the given repertoire and encoding.

digit_value (
lib : LIBCHARS
) : SAME
Formal Signature
digit_value(self : SAME, lib : LIBCHARS) res : CARD
Pre-condition
pre true
Post-condition
post (is_digit(self,lib)
and create(CHAR_CODE.create(res,lib),lib) = self)
or res = CARD.maxval

This routine returns the numeric value corresponding to self, provided that it is a decimal digit, otherwise CARD::maxval.


digit_value

This routine returns the numeric value represented by self, if self is a decimal digit.

digit_value : CARD
Formal Signature
digit_value2(self : SAME) res : CARD
Pre-condition
pre true
Post-condition
post (is_digit(self)
and create(CHAR_CODE.create(res)) = self)
or res = CARD.maxval

This routine returns the decimal numeric value of the digit which is represented by the character self if this exists, otherwise CARD::maxval.


hex_digit_value

This routine returns the numeric value represented by self as a hexa-decimal digit in the given repertoire and encoding.

hex_digit_value (
lib : LIBCHARS
) : SAME
Formal Signature
hex_digit_value(self : SAME, lib : LIBCHARS) res : CARD
Pre-condition
pre true
Post-condition
post (is_hex_digit(self,lib)
and create(CHAR_CODE.create(res,lib),lib) = self)
or res = CARD.maxval

This routine returns the numeric value corresponding to self, provided that it is a hexa-decimal digit, otherwise CARD::maxval.


hex_digit_value

This routine returns the numeric value represented by self, if self is a hexa-decimal digit.

hex_digit_value : CARD
Formal Signature
hex_digit_value2(self : SAME) res : CARD
Pre-condition
pre true
Post-condition
post (is_hex_digit(self)
and create(CHAR_CODE.create(res)) = self)
or res = CARD.maxval

This routine returns the hexa-decimal numeric value of the digit which is represented by the character self if this exists, otherwise CARD::maxval.


code!

This iter yields successive encodings of self in the given encoding and repertoire.

code! (
once lib : LIBCHARS
) : CHAR_CODE
Formal Signature

Note that the formal name of the iter has been changed to replace the exclamation mark iter symbol to a name acceptable to vdm tools.

code_iter(self : SAME, lib : LIBCHARS) res : CHAR_CODE
Pre-condition
pre true
Post-condition

This post-condition makes use of the history concept from vdm++ (see the vdm dialect notes).

post history~ = [] and res = self(1)
and history = [res])

or (res = self(len history)
and history = history~ ^ res)
Quit condition

For quit actions see the specificatiion of the quit statement.

errs QUIT : len history = len self -> quit

This iter yields successive encodings of self in the given encoding and repertoire.


code!

This iter yields successive encodings of self in the default execution environment encoding and repertoire.

code! : CHAR_CODE
Formal Signature

Note that the formal name of the iter has been changed to replace the exclamation mark iter symbol to a name acceptable to vdm tools.

code2_iter(self : SAME) res : CHAR_CODE
Pre-condition
pre true
Post-condition

This post-condition makes use of the history concept from vdm++ (see the vdm dialect notes).

post history~ = [] and res = self(1)
and history = [res])

or (res = self(len history)
and history = history~ ^ res)
Quit condition

For quit actions see the specificatiion of the quit statement.

errs QUIT : len history = len self -> quit

This iter yields successive encodings of self in the default execution environment encoding and repertoire.


Language Index Library Index Text Index
Comments or enquiries should be made to Keith Hopper.
Page last modified: Thursday, 23 November 2000.
Produced with Amaya