# Section 8.16.1.1:
$STRINGS

###### abstract class $STRINGS < $IS_EQ, $ELT, $HASH

#### 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 ;
$STRINGS = set of object_type
state
multi : $STRINGS
inv multi_types ==
forall obj in set multi_types & sub_type($STRINGS,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 any kind of string which is suitable for exporting to a communications/file medium. The features provided are generic operations on a string needed in order to carry out import/export.

#### size

The size feature of this string model gives the number of elements in the string.

size | : CARD

##### Formal Signature

size(self : SAME) res : CARD

##### 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, leading to the pre-condition being vacuously true.

##### Post-condition

post"> res = card dom self

This feature returns the number of elements in the string.

NOTE | This is not necessarily directly related to the amount of storage occupied.

#### array_ptr

This feature is included in the model to providea means for using a string in some external execution environment service call. The returned value is implementation-dependent.

array_ptr | : REFERENCE

##### Formal Signature

array_ptr(self : SAME) res : REFERENCE

##### 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, leading to the pre-condition being vacuously true.

##### Post-condition

Since the result of this feature is implementation-dependent no post-condition can be specified (except to state here that the reference is required to be a valid handle for self).

This feature provides an environment-defined handle for the contents of self (for use in external input or output).

#### head

This feature is provided to enable a program to manipulate the elements at the beginning of the string as an independent string.

head | (
| cnt : CARD
| ) : SAME

##### Formal Signature

head(self : SAME, cnt : CARD) res : SAME

##### Pre-condition

This feature is required to operate successfully whatever the value of cnt may be. The pre-condition is therefore vacuously true.

##### Post-condition

post let rest : SAME be st res ^ rest = self in
((cnt <= size(self))
and (size(res) = cnt))
or (size(rest) = 0)

This feature provides either cnt elements from the head of self or the contents of self if that contains fewer elements.

#### tail

This feature corresponds to the one above in respect of the end of the string being made available for manipulation purposes.

tail | (
| cnt : CARD
| ) : SAME

##### Formal Signature

tail(self : SAME, cnt : CARD) res : SAME

##### Pre-condition

This feature is required to operate successfully whatever the value of cnt may be. The pre-condition is therefore vacuously true.

##### Post-condition

post let rest : SAME be st rest ^ res = self in
((cnt <= size(self))
and (size(res) = cnt))
or (size(rest) = 0)

This feature provides either cnt elements from the tail of self or the contents of self if that contains fewer elements.

#### substring

This feature emables a program to select an arbitrary substring of the string for independent manipulation.

substring | (
| beg : CARD ,
| num : CARD
| ) : SAME

##### Formal Signature

substring(self : SAME, beg : CARD, num : CARD) res : SAME

##### Pre-condition

pre (beg + num) <= size(self)

##### Post-condition

post let begin : SAME, end : SAME be st begin ^ res ^ end = self in
(size(begin) = beg)
(and (size(res) = num)

This feature provides the substring of num elements of self beginning with the one whose index is one greater than beg.

NOTE | Indices used in Sather programs start with zero, those in vdm-sl are ordinal numbers starting from 1.

| Language Index |  | Library Index |  | String Index

Comments or enquiries should be made to Keith Hopper . Page last modified: Monday, 22 May 2000. |