Sather Home Page

Section 8.16.1.7:
$FTEXT_STRING

This page defines two generic abstract classes named $FTEXT_STRING which have different numbers of class arguments

abstract class $FTEXT_STRING{ELT < $IS_EQ} < $FSTRING{ELT}

Inheritance map
$FSTRINGS $IS_EQ $HASH $ELT

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 ;
$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.


index_lib

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 : LIBCHARS
Formal Signature
index_lib(self : SAME) res : LIBCHARS
Pre-condition

Since the string has to exist then so does this component. The pre-condition, therefore, is vacuously true.

Post-condition

Thie 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}
Inheritance map
$IS_EQ $ELT $HASH $FSTRINGS $STRINGS $FTEXT_STRING{ELT} $TEXT_STRING{ELT}

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 ;
$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.

Auxiliary Function

The strip feature in this class needs the definition of a line mark - which is given below.

lmark () res : STP

post res = CHAR_STR.str(LIBCHARS.Line_Mark(STP.index_lib(buffer)))

build

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
Formal Signature
build(cursor : BIN_CURSOR) res : SAME
Pre-condition
pre not cursor.is_done
Post-condition
post let width = lib.my_size in
((BIN_CURSOR.remaining(cursor) mod width > 0) or not exists idx1, idx2 in set inds cursor.buffer & (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.


build

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
Formal Signature
build2(cursor : BIN_CURSOR, lib : LIBCHARS) res : SAME
Pre-condition
pre not cursor.is_done
Post-condition
post let width = lib.my_size in
((BIN_CURSOR.remaining(cursor) mod width > 0) or not exists idx1, 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 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.


strip

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
Formal Signature
strip(self : SAME) res : SAME
Pre-condition
pre true
Post-condition

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.


elt!

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.

elt! (
once  start : CARD
) : ELT
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.

elt_iter2(self : SAME, start : CARD) res : ELT
Pre-condition

Since the iter may quit if start is not in the domain of indices of self, the pre-condition is vacuously true.

Post-condition

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)
Quit condition

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.


elt!

This iter version specifies both the element to yield first and the number of elements to be yielded.

elt! (
once  start : CARD
once  num : CARD
) : ELT
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.

elt_iter3(self : SAME, start : CARD, num : CARD) res : ELT
Pre-condition

Since the iter may quit if start is not in the domain of indices of self, the pre-condition is vacuously true.

Post-condition

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)
Quit condition

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.


code!

This iter yields the character encodings of self in sequence starting at the one indicated.

code! : CHAR_CODE
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) res : CHAR_CODE
Pre-condition

Since the iter may quit when all elements have been yielded, the pre-condition is vacuously true.

Post-condition

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))
Quit condition

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.


code!

This iter yields the character encodings of self in sequence starting at the one indicated.

code! (
once  start : CARD
) : CHAR_CODE
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_iter2(self : SAME, start : CARD) res : CHAR_CODE
Pre-condition

Since the iter may quit if start is not in the domain of indices of self, the pre-condition is vacuously true.

Post-condition

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))
Quit condition

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 to Keith Hopper.
Page last modified: Wednesday, 29 November 2000.
Produced with Amaya