Sather Home Page

Section 8.17.3.8:
OCT_STR

class OCT_STR < $TEXT_STRING{CHAR,FSTR,OCT_STR}

Inheritance map

$TEXT_STRING $EXTERNAL_REF $IMMUTABLE $ANCHORED_FMT

Formal Types

types

SAME = OCT_STR ;
OCT_STR = seq of CHAR

This class provides a string implementation in which each character has a single eight-bit encoding. Objects of this type have immutable semantics.


External specifications

The following features are required to be implemented for this class in accordance with the specifications given in $TEXT_STRING{CHAR,FSTR,OCT_STR} from which this class inherits :-


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


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


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


The following feature is required to be implemented for this class in accordance with the specification given in $EXTERNAL_REF from which this class inherits :-


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


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


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 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 $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 len res = len self
      >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.


create

This creation routine returns a single element string containing the charecter given which is to be treated as though it is in the given repertoire and encoding.

create (
ch : CHAR,
lib : LIBCHARS
) : SAME
Formal Signature
create7(ch : CHAR, lib : LIBCHARS) res : SAME
Pre-condition

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

Post-condition
post len res = 1
      and res(1) = ch
      and index_lib(res) = lib

This routine returns the single element string in the given encoding and repertoire.


from_fstr

Although this feature actually creates a new immutable string, this is really a conversion operation since the two strings have identical content and cultural context.

from_fstr (
fstr : FSTR
) : SAME
Formal Signature
from_fstr(fast_str : FSTR) res : SAME
Pre-condition

Since the argument is not optional (though it may be the empty string), this pre-condition is vacuously true.

Post-condition
post FSTR.index_lib(fast_str) = index_lib(res)
      and len res = len fast_str
      and forall idx | idx in set inds fast_str &
         fast_str(idx) = res(idx)

This routine converts the argument (mutable) string into the immutable form. The contents of both are the identical sequence of characters.


char

This feature is provided for symmetry with the RUNES class (qv). It returns the character at the indicated index.

char (
index : CARD
) : CHAR
Formal Signature
char(self : SAME, index : CARD) res : CHAR
Pre-condition
pre index < len self
Post-condition
post res = self(index)

This routine returns the value of the character at the given index. It is a synonym for aget.


convert

This feature provides a means by which the cultural context of a string may be converted to the one described by the given argument.

convert (
lib : LIBCHARS
) : SAME
Formal Signature
convert(self : SAME, lib : LIBCHARS) res : [SAME]
Pre-condition

Since the arguments are not optional then the pre-condition is vacuously true.

Post-condition
post (res = nil)
      or let to_map : CODE_MAPPER = CODE_CONVERTER.map(CULTURE.kind(LIBCHARS.cult(index_lib)),
            from_map : CODE_MAPPER = CODE_CONVERTER.map(CULTURE.kind(LIBCHARS.cult(lib)) in
               forall ch | ch in set dom self &
                  let ucode = CODE_MAPPER.to_unicode(to_map,CHAR_CODE.create(ch,index_lib)) in
                     CODE_MAPPER.from_unicode(from_map,ucode) <> nil

This routine returns a new string in the given encoding and repertoire with the identical character contents to self. If any character of self has no corresponding code in the target culture then void is returned.


split!

This iter is provided to enable splitting of strings which are composed of sequences of strings with the insertion of some separator. The sub-strings yielded are successive strings without separating characters. If there are two adjacent separating characters then the empty string is returned.

split! (
once ch : CHAR
) : 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.

split_iter(self : SAME, ch : CHAR) res : SAME
Pre-condition

The pre-condition to all calls is vacuously true except for the history which must be the empty sequence at the initial call (only).

Post-condition

This post-condition makes use of the history concept from vdm++ (see the vdm dialect notes).

post let rest = [self(len history~), ..., self(len self)] in
         let res ^ tail = rest be st
            forall idx | idx in set inds res &
               res(idx <> ch)
      and (((history~ = [])
            and (history = [ch] ^ res))
         or ((len history > 0)
            and (history = history~ ^ [ch] ^ res)))
Quit condition

For quit actions see the specification of the quit statement.

errs QUIT :  len history = len self + 1 -> quit

This iter yields successive substrings of self which are separated by the single given character. each occurrence of the separating character in self is omitted from the strings returned. Successive strings are taken from the remainder of self after the separating character at the end of the previous yield (if any) has been passed over.


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 : SAME) yld : SAME
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