Sather Home Page

Section 8.3.1.2:
$CODE_CONVERTER

immutable class $CODE_CONVERTER

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 ;
$CODE_CONVERTER = set of object_type

state

multi : $CODE_CONVERTER
   inv multi_types ==
      forall obj | obj in set multi_types &
         sub_type($CODE_CONVERTER,obj)
NOTE See the important note about vdm state in the notes on vdm-sl usage in this specification.

This abstract class defines the concept of an object which can convert text objects from one encoding to another, preserving the semantics of the object in doing so.


rune

This feature converts the character which is presumed to be encoded in the 'from' argument repertoire and encoding into a Unicode rune. Note that, since Unicode is the universal encoding, then this mapping will always succeed.

rune (
from : LIBCHARS
val : CHAR,
) : RUNE
Formal Signature
rune(self : SAME, from : LIBCHARS, val : CHAR) res : RUNE
Pre-condition

Note that in contrast to a pre-condition written in Sather source code, in vdm-sl the type SAME is not an optional type and therefore self must exist; the other arguments are also not optional, leading to the pre-condition being vacuously true.

Post-condition
post let loc_code = CHAR_CODE.create(val,from) in
      exists map | map in set $CODE_MAPPER.references &
         res = CHAR_CODE.rune($CODE_CONVERTER.to_unicode(map,loc_code))

This feature returns the rune encoding (in Unicode) given the value of the argument character in the indicated encoding.


runes

This feature converts the given text string into Unicode runes, preserving the semantics of the individual characters. Note that, since Unicode is the universal encoding, then this mapping will always succeed.

runes (
val : STR
) : RUNES
Formal Signature
runes(self : SAME, val : STR) res : RUNES
Pre-condition

Note that in contrast to a pre-condition written in Sather source code, in vdm-sl the type SAME is not an optional type and therefore self must exist; the other arguments are also not optional, leading to the pre-condition being vacuously true.

Post-condition
post forall idx | idx in set inds val &
      let loc_code = CHAR_CODE.create(val(idx),STR.index_lib(val)) in
         exists map | map in set $CODE_MAPPER.references &
            res(idx) = CHAR_CODE.rune($CODE_CONVERTER.to_unicode(map,loc_code))

This feature returns the rune encoding (in Unicode) string which corresponds to the given string, preserving the semantics of the individual characters.


char

This feature converts the given rune into the required encoding as a character.

char (
to : CODE_KINDS,
val : RUNE
) : CHAR
Formal Signature
char(self : SAME, to : CODE_KINDS, val : RUNE) res : CHAR
Pre-condition

Note that in contrast to a pre-condition written in Sather source code, in vdm-sl the type SAME is not an optional type and therefore self must exist; the other arguments are also not optional, leading to the pre-condition being vacuously true.

Post-condition
post let loc_code = CHAR_CODE.create(val) in
      exists cmap | cmap in set $CODE_MAPPER.references
             and $CODE_MAPPER.kind(cmap) = to &
         let res_code = $CODE_MAPPER.from_unicode(map,loc_code) in
            (res_code = CHAR_CODE.nil
               and res = CHAR.nil)
            or res = CHAR_CODE.char(res_code)

This feature returns the character encoding in the specified code kind corresponding to the given rune. It is an error if either the given rune contains combining codes or if no such character code exists in the given code kind when CHAR::nil is returned.


str

This feature converts the given rune into the required encoding as a character.

str (
to : LIBCHARS
val : RUNES,
) : STR
Formal Signature
str(self : SAME, to : LIBCHARS, val : RUNES) res : [STR]
Pre-condition

Note that in contrast to a pre-condition written in Sather source code, in vdm-sl the type SAME is not an optional type and therefore self must exist; the other arguments are also not optional, leading to the pre-condition being vacuously true.

Post-condition
post forall idx | idx in set inds val &
      let loc_code = CHAR_CODE.create(val(idx)) in
         (exists map | map in set $CODE_MAPPER.references
               and $CODE_MAPPER.kind(map) = CULTURE.kind(LIBCHARS.culture(to) &
            res(idx) = CHAR_CODE.char($CODE_MAPPER.from_unicode(map,loc_code)))
         or res = nil

This feature returns the character string the given encoding and repertoire which corresponds to the val argument. If one or more elements cannot be mapped then void is returned.


code

This feature converts the given rune into the required encoding and repertoire as a character code.

code (
to : LIBCHARS,
val : RUNE
) : CHAR_CODE
Formal Signature
code(self : SAME, to : CODE_KINDS, val : RUNE) res : CHAR_CODE
Pre-condition

Note that in contrast to a pre-condition written in Sather source code, in vdm-sl the type SAME is not an optional type and therefore self must exist; the other arguments are also not optional, leading to the pre-condition being vacuously true.

Post-condition
post exists map | map in set $CODE_MAPPER.references
         and $CODE_MAPPER.kind(map) = to &
      res = $CODE_MAPPER.from_unicode(map,CHAR_CODE.create(val))
         or res = CHAR_CODE::nil

This feature returns the character encoding in the specified code kind corresponding to the given rune. It is an error if either the given rune contains combining codes or if no such character code exists in the given code kind when CHAR_CODE::nil is returned.


codes

This feature converts the given rune string into the required encoding as a string of character codes.

codes (
to : LIBCHARS
val : RUNES,
) : CODE_STR
Formal Signature
codes(self : SAME, to : LIBCHARS, val : RUNES) res : [CODE_STR]
Pre-condition

Note that in contrast to a pre-condition written in Sather source code, in vdm-sl the type SAME is not an optional type and therefore self must exist; the other arguments are also not optional, leading to the pre-condition being vacuously true.

Post-condition
post forall idx | idx in set inds val &
      exists map | map in set $CODE_MAPPER.references
            and $CODE_MAPPER.kind(map) = CULTURE.kind(LIBCHARS.culture(to)) &
         res = $CODE_MAPPER.from_unicode(map,CHAR_CODE.create(val(idx)))
            or res = nil

This feature returns the character code string of the given encoding and repertoire which corresponds to the val argument. If one or more elements cannot be mapped then void is returned.


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