![]() |
Section 8.16.1.7:
|
![]() |
This page defines two generic abstract classes named $FTEXT_STRING which have different numbers of class arguments
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 ; $FTEXT_STRING_ELT = set of object_type state multi : $FTEXT_STRING_ELT
inv multi_types == forall obj in set multi_types & sub_type($FTEXT_STRING_ELT,obj)
NOTE | See the important note about vdm state in the notes on vdm-sl usage in this specification. |
This abstract class characterises the concept of a mutable text string as sequences of the argument class (elements) which must sub-type from $IS_EQ.
This feature is the cultural description and coding which is associated with the string. It need not be the default culture and coding for the environment in which the program is executing, since a program may manipulate culture objects independently of local textual representations.
index_lib(self : SAME) res : LIBCHARS
Since the string has to exist then so does this component. The pre-condition, therefore, is vacuously true.
This is also vacuously true, since it is a component of every string of text.
This feature provides access to all of the cultural and environment dependencies relating to this character string.
abstract class $FTEXT_STRING{ | |
ELT < $IS_EQ, | |
STP < $TEXT_STRING{ELT}, | |
FSTP < $FTEXT_STRING{ELT} | |
} < $FTEXT_STRING{ELT} |
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 ; $FTEXT_STRING_ELT_FTP_STP = set of object_type state multi : $FTEXT_STRING_ELT_FTP_STP inv multi_types == forall obj in set multi_types & sub_type($FTEXT_STRING_ELT_FTP_STP,obj)
NOTE | See the important note about vdm state in the notes on vdm-sl usage in this specification. |
This abstract class characterises the concept of a mutable text string as a sequence of the argument class (elements) which must sub-type from $IS_EQ. The second and third class arguments are the 'corresponding' mutable ($FTEXT_STRING{ELT}) and self string classes.
The strip feature in this class needs the definition of a line mark - which is given below.
functions lmark () res : STP post res = CHAR_STR.str(LIBCHARS.Line_Mark(STP.index_lib(buffer)))
This feature replaces the one inherited from $BINARY which makes use of the execution environment default repertoire and encoding in building the resultant text string.
build | ( |
cursor : BIN_CURSOR | |
) : SAME |
build(cursor : BIN_CURSOR) res : SAME
pre not cursor.is_done
post let width = lib.my_size in ((BIN_CURSOR.remaining(cursor) mod width > 0) or not exists idx1, idx2 | idx1 in set inds cursor.buffer and idx1 in set inds cursor.buffer and idx1 <> idx2 & (idx2 = idx1 + width - 1) and REP_MAP.is_valid_encoding(LIBCHARS.culture(LIBCHARS.default()).charmap, cursor.buffer(idx1, ..., idx2)) and (cursor.index = cursor~.index)) or (cursor.is_done and let res be st forall idx in set inds res & let start = idx - 1 * width, finish = start + width - 1 in binstr(res(idx)) = cursor.buffer(start, ..., finish)
This routine builds a new mutable string from the binary string indicated using the encoding and repertoire defined by the external execution environment. If there is not an exact number of character codes in the string then void is returned and the cursor has not been moved.
This feature makes use of the given encoding and repertoire rather than the execution environment default in building the resultant text string.
build | ( |
cursor : BIN_CURSOR, | |
lib : LIBCHARS | |
) : SAME |
build2(cursor : BIN_CURSOR, lib : LIBCHARS) res : SAME
pre not cursor.is_done
post let width = lib.my_size in ((BIN_CURSOR.remaining(cursor) mod width > 0) or not exists idx1, idx2 | idx1 in set inds cursor.buffer and idx2 in set inds cursor.buffer & (idx2 = idx1 + width - 1) and REP_MAP.is_valid_encoding(LIBCHARS.culture(lib).charmap, cursor.buffer(idx1, ..., idx2)) and (cursor.index = cursor~.index)) or (cursor.is_done and let res be st forall idx | idx in set inds res & let start = idx - 1 * width, finish = start + width - 1 in binstr(res(idx)) = cursor.buffer(start, ..., finish)
This routine builds a new mutable string from the binary string indicated using the encoding and repertoire defined by lib. If there is not an exact number of character codes in the string then void is returned and the cursor has not been moved.
This feature provides a facility of removing line marks from the end of a string (if there are any there). Multiple line marks at the end will be removed, irrespectiv of any escaping mechanism.
strip | : SAME |
strip(self : SAME) res : SAME
Since the self argument is not optional, this pre-condition is vacuously true.
This post-condition uses the auxiliary function lmark defined above.
post (len res < len lmark()) or let test = self((len self - len lmark()), ..., len self) in test <> lmark() and res = self
This feature removes as many line marks as are found at the end of the string, returning the result.
This is the first of three features which are provided for appending new elements to the string. It is provided for appending a single elemnt, returning the string having done so. Note that the string returned will be a new string if the buffer of self is full when invoked.
plus | ( |
val : ELT | |
) : SAME |
plus(self : SAME, val : ELT) res : SAME
Since neither argument is optional, this pre-condition is vacuously true.
Note that this post-condition makes use of the feature is_full inherited from $FLISTS.
post let res = (if is_full(self) then let new_len : CARD be st new_len > loc in create(new_len) else self end) in res = self~ ^ [val]> and loc(res) = loc(self~) + 1
This feature appends the given element onto the end of the sequence of elements in self, returning an object of the same type. This object returned may be self or it may be a new object.
This version of string concatenation is provided to append a mutable string tp self, returning the string having done so. Note that the string returned will be a new string if the buffer of self is not large enough to contain the string to be appended when invoked.
plus | ( |
val : SAME | |
) : SAME |
plus2(self : SAME, val : SAME) res : SAME
Since neither argument is optional, this pre-condition is vacuously true.
Note that this post-condition makes use of the feature is_full inherited from $FLISTS in addition to the auxiliary function new_length specified for this abstraction.
post let res = (let new_len : CARD = new_length(self,other) in if new_len > self.loc then create(new_len) else self end) in res = self~ ^ val> and res.loc = (self~.loc + val.loc)
This feature appends the given element onto the end of the sequence of elements in self, returning an object of the same type. This object returned may be self or it may be a new object.
This version of string concatenation is provided to append a mutable string tp self, returning the string having done so. Note that the string returned will be a new string if the buffer of self is not large enough to contain the string to be appended when invoked.
plus | ( |
val : STP | |
) : SAME |
plus3(self : SAME, val : STP) res : SAME
Since neither argument is optional, this pre-condition is vacuously true.
Note that this post-condition makes use of the feature is_full inherited from $FLISTS in addition to the auxiliary function new_length specified for this abstraction.
post let res = (let new_len : CARD = new_length(self,other) in if new_len > self.loc then create(new_len) else self end) in res = self~ ^ val> and res.loc = (self~.loc + val.loc)
This feature appends the given element onto the end of the sequence of elements in self, returning an object of the same type. This object returned may be self or it may be a new object.
This iter version and the one following complement the one inherited by this abstraction. This permits the first element yielded to be the element indexed by the start argument.
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.
elt_iter2(self : SAME, start : CARD) res : ELT
Since the iter may quit if start is not in the domain of indices of self, the pre-condition is vacuously true.
This post-condition makes use of the history concept from vdm++ (see the vdm dialect notes).
post history = history~ ^ [res] and res = self(len history + start)
For quit actions see the specification of the quit statement.
errs QUIT : (len history + start) = len self -> quit
This iter yields the elements of self in order beginning with the element at the given starting index.
This iter version specifies both the element to yield first and the number of elements to be yielded.
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.
elt_iter3(self : SAME, start : CARD, num : CARD) res : ELT
Since the iter may quit if start is not in the domain of indices of self, the pre-condition is vacuously true.
This post-condition makes use of the history concept from vdm++ (see the vdm dialect notes).
post history = history~ ^ [res]
and res = self(len history + start)
For quit actions see the specification of the quit statement.
errs QUIT : (len history = num) or (len history + start) = len self -> quit
This iter yields num elements of self in order beginning with the element at the given starting index.
This iter yields the character encodings of self in sequence starting at the one indicated.
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) res : CHAR_CODE
Since the iter may quit when all elements have been yielded, the pre-condition is vacuously true.
This post-condition makes use of the history concept from vdm++ (see the vdm dialect notes).
post history = history~ ^ [res] and res = CHAR_CODE.create(self(len history))
For quit actions see the specification of the quit statement.
errs QUIT : (len history = len self -> quit
This iter yields in sequence the individual character encodings in self starting with the first.
This iter yields the character encodings of self in sequence starting at the one indicated.
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_iter2(self : SAME, start : CARD) res : CHAR_CODE
Since the iter may quit if start is not in the domain of indices of self, the pre-condition is vacuously true.
This post-condition makes use of the history concept from vdm++ (see the vdm dialect notes).
post history = history~ ^ [res] and res = CHAR_CODE.create(self(len history + start))
For quit actions see the specification of the quit statement.
errs QUIT : (len history + start) = len self -> quit
This iter yields in sequence the individual character encodings in self starting with the one indicated.
![]() |
Language Index | ![]() |
Library Index | ![]() |
String Index |
Comments
or enquiries should be made toKeith Hopper. Page last modified: Wednesday, 4 April 2001. |
![]() |