Sather Home Page

Section 8.17.3.2:
FSTR

class FSTR < $FTEXT_STRING{CHAR,STR,FSTR}

Inheritance map

$FTEXT_STRING

Formal Types

types

SAME = FSTR ;
FSTR = seq of CHAR

This class implements the concept of a fast (mutable) text string - in this particular case a string of characters each having a single encoding.


External specifications

The following features are required to be implemented for this class in accordance with the specifications given in $FTEXT_STRING{CHAR,STR,FSTR} :-


The following features are required to be implemented for this class in accordance with the specifications given in $FTEXT_STRING :-


The following features are required to be implemented for this class in accordance with the specifications given in $FSTRINGS :-


The following features are required to be implemented for this class in accordance with the specifications given in $BINARY :-


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 specifications given in $FLISTS :-


The following features are required to be implemented for this class in accordance with the specification given in $LISTS{CHAR} from which this class inherits :-


The following features are required to be implemented for this class in accordance with the specification given in $ARR{CHAR} 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{CHAR} from which this class inherits :-


The following features are required to be implemented for this class in accordance with the specification given in $CONTAINER{CHAR} from which this class inherits :-


The following features are required to be implemented for this class in accordance with the specification given in $FILTERS{CHAR} from which this class inherits :-


The following feature is required to be implemented for this class in accordance with the specification given in $ELT{CHAR} 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 $ELT{CHAR} 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 $IS_EQ from which this class inherits :-


create

This creation routine returns a string of the given size for the cultural context defined by the second argument.

create (
size : CARD,
lib : LIBCHARS
) : SAME
Formal Signature
create5(size : CARD, lib : LIBCHARS) res : SAME
Pre-condition

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-condition
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.


create

This creation routine returns an empty string for the given cultural context.

create (
lib : LIBCHARS
) : SAME
Formal Signature
create6(lib : LIBCHARS) res : SAME
Pre-condition

Since the argument is not optional the pre-condition of this routine is merely true.

Post-condition
post size(res) = 0
      and index_lib(res) = lib

This routine creates an empty string which is in the given culture, encoding and repertoire.


append_file

This feature returns the string formed by appending the contents of the named file to the current contents of self. Any file problem results in an exception being raised.

append_file (
name : STR
) : SAME
Formal Signature
append_file(self : SAME, name : STR) res : [SAME]
Pre-condition

Since this feature is defined (below) to raise an exception if there is a problem in accessing the named file, the pre-condition may be vacuously true.

Post-condition
post let fpath : FILE_PATH = FILE_PATH::create(name) in
         ((fpath = nil)
            and (res = nil))
         or (let fyle = TEXT_FILE.open_for_read(name) in
            let contents : SAME = TEXT_FILE.fstr(fyle) in
               res = self ^ contents
Exception

This exception mechanism uses the raise statement (feature) of Sather.

errs FILE_ERROR : (fyle = nil)
                or (TEXT_FILE.error(fyle) -> raise fyle

This routine opens the file which has the given name. If this is successful then the contents of the file are appended to self which is returned after closing the file.

NOTE If there is a file reading error then an exception is raised!

append_file_range

This feature returns the string formed by appending the indicated sub-string of the contents of the named file to the current contents of self. Any file problem results in an exception being raised.

append_file_range (
name : STR,
start_position : CARD,
count : CARD
) : SAME
Formal Signature
append_file_range(self : SAME, name : STR, start_position : CARD, count : CARD) res : [SAME]
Pre-condition

Since this feature is defined (below) to raise an exception if there is a problem in accessing the named file, the pre-condition may be vacuously true.

Post-condition
post let fpath : FILE_PATH = FILE_PATH::create(name) in
         ((fpath = nil)
            and (res = nil))
         or (let fyle = TEXT_FILE.open_for_read(name) in
            let contents : SAME = TEXT_FILE.fstr(fyle) in
               res = self ^ contents(start_position, ..., (start_position + count))
Exception

This exception mechanism uses the raise statement (feature) of Sather.

errs FILE_ERROR : (fyle = nil)
            or (TEXT_FILE.error(fyle) -> raise fyle

This routine opens the file which has the given name. If this is successful then the indicated substring of the file contents are appended to self which is returned after closing the file.

NOTE If there is a file reading error then an exception is raised!

separate!

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

separate_iter(self : SAME, str : STR) yld : STR
Pre-condition

Since the arguments are not optional 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~ = [])
         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.


Language Index Library Index Text Index
Comments or enquiries should be made toKeith Hopper.
Page last modified: Monday, 26 March 2001.
Produced with Amaya