Sather Home Page

Section 8.17.3.6:
FRUNES

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

Inheritance map

$FTEXT_STRING

Formal Types

types

SAME = FRUNES ;
FRUNES = seq of RUNE

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{RUNE,STR,FSTR} :-


The following features are required to be implemented for this class in accordance with the specifications given in the abstract class $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{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 $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 $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.frunes(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.frunes(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.


vset

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 (
index : CARD
elem : RUNE
) : SAME
Formal Signature
vset(self : SAME, index : CARD, elem : RUNE) res : SAME
Pre-condition
pre index < len self
Post-condition
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.


runes

This feature creates an immutable rune string - a counterpart to the str feature in FSTR.

runes : RUNES
Formal Signature
runes(self : SAME) res : RUNES
Pre-condition

Since the self argument is not optional, this pre-condition is vacously true.

Post-condition
post let buff : seq of RUNE be st buff = self in
      (res = buff)

This feature creates and returns an immutable rune string.


Language Index Library Index Text Index
Comments or enquiries should be made toKeith Hopper.
Page last modified: Thursday, 5 April 2001.
Produced with Amaya