class STR < $IS_LT{STR},$HASH,$STR,$ELT{CHAR},$FMT
****
Strings. Strings are represented as arrays of characters. Every character is significant.
_
References: Gonnet and Baeza-Yates, "Handbook of Algorithms and Data Structures", Addison Wesley, 1991. Make modification routines private.


Ancestors
$FMT $ELT{_} $ELT $STR
$HASH $IS_EQ $IS_LT{_} AREF{_}



Public


Features
end;
acopyn(s:FSTR,n:INT)
**** copy "n" chars from "s" into "self". Built-in.
aget(ind:INT):T
**** The element of self with index `ind'. Built-in.
**** 's' was just a temporary
r::=new(selfsize+ssize);
r.acopy(p1,s1);
r.acopy(p2,s2);
r.acopy(p3,s3);
r.acopy(p4,s4);
when '\"' then buf:=buf+'\"'
**** A copy of self with each character in upper case. Self may be void.
**** The index of the first character of self which differs from `s'. -1 if self is a prefix of `s'. Either may be void.
if void(self) then return -1 end;
**** Another name for `size'.
r::=new(i); r.acopy(i-asize,self);
end;
**** The index of the first appearance of `c' at location `st' or greater in self or -1 if absent. Self may be void.
if beg=0 then return void end;
**** A string whose characters are the reverse of those in self. Self may be void.
create(c:CHAR):SAME
**** String containing the single character 'c'.
create:SAME
**** An empty string. (Occasionally useful in constructs like `#STR + foo').
end;
create_from_file(nm:STR):SAME
**** Open the file named `nm' in the current directory, create a string containing its contents and then close the file. Return void if there is no such file.
end;
if void(self) then return 0 else return asize end
return r;
acopyn(s:STR,n:INT)
**** copy "n" chars from "s" into "self". Built-in.
r::=new(sz);
**** contained in `s' or -1 if none. Self or `s' may be void.
r::=new(asize);
if qt then return void
**** Must close internal quotes.
**** by "memcmp" in MACROS.
is_eq(arg: $OB): BOOL
else return false end
else
if c.is_gt(sc) then return false
**** True if `s' is lexicographically before self or equal to it. Either may be void.
else
**** True if `s' is lexicographically before self. Either may be void.
r.aset!(c) end;
end;
**** True if each alphabetic character of self is lower case. Self may be void.
if ns=0 then return void end;
end;
**** Specialized versions of plus
**** the following ones could be optimized if one gets excited about it
if void(sarg) then return self end;
**** r::=#FSTR(size);
______loop_r:=r.push(elt!);_end;
______return_r;
______end;
end;
end;
substring(beg,num:INT):SAME
**** The substring with `num' charcters whose first character has index `beg'. Self may be void if beg=0 and num=0.
r::=0; loop if s.contains(elt!) then r:=r+1 end end;
if void(self) then return -1 end;
r.aset!(c)
end;
if ~s.contains(c) then r.aset!(c) end end;
end;
return false
loop if s.contains(elt!) then return true end end;
loop r.acopy(0.step!(i,asize),self) end;
return r
return -1
end;
r.acopy(p5,s5);
**** The first `i' characters of self. Self may be void if i=0.
**** Self may be void.
**** True if each alphabetic character of self is upper case. Self may be void.

Iters
if void(s) then return 0 end;
loop until!(i = sz); yield [i]; i := i + 1; end;
loop until!(i = sz); yield [i]; i := i + 1; end;
**** The character at index `i' of self.
loop until!(i = sz); yield [i]; i := i + 1; end;
i:=i+1;


Private

aclear
**** Set each element of self to nil. Built-in.
acopy(beg,num,srcbeg:INT, src:SAME)
**** Copy `num' elements from `src' to self starting at index `beg' of self and index `srcbeg' of `src'. Built-in.
acopy(beg,num:INT, src:SAME)
**** Copy `num' elements from `src' to self starting at index `beg' of self.
acopy(beg:INT, src:SAME)
**** Copy as many elements from `src' to self as will fit when starting at index `beg' of self.
acopy(src:SAME)
**** Copy as many elements from `src' to self as will fit. Built-in.
aelt!(once beg:INT):T
**** Yield each element of self starting at `beg'. Built-in.
aelt!(once beg,once num:INT):T
**** Yield `num' successive elements of self starting at index `beg'. Built-in.
aelt!(once beg,once num,once step:INT):T
**** Yield `num' elements of self starting at `beg' and stepping by `step' which must not be zero. Built-in.
aelt!:T
**** Yield each element of self in order. Built-in.
aind!:INT
**** Yield the indices of self in order.
aset!(val:T)
**** Set successive elements of self to the values `val'. Built-in.
aset!(once beg:INT,val:T)
**** Set successive elements of self starting at `beg' to the values `val'.
aset!(once beg,once num:INT,val:T)
**** Set `num' successive elements of self starting at `beg' to the values `val'.
aset!(once beg,once num,once step:INT, val:T)
**** Set `num' elements of self starting at `beg' stepping by `step' to the values `val'. `step' must not be zero.
aset(ind:INT, val:T)
**** Set the element of self with index `ind' to `val'. Built-in.
asize:INT
**** The number of elements in self. Classes which inherit this may replace this by a constant to get constant sized objects (and the compiler may optimize certain operations in this case). Built-in.
shared buf:FSTR;
**** Character buffer.
shared buf:FSTR;
**** Character buffer.
create(n:INT):SAME
**** A new array with `n' elements.
is_empty:BOOL
**** True if self has no characters. Self may be void.
is_legal_aelts_arg( beg, num, step:INT) :BOOL
**** True if the arguments are legal values for `aelts'.