Sather Home Page

Section 8.3.2.9:
UTF7

immutable class UTF7 < $IS_EQ
$IS_EQ

Inheritance map

Formal Types

types

SAME = UTF7 ;
UTF7 = token ;

This class provides for conversion of encoding sequences (ie text strings in some encoding) to a sequence of one or more octets in which a clear octet is only found when the original encoding was void.

The algorithm provided is designed to achieve the translation given in the following table in which v signifies a value bit of the original code.

Bits Hex Min Hex Max Octet Sequence in Binary
 7 00000000 0000007F 0vvvvvvv
11 00000080 000007FF 110vvvvv 10vvvvvv
16 00000800 0000FFFF 1110vvvv 10vvvvvv 10vvvvvv
21 00010000 001FFFFF 11110vvv 10vvvvvv 10vvvvvv 10vvvvvv
26 00200000 03FFFFFF 111110vv 10vvvvvv 10vvvvvv 10vvvvvv 10vvvvvv
31 04000000 7FFFFFFF 1111110v 10vvvvvv 10vvvvvv 10vvvvvv 10vvvvvv 10vvvvvv

Note that two octets are required to transform eight-bit encodings. When there are multiple ways to transform a single encoding, for example UCS 0, only the shortest transformation is legal.

The original character encoding may be obtained by concatenating the v bits into a (possibly multiple) octet encoding.


External specifications

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


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


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


create

This feature creates a UTF7 encoding of the bit-pattern contained in the argument value.

create (
val : CARD
) : SAME
Formal Signature
create2(val : CARD) res : SAME
Pre-condition

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

Post-condition
post card(res) = self

This feature creates and returns a UTF7 encoding corresponding to the given numeric value (treated as a bit-pattern).


create

This feature creates a UTF7 encoding from the given rune argument - which may consist of one or more individual encodings. The rune code kind is discarded in this transformation.

create (
rn : RUNE
) : SAME
Formal Signature
create3(rn : RUNE) res : SAME
Pre-condition

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

Post-condition
post runes(res)(1) = self

This feature creates and returns a UTF7 encoding corresponding to the given rune encoding.


create

This feature creates a UTF7 encoding from the given rune string argument. The rune code kind is discarded in this transformation.

Note that the result of this operation is of the same form as when converting a single (multiple encoding) rune.

create (
rn : RUNES
) : SAME
Formal Signature
create3(rn : RUNES) res : SAME
Pre-condition

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

Post-condition
post runes(res) = self

This feature converts the given rune string which is a sequence of runes for conversion into a valid UTF7 code.


build

This feature builds a UTF7 encoding from the indicated binary string buffer - using all of the buffer contents from the current cursor position. The rune code kind is discarded in this transformation.

Note that the result of this operation is of the same form as when converting a single (multiple encoding) rune.

build (
octets : BIN_CURSOR,
lib : LIBCHARS
) : SAME
Formal Signature
build2(octets : BIN_CURSOR, lib : LIBCHARS) res : SAME
Pre-condition
pre BIN_CURSOR.remaining(octets) mod LIBCHARS.my_size(lib) = 0
Post-condition
post let loc_runes = RUNES.build(octets,lib) in
      runes(res) = loc_runes

This feature converts the indicated binary string into a valid UTF7 code using the given repertoire and encoding.


is_singleton

This predicate returns true if and only if self is the transformation of a single character encoding.

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

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

Post-condition
post res = (RUNE.size(runes(self)(1)) = 1)

This feature returns true if and only if self is the transformation of a single character encoding.


card

This feature transforms self into a numeric value provided that self only contains a single character coding.

card : CARD
Formal Signature
card(self : SAME) res : CARD
Pre-condition
pre is_singleton(self)
Post-condition
post create(res) = self

This feature returns the encoded bits of self as a numeric value providing that self is merely a single transformed encoding.


runes

This feature transforms self into a rune string in the indicated repertoire and encoding.

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

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

Post-condition
post create(res) = self

This feature returns a string consisting of the individual codes of self treated as a rune string in the given repertoire and encoding.


runes

This feature transforms self into a rune string in the indicated repertoire and encoding.

runes : RUNES
Formal Signature
runes2(self : SAME) res : RUNES
Pre-condition

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

Post-condition
post create(res) = self

This feature returns a string consisting of the individual codes of self treated as a rune string in the default repertoire and encoding.


tgt_str

This feature transforms self into a local environment character string using the default repertoire and encoding. If self is a transformation of a character code within table 0 of the Unicode standard then the result will be identical in bit-pattern to self. This is the reason for the existence of UTF7 as a coding which can be used to name files across computer systems in different cultures - see the POSIX standard.

tgt_str : STR
Formal Signature
tgt_str(self : SAME) res : STR
Pre-condition

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

Post-condition
post res = RUNES.str(runes(self))

This feature transforms self into the locally defined default character string using eight, sixteen or thirty-two bit code spaces as defined in the environment.


rune!

This iter yields in sequence the individual transformations of single encodings contained in self - in the given cultural context.

rune! (
once lib : LIBCHARS
) : RUNE
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.

rune_iter(self : SAME, lib : LIBCHARS) yld : SAME
Pre-condition

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

Post-condition

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

post let rns : seq of RUNE be st create(rns) = self in
      RUNE.lib(yld) = lib
      and yld = rns(card history~ + 1)
      and history = history~ ^ yld
Quit condition

For quit actions see the specification of the quit statement.

errs QUIT : let rns : seq of RUNE be st rns = self in
      card history = card rns -> quit

This iter yields in sequence individual runes of which self is a sequence of transformations in the given encoding and repertoire.


rune!

This iter yields in sequence the individual transformations of single encodings contained in self.

rune! : RUNE
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.

rune_iter2(self : SAME) yld : SAME
Pre-condition

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

Post-condition

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

post let rns : seq of RUNE be st create(rns) = self in
      RUNE.lib(yld) = LIBCHARS.default
      and yld = rns(card history~ + 1)
      and history = history~ ^ yld
Quit condition

For quit actions see the specification of the quit statement.

errs QUIT : let rns : seq of RUNE be st rns = self in
      card history = card rns -> quit

This iter yields in sequence individual runes of which self is a sequence of transformations in the default encoding and repertoire.


code!

This iter yields in sequence the individual transformations of single encodings contained in self.

code! : SAME
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) yld : SAME
Pre-condition

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

Post-condition

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

post let codes : seq of SAME be st codes = self in
      yld = codes(card history~ + 1)
      and history = history~ ^ yld
Quit condition

For quit actions see the specification of the quit statement.

errs QUIT : let codes : seq of SAME be st codes = self in
      card history = card codes -> quit

This iter yields in sequence individual character coding transformations.


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