![]() |
Section 8.3.1.2:
|
![]() |
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.
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(self : SAME, from : LIBCHARS, val : CHAR) res : RUNE
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 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.
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(self : SAME, val : STR) res : RUNES
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 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.
This feature converts the given rune into the required encoding as a character.
char | ( |
to : CODE_KINDS, | |
val : RUNE | |
) : CHAR |
char(self : SAME, to : CODE_KINDS, val : RUNE) res : CHAR
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 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.
This feature converts the given rune into the required encoding as a character.
str(self : SAME, to : LIBCHARS, val : RUNES) res : [STR]
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 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.
This feature converts the given rune into the required encoding and repertoire as a character code.
code(self : SAME, to : CODE_KINDS, val : RUNE) res : CHAR_CODE
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 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.
This feature converts the given rune string into the required encoding as a string of character codes.
codes(self : SAME, to : LIBCHARS, val : RUNES) res : [CODE_STR]
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 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. |
![]() |