Sather Home Page

Section 8.3.2.4:
CHAR_CODE

immutable class CHAR_CODE < $IS_EQ, $IS_LT{CHAR_CODE},
$BINARY,$TEXT,$HASH, $NIL
$IS_EQ $IS_LT $BINARY $TEXT $HASH $NIL

Inheritance map

Formal Types

types

SAME = CHAR_CODE ;
CHAR_CODE = token ;

This class implements the concept of a character encoding which is applicable to a given culture.


External specifications

The following feature is required to be implemented for this class in accordance with the specification given in $IS_EQ :-


The following feature is required to be implemented for this class in accordance with the specification given in $IS_LT{CHAR_CODE} :-


The following feature is required to be implemented for this class in accordance with the specification given in $IS_NILof which $NIL is a sub-type :-


The following feature is required to be implemented for this class in accordance with the specification given in $NIL :-


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


The following feature is required to be implemented for this class in accordance with the specification given in $HASH :-


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


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


Reader Routines

This class has the following three reader routines -


raw_build

This version of a building feature takes the appropriate number of octets from the binary cursor buffer (defined in the lib argument) and returns the corresponding character code. It is provided for use in situations where the binary representation of a number of character codes in the same encoding is needed. The encoding can then be used once (separately) for the whole sequence.

raw_build (
cursor : BIN_CURSOR
lib : LIBCHARS
) : SAME
Formal Signature
raw_build(cursor : BIN_CURSOR, plib : LIBCHARS) res : SAME
Pre-condition
pre not BIN_CURSOR.is_done(cursor)
Post-condition
post let loc_res : seq of OCTET be st loc_res = res in
      let loc_buff = BIN_CURSOR.buffer(cursor),
            loc_idx = BIN_CURSOR.index(cursor) in
         LIBCHARS.my_size(plib) = len loc_res
            and loc_res = loc_buff((loc_idx - len loc_res), ..., loc_idx)

This routine creates a character code object from the binary string indicated by the cursor, in the given repertoire and encoding (which is not contained in the binary string)!


is_valid

This predicate returns true if and only if the given numeric argument is a valid bit-pattern for a character encoding in the given culture.

is_valid (
val : CARD,
lib : LIBCHARS
) : BOOL
Formal Signature
is_valid(val : CARD, plib : LIBCHARS) res : SAME
Pre-condition

Since this operation is a predicate then this pre-condition is vacuously true.

Post-condition

Note that this post-condition performs an abstract character code creation in order to determine if the result is in the domain of the character repertoire. Such an operation could not be performed in general with executable code. It is used solely for specification purposes.

post let loc_ch = create2(val,lib) in
      res = (loc_ch in set dom CULTURE.rep_map(LIBCHARS.culture(plib)))

This predicate returns true if and only if the bit-pattern of the numeric argument forms a valid character code in the given cultural repertoire.


create

This feature creates a character code from the given binary string. There should be no cultural indicator(s) in the binary string which is expected to ba a 'raw' bit-patterns containing exactly the number of octets specified by the lib argument.

create (
str : BINSTR,
lib : LIBCHARS
) : SAME
Formal Signature
create(str : BINSTR, plib : LIBCHARS) res : SAME
Pre-condition
pre len str = LIBCHARS.my_size(plib)
Post-condition
post let loc_res : seq of OCTET be st loc_res = res in
      loc_res = str
         and lib(res) = plib

This feature creates a code object from the given binary string which contains no culture-defining component(s).


create

This feature creates a character code from the given numeric value, used as a bit-pattern.

create (
val : CARD,
lib : LIBCHARS
) : SAME
Formal Signature
create2(val : CARD, plib : LIBCHARS) res : SAME
Pre-condition
pre is_valid(val, plib)
Post-condition
post let loc_res : seq of OCTET be st loc_res = res in
      loc_res = CARD.binstr(val)(1, ..., LIBCHARS.my_size(plib))
         and lib(res) = plib

This feature creates a new character code which has the bit-pattern representation which is the same as the value given.


create

This feature creates a character code from the given character which is assumed to be a correct value for the encoding and repertoire specified by the lib argument. This assumption cannot in general be proved!

create (
ch : CHAR,
lib : LIBCHARS
) : SAME
Formal Signature
create3(ch : CHAR, plib : LIBCHARS) res : SAME
Pre-condition

Since neither argument is optional then this pre-condition is vacuously true.

Post-condition
post let loc_res : seq of OCTET be st loc_res = res in
      loc_res = CHAR.binstr(ch)(1, ..., LIBCHARS.my_size(plib))
         and lib(res) = plib

This feature creates a new character code which has the bit-pattern representation which is the same as the value given.


is_combining

This predicate returns true only if self is a combvining code as defined in ISO/IEC 10646-1:2000 (see also Unicode version 3.1)

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

Since this feature is a predicate and the argument is not optional then this pre-condition is vacuously true.

Post-condition
post res = (self in set dom UNICODE.Combining)

This predicate returns true if and only if self is a combining encoding in the Unicode domain.


raw_binstr

This feature corresponds to the 'raw' building routine, the result having no cultural coding, etc information.

raw_binstr : BINSTR
Formal Signature
raw_binstr(self : SAME) res : BINSTR
Pre-condition

Since the argument is not optional then this pre-condition is vacuously true.

Post-condition
post build(res,lib) = self

This feature returns the binary string representation of self which contains no encoding or re[ertoire information.


card

This feature produces the cardinal number represented by the encoding of this character.

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

Since the argument is not optional then this pre-condition is vacuously true.

Post-condition
post create(res,lib) = self

This feature returns the cardinal number which is represented by the encoding of this character code.


char

This feature produces the character corresponding to self as a charcater code. Doing this results in dissociating the cultural data from the character.

char : CHAR
Formal Signature
char(self : SAME) res : CHAR
Pre-condition

Since the argument is not optional then this pre-condition is vacuously true.

Post-condition

The use of this routine results in the loss of associated cultural information.

post create(res,lib) = self

This feature returns the character, the encoding of which is represented by self.


rune

This feature produces the singly coded rune corresponding to self as a charcater code.

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

Since the argument is not optional then this pre-condition is vacuously true.

Post-condition
post create(res,lib) = self

This feature returns the rune, the single encoding of which is represented by self.


next

This successor routine is provided to enable simple sequential character encoding operations to be carried out. Note that the successor of the bit-pattern with the highest number of bits set (as defined in the Unicode standard) is that with no bits set as the semantics attributed are those of the closed field class FIELD.

next : SAME
Formal Signature
next(self : SAME) res : SAME
Pre-condition

Since the argument is not optional then this pre-condition is vacuously true.

Post-condition

The use of this routine results in the loss of associated cultural information.

post let loc_max = UNICODE.card(UNICODE.Invalid) - 1 in
         ((card(self) = loc_max)
            and (card(res) = 0))
      or card(res) = card(self) + 1


offset

This routine returns a new character code the corresponding cardinal number for which is offset by the given argument count.

offset (
cnt : INT
) : SAME
Formal Signature
offset(self : SAME, cnt : INT) res : SAME
Pre-condition
pre let loc_max = UNICODE.card(UNICODE.Invalid) - 1 in
      let loc_res =
           cases :
         (card(self) + cnt > loc_max) -> card(self) - loc_max + cnt,
         (card(self) + cnt < 0) -> card(self) + loc_max + cnt,
         others -> card(self) + cnt
            end in
               UNICODE.create(loc_res) in set dom UNICODE.Code_Groups 
Post-condition
post let loc_max = UNICODE.card(UNICODE.Invalid) - 1 in
         ((card(self) + cnt > loc_max)
            and (card(res) = card(self) + cnt - loc_max))
      or ((card(self) + cnt < 0)
            and (card(res) = card(self) + loc_max + cnt))
      or card(res) = card(self) + cnt

This routine returns the ccharaccter code which is count positions before/after self provided that such a code exists.

octet!

This iter yields in sequence the individual octets which make up self - from the most significant group of eight downwards.

octet! : OCTET
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.

octet_iter(self : SAME) res : OCTET
Pre-condition
pre len history mod 8 = 0
Post-condition

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

post let loc_res : seq of BIT be st
         (res = loc_res
            and len loc_res = 8) in
               let loc_size = LIBCHARS.my_size(lib(self)) in
      ((history~ = []
         and (history = loc_res))
      or (history = history ^ loc_res))
         and loc_res = self((loc_size - len history), ..., (loc_size - len history~))
Quit condition

For quit actions see the specification of the quit statement.

errs QUIT : len history~ = len self -> quit

This iter yields in turn the sequence of octets making up self, starting with the most significant group of eight bits.

octet!

This iter yields in sequence cnt individual octets which make up self - finishing with the least significant group of eight.

octet! (
once cnt : CARD
) : OCTET
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.

octet_iter2(self : SAME, cnt : CARD) res : OCTET
Pre-condition
pre len history mod 8 = 0
      and (cnt <= LIBCHARS.my_size(lib(self)))
Post-condition

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

post let loc_res : seq of BIT be st
         (loc_res = res
            and len loc_res = 8) in
      ((history~ = []
         and (history = loc_res))
      or (history = history ^ loc_res))
         and loc_res = self((cnt - len history), ..., (loc_size - len history~))
Quit condition

For quit actions see the specification of the quit statement.

errs QUIT : len history~ = len self -> quit

This iter yields in turn a sequence of cnt octets making up self, ending with the least significant group of eight bits.


Language Index Library Index Codes Index
Comments or enquiries should be made toKeith Hopper.
Page last modified: Monday, 23 April 2001.
Produced with Amaya