![]() |
Section 8.17.3.5:
|
![]() |
types SAME = RUNES ; RUNES = seq of RUNE
This class provides a string implementation in which each rune may have a variable number of encodings - a basic encoding and then a number of combining codes. Objects of this type have immutable semantics.
The following features are required to be implemented for this class in accordance with the specifications given in $TEXT_STRING{RUNE,FRUNES,RUNES} from which this class inherits :-
The following features are required to be implemented for this class in accordance with the specifications given in $TEXT_STRING{RUNE} from which this class inherits :-
The following features are required to be implemented for this class in accordance with the specifications given in $BINARY from which this class inherits :-
The following features are required to be implemented for this class in accordance with the specifications given in $SEARCH from which this class inherits :-
The following features are required to be implemented for this class in accordance with the specification given in $STRING{RUNE} from which this class inherits :-
The following features are required to be implemented for this class in accordance with the specification given in $STRINGS from which this class inherits :-
The following features are required to be implemented for this class in accordance with the specification given in $LISTS{RUNE} from which this class inherits :-
The following features are required to be implemented for this class in accordance with the specification given in $ARR{RUNE} from which this class inherits :-
The following features are required to be implemented for this class in accordance with the specification given in $RO_ARR{RUNE} from which this class inherits :-
The following features are required to be implemented for this class in accordance with the specification given in $CONTAINER{RUNE} from which this class inherits :-
The following features are required to be implemented for this class in accordance with the specification given in $FILTERS{RUNE} from which this class inherits :-
The following feature is required to be implemented for this class in accordance with the specification given in $ELT{RUNE} from which this class inherits :-
The following features are required to be implemented for this class in accordance with the specification given in $ELT from which this class inherits :-
The following feature is required to be implemented for this class in accordance with the specification given in $HASH from which this class inherits :-
The following feature is required to be implemented for this class in accordance with the specification given in $COPY from which this class inherits :-
The following features are required to be implemented for this class in accordance with the specification given in $STR from which this class inherits :-
The following feature is required to be implemented for this class in accordance with the specification given in $IS_EQ from which this class inherits :-
This creation routine returns a string of the given size for the cultural context defined by the second argument.
create5(size : CARD, lib : LIBCHARS) res : SAME
Since the second argument is not optional and because it is possible to create an empty string then the pre-condition of this routine is merely true.
post size(res) = size and index_lib(res) = lib
This routine creates a string of the requested size and in the culture specified by the second lib argument.
This creation routine returns an empty string for the given cultural context.
create6(lib : LIBCHARS) res : SAME
Since the argument is not optional the pre-condition of this routine is merely true.
post size(res) = 0 and index_lib(res) = lib
This routine creates an empty string which is in the given culture, encoding and repertoire.
This creation routine returns a single element string containing the character given which is to be treated as though it is in the given repertoire and encoding.
create7(ch : CHAR, lib : LIBCHARS) res : SAME
Since neither argument is optional, the pre-condition of this routine is merely true.
post len res = 1 and res(1) = ch and index_lib(res) = lib
This routine returns the single element string in the given encoding and repertoire.
This creation routine is provided for symmetry with the class STR (qv).
create8(rns : RUNES) res : SAME
pre let codes : seq of CHAR_CODE be st codes = rns in forall idx | idx in set inds codes & not UNICODE.is_combining(UNICODE.create(CHAR_CODE.card(codes(idx)))) and index_lib(res) = RUNES.index_lib(rns)
post forall idx | idx in set inds rns & RUNE.char(rns(idx)) = res(idx)
This routine creates a new rune string from the given rune string (subject to the pre-condition), using the same repertoire and encoding.
This feature creates a rune string in the given target culture from the binary string of UCS2 (16-bit) encodings.
create_from_ucs2 | ( |
str : BINSTR | |
lib : LIBCHARS | |
) : SAME |
create_from_ucs2(bstr : BINSTR, lib : LIBCHARS) res : SAME
pre len bstr mod 2 = 0
post let loc_codes : seq of UCS2 be st loc_codes = bstr in let ucodes = convert(res,LIBCHARS.dummy_lib(CODE_KINDS.Unicode)) in forall idx | idx in set inds ucodes & UCS2.code(loc_ucodes(idx)) = UNICODE.code(ucodes(idx))
This routine creates a rune string from the given binary string on the basis that the encodings are UCS2, not UCS4.
Although this feature actually creates a new immutable string, this is really a conversion operation since the two strings have identical content and cultural context.
from_frunes | ( |
fstr : FRUNES | |
) : SAME |
from_frunes(fast_str : FRUNES) res : SAME
Since the argument is not optional (though it may be the empty string) then this pre-condition is vacuously true.
post FRUNES.index_lib(fast_str) = index_lib(res) and len res = len fast_str and forall idx | idx in set inds fast_str & fast_str(idx) = res(idx)
This routine converts the argument (mutable) string into the immutable form. The contents of both are the identical sequence of runes.
This routine creates a new string cursor pointing to the beginning of the buffer, which is self.
cursor(self : SAME) res : RUNES_CURSOR
Since the argument is not optional then the pre-condition is vacuously true.
post RUNES_CURSOR.buffer(res) = self and RUNES_CURSOR.item(res) = self(1) and RUNES_CURSOR.skip_val = nil and RUNES_CURSOR.line_no = 0 and RUNES_CURSOR.comment_start = create(LIBCHARS.Space(index_lib)) and RUNES_CURSOR.is_done = (size = 0)
This routine creates and returns an initialised cursor object, the buffer of which is self.
This feature is provided for symmetry with the STR class (qv). It returns the rune at the indicated index.
rune(self : SAME, index : CARD) res : RUNE
pre index < len self
post res = self(index)(1)
This routine returns the rune at the given index.
This feature is provided for symmetry with the STR class (qv). It returns the rune at the indicated index.
char(self : SAME, index : CARD) res : RUNE
pre index < len self
post res = self(index)(1)
This routine returns the rune at the given index.
This feature provides a means by which the cultural context of a string may be converted to the one described by the given argument.
convert(self : SAME, lib : LIBCHARS) res : [SAME]
Since the arguments are not optional then the pre-condition is vacuously true.
post (res = nil) or let to_map : CODE_MAPPER = CODE_CONVERTER.map(CULTURE.kind(LIBCHARS.cult(index_lib)), from_map : CODE_MAPPER = CODE_CONVERTER.map(CULTURE.kind(LIBCHARS.cult(lib)) in forall ch | ch in set dom self & let ucode = CODE_MAPPER.to_unicode(to_map,CHAR_CODE.create(ch,index_lib)) in CODE_MAPPER.from_unicode(from_map,ucode) <> nil
This routine returns a new string in the given encoding and repertoire with the identical contents to self. If any character of self has no corresponding code in the target culture then void is returned.
This feature is the only case in which an implied knowledge of storage is needed. It is the equivalent of aset, but, since the element to be set may have more encodings than the element it replaces it is necessary to return what could well be a new string capable of holding the existing contents minus the replaced element plus the replacing element.
vset(self : SAME, index : CARD, elem : RUNE) res : SAME
pre index < len self
post len self = len res and let head : seq of RUNE, item : RUNE, tail : seq of RUNE be st len head = index and head ^ [item] ^ tail = self in res = head ^ [elem] ^ tail
This feature is the indexing facility for the case where the number of codes in elem is different from the number currently at that index position in the string. A new rune string has to be produced if the resulting length is different from that currently allocated.
This routine creates and returns a binary string version of self provided that all of the encodings are representahle as UCS2 values, otherwise void.
ucs2(self : SAME) res : [BINSTR]
Since the argument is not optional and the result is, the pre-condition is vacuously true.
post self = create_from_ucs2(res, index_lib) or (res = nil and let ucodes : seq of UNICODE = convert(self,LIBCHARS.dummy_lib(CODE_KINDS.Unicode)) in exists elt | elt in set dom ucodes & elt not in set dom UCS2
This routine returns a copy of self which is in the UCS2 binary form. If it is not possible to represent any rune element in UCS2 coding then void is returned.
This iter is provided to enable splitting of strings which are composed of sequences of strings with the insertion of some separator. The sub-strings yielded are successive strings without separating runes. If there are ywo adjacent separating characters then the empty strinf is returned.
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.
split_iter(self : SAME, ch : RUNE) res : SAME
The pre-condition to all calls is vacuously true except for the history which must be the empty sequence at the initial call (only).
This post-condition makes use of the history concept from vdm++ (see the vdm dialect notes).
post let rest = [self(len history~), ..., self(len self)] in let res ^ tail = rest be st forall idx | idx in set inds res & res(idx <> ch) and (((history~ = []) and (history = [ch] ^ res)) or ((len history > 0) and (history = history~ ^ [ch] ^ res)))
For quit actions see the specification of the quit statement.
errs QUIT : len history = len self + 1 -> quit
This iter yields successive substrings of self which are separated by the single given character. each occurrence of the separating character in self is omitted from the strings returned. Successive strings are taken from the remainder of self after the separating character at the end of the previous yield (if any) has been passed over.
This feature is provided as a complement to the one above, yielding the argument only on the first iteration, successive iterations yielding self followed by the argument. It is provided for ease in creating string lists of some kind.
separate! | ( |
str : SAME | |
: SAME |
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.
separate_iter(self : SAME, str : SAME) yld : SAME
Since the arguments are not optional the pre-condition is vacuously true.
This post-condition makes use of the history concept from vdm++ (see the vdm dialect notes).
post (((history~ = []) and (res = str)) or (res = self ^ str)) and (history = self)
NOTE | This is an infinite iterator and the enclosing loop must be left by some other iter! |
On the first iteration this feature yields the string argument. On successive iterations it yields self followed by the argument.
This feature is provided to permit human visualisation of the rune string in the given repertoire and encoding. The result consists of a sequence of hexadecimal numbers representing the bit-pattern of an encoding, separated from each other by spaces.
text_str(self : SAME, lib : LIBCHARS) res : STR
Since neither argument is optional then the pre-condition is vacuously true.
post let space : CHAR = CHAR_CODE.char(LIBCHARS.Space(lib)) in let loc_codes : seq of CHAR_CODE be st loc_codes = self, loc_ans : seq of STR be st loc_ans = res and len loc_ans = len loc_codes and forall idx | idx in set {2, ..., len loc_ans} & hd loc_ans(idx) = space and forall ch | ch in set dom tl loc_ans(idx) & ch <> space in CARD.hex_str(CHAR_CODE.card(loc_codes(idx))) = tl loc_ans(idx)
This routine returns a string representation of self in the given repertoire and encoding as a space separated sequence of hexadecimal numbers.
This feature is provided to permit human visualisation of the rune string in the default environment repertoire and encoding. The result consists of a sequence of hexadecimal numbers representing the bit-pattern of an encoding, separated from each other by spaces.
text_str2(self : SAME) res : STR
Since neither argument is optional then the pre-condition is vacuously true.
post let space : CHAR = CHAR_CODE.char(LIBCHARS.Space(LIBCHARS.default)) in let loc_codes : seq of CHAR_CODE be st loc_codes = self, loc_ans : seq of STR be st loc_ans = res and len loc_ans = len loc_codes and forall idx | idx in set {2, ..., len loc_ans} & hd loc_ans(idx) = space and forall ch | ch in set dom tl loc_ans(idx) & ch <> space in CARD.hex_str(CHAR_CODE.card(loc_codes(idx)),LIBCHARS.default) = tl loc_ans(idx)
This routine returns a string representation of self in the execution environment default repertoire and encoding as a space separated sequence of hexadecimal numbers.
![]() |
Language Index | ![]() |
Library Index | ![]() |
Text Index |
Comments
or enquiries should be made toKeith Hopper. Page last modified: Monday, 26 March 2001. |
![]() |