Changeset 681e12f


Ignore:
Timestamp:
Jan 4, 2024, 11:58:49 AM (12 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
be10079
Parents:
8b4faf6
Message:

formatting, change cmp to strcmp, add strlen and strcat

Location:
libcfa/src/collections
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/collections/string.cfa

    r8b4faf6 r681e12f  
    1010// Created On       : Fri Sep 03 11:00:00 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Oct 18 21:52:09 2023
    13 // Update Count     : 208
     12// Last Modified On : Thu Jan  4 11:27:37 2024
     13// Update Count     : 233
    1414//
    1515
     
    3030
    3131
    32 void ?{}( string & this ) {
    33     (this.inner) { malloc() };
    34     ?{}( *this.inner );
     32void ?{}( string & s ) {
     33    (s.inner) { malloc() };
     34    ?{}( *s.inner );
    3535}
    3636
    3737// private (not in header)
    38 static void ?{}( string & this, string_res & src, size_t start, size_t end ) {
    39     (this.inner) { malloc() };
    40     ?{}( *this.inner, src, SHARE_EDITS, start, end );
    41 }
    42 
    43 void ?{}( string & this, const string & other ) {
    44     (this.inner) { malloc() };
    45     ?{}( *this.inner, *other.inner, COPY_VALUE );
    46 }
    47 
    48 void ?{}( string & this, string & other ) {
    49     ?{}( this, (const string &) other );
    50 }
    51 
    52 void ?{}( string & this, const char * val ) {
    53     (this.inner) { malloc() };
    54     ?{}( *this.inner, val );
    55 }
    56 
    57 void ?{}( string & this, const char * buffer, size_t bsize) {
    58     (this.inner) { malloc() };
    59     ?{}( *this.inner, buffer, bsize );
    60 }
    61 
    62 void ^?{}( string & this ) {
    63     ^(*this.inner){};
    64     free( this.inner );
    65     this.inner = 0p;
     38static void ?{}( string & s, string_res & src, size_t start, size_t end ) {
     39    (s.inner) { malloc() };
     40    ?{}( *s.inner, src, SHARE_EDITS, start, end );
     41}
     42
     43void ?{}( string & s, const string & c ) {
     44    (s.inner) { malloc() };
     45    ?{}( *s.inner, *c.inner, COPY_VALUE );
     46}
     47
     48void ?{}( string & s, string & c ) {
     49    ?{}( s, (const string &) c );
     50}
     51
     52void ?{}( string & s, const char * val ) {
     53    (s.inner) { malloc() };
     54    ?{}( *s.inner, val );
     55}
     56
     57void ?{}( string & s, const char * buffer, size_t bsize) {
     58    (s.inner) { malloc() };
     59    ?{}( *s.inner, buffer, bsize );
     60}
     61
     62void ^?{}( string & s ) {
     63    ^(*s.inner){};
     64    free( s.inner );
     65    s.inner = 0p;
    6666}
    6767
     
    6969// Alternate construction: request shared edits
    7070
    71 string_WithSharedEdits ?`shareEdits( string & this ) {
    72     string_WithSharedEdits ret = { &this };
    73     return ret;
    74 }
    75 
    76 void ?{}( string & this, string_WithSharedEdits src ) {
    77     ?{}( this, *src.s->inner, 0, src.s->inner->Handle.lnth);
     71string_WithSharedEdits ?`shareEdits( string & s ) {
     72    string_WithSharedEdits ret = { &s };
     73    return ret;
     74}
     75
     76void ?{}( string & s, string_WithSharedEdits src ) {
     77    ?{}( s, *src.s->inner, 0, src.s->inner->Handle.lnth);
    7878}
    7979
     
    8181// Assignment
    8282
    83 void ?=?( string & this, const char * val ) {
    84     (*this.inner) = val;
    85 }
    86 
    87 void ?=?(string & this, const string & other) {
    88     (*this.inner) = (*other.inner);
    89 }
    90 
    91 void ?=?( string & this, char val ) {
    92     (*this.inner) = val;
    93 }
    94 
    95 string & ?=?(string & this, string & other) { //// <---- straw man change
    96     (*this.inner) = (*other.inner);
    97     return this;
     83void ?=?( string & s, const char * val ) {
     84    (*s.inner) = val;
     85}
     86
     87void ?=?(string & s, const string & c) {
     88    (*s.inner) = (*c.inner);
     89}
     90
     91void ?=?( string & s, char val ) {
     92    (*s.inner) = val;
     93}
     94
     95string & ?=?(string & s, string & c) { //// <---- straw man change
     96    (*s.inner) = (*c.inner);
     97    return s;
    9898}
    9999
     
    102102// Input-Output
    103103
    104 ofstream & ?|?( ofstream & out, const string & this ) {
    105     return out | (*this.inner); // print internal string_res
    106 }
    107 
    108 void ?|?( ofstream & out, const string & this ) {
    109     (ofstream &)(out | (*this.inner)); ends( out );
     104ofstream & ?|?( ofstream & out, const string & s ) {
     105    return out | (*s.inner); // print internal string_res
     106}
     107
     108void ?|?( ofstream & out, const string & s ) {
     109    (ofstream &)(out | (*s.inner)); ends( out );
    110110}
    111111
     
    124124}
    125125
    126 ifstream & ?|?(ifstream & in, string & this) {
    127     return in | (*this.inner); // read to internal string_res
    128 }
    129 
    130 void ?|?( ifstream & in, string & this ) {
    131     in | (*this.inner);
     126ifstream & ?|?(ifstream & in, string & s) {
     127    return in | (*s.inner); // read to internal string_res
     128}
     129
     130void ?|?( ifstream & in, string & s ) {
     131    in | (*s.inner);
    132132}
    133133
     
    144144// Slicing
    145145
    146 string ?()( string & this, size_t start, size_t end ) {
    147     string ret = { *this.inner, start, end };
     146string ?()( string & s, size_t start, size_t end ) {
     147    string ret = { *s.inner, start, end };
    148148    return ret`shareEdits;
    149149}
    150150
    151 string ?()( string & this, size_t start ) {
    152     string ret = { *this.inner, start, size( this ) };
     151string ?()( string & s, size_t start ) {
     152    string ret = { *s.inner, start, size( s ) };
    153153    return ret`shareEdits;
    154154}
     
    157157// Comparison
    158158
    159 int  cmp (const string &s1, const string &s2) { return cmp(*s1.inner , *s2.inner); }
    160 bool ?==?(const string &s1, const string &s2) { return     *s1.inner == *s2.inner ; }
    161 bool ?!=?(const string &s1, const string &s2) { return     *s1.inner != *s2.inner ; }
    162 bool ?>? (const string &s1, const string &s2) { return     *s1.inner >  *s2.inner ; }
    163 bool ?>=?(const string &s1, const string &s2) { return     *s1.inner >= *s2.inner ; }
    164 bool ?<=?(const string &s1, const string &s2) { return     *s1.inner <= *s2.inner ; }
    165 bool ?<? (const string &s1, const string &s2) { return     *s1.inner <  *s2.inner ; }
    166 
    167 int  cmp (const string &s1, const char*   s2) { return cmp(*s1.inner ,   s2      ); }
    168 bool ?==?(const string &s1, const char*   s2) { return     *s1.inner ==  s2       ; }
    169 bool ?!=?(const string &s1, const char*   s2) { return     *s1.inner !=  s2       ; }
    170 bool ?>? (const string &s1, const char*   s2) { return     *s1.inner >   s2       ; }
    171 bool ?>=?(const string &s1, const char*   s2) { return     *s1.inner >=  s2       ; }
    172 bool ?<=?(const string &s1, const char*   s2) { return     *s1.inner <=  s2       ; }
    173 bool ?<? (const string &s1, const char*   s2) { return     *s1.inner <   s2       ; }
    174 
    175 int  cmp (const char*   s1, const string &s2) { return cmp( s1       , *s2.inner); }
    176 bool ?==?(const char*   s1, const string &s2) { return      s1       == *s2.inner ; }
    177 bool ?!=?(const char*   s1, const string &s2) { return      s1       != *s2.inner ; }
    178 bool ?>? (const char*   s1, const string &s2) { return      s1       >  *s2.inner ; }
    179 bool ?>=?(const char*   s1, const string &s2) { return      s1       >= *s2.inner ; }
    180 bool ?<=?(const char*   s1, const string &s2) { return      s1       <= *s2.inner ; }
    181 bool ?<? (const char*   s1, const string &s2) { return      s1       <  *s2.inner ; }
     159int  strcmp(const string & s1, const string & s2) { return strcmp(*s1.inner, *s2.inner); }
     160bool ?==?(const string & s1, const string & s2) { return *s1.inner == *s2.inner; }
     161bool ?!=?(const string & s1, const string & s2) { return *s1.inner != *s2.inner; }
     162bool ?>? (const string & s1, const string & s2) { return *s1.inner >  *s2.inner; }
     163bool ?>=?(const string & s1, const string & s2) { return *s1.inner >= *s2.inner; }
     164bool ?<=?(const string & s1, const string & s2) { return *s1.inner <= *s2.inner; }
     165bool ?<? (const string & s1, const string & s2) { return *s1.inner <  *s2.inner; }
     166
     167int  strcmp(const string & s1, const char * s2) { return strcmp(*s1.inner, s2 ); }
     168bool ?==?(const string & s1, const char * s2) { return *s1.inner == s2; }
     169bool ?!=?(const string & s1, const char * s2) { return *s1.inner != s2; }
     170bool ?>? (const string & s1, const char * s2) { return *s1.inner >  s2; }
     171bool ?>=?(const string & s1, const char * s2) { return *s1.inner >= s2; }
     172bool ?<=?(const string & s1, const char * s2) { return *s1.inner <= s2; }
     173bool ?<? (const string & s1, const char * s2) { return *s1.inner <  s2; }
     174
     175int  strcmp(const char * s1, const string & s2) { return strcmp( s1, *s2.inner); }
     176bool ?==?(const char * s1, const string & s2) { return s1 == *s2.inner; }
     177bool ?!=?(const char * s1, const string & s2) { return s1 != *s2.inner; }
     178bool ?>? (const char * s1, const string & s2) { return s1 >  *s2.inner; }
     179bool ?>=?(const char * s1, const string & s2) { return s1 >= *s2.inner; }
     180bool ?<=?(const char * s1, const string & s2) { return s1 <= *s2.inner; }
     181bool ?<? (const char * s1, const string & s2) { return s1 <  *s2.inner; }
    182182
    183183
     
    186186
    187187size_t size(const string & s) {
    188     return size( * s.inner );
     188    return size( *s.inner );
    189189}
    190190
     
    192192// Concatenation
    193193
    194 void ?+=?(string & s, char other) {
    195     (*s.inner) += other;
     194void ?+=?(string & s, char c) {
     195    (*s.inner) += c;
    196196}
    197197
     
    200200}
    201201
    202 void ?+=?(string & s, const char * other) {
    203     (*s.inner) += other;
    204 }
    205 
    206 string ?+?(const string & s, char other) {
     202void ?+=?(string & s, const char * c) {
     203    (*s.inner) += c;
     204}
     205
     206string ?+?(const string & s, char c) {
    207207    string ret = s;
    208     ret += other;
     208    ret += c;
    209209    return ret;
    210210}
     
    222222}
    223223
    224 string ?+?(const string & s, const char * other) {
     224string ?+?(const string & s, const char * c) {
    225225    string ret = s;
    226     ret += other;
     226    ret += c;
    227227    return ret;
    228228}
     
    339339// charclass, include, exclude
    340340
    341 void ?{}( charclass & this, const string & chars) {
    342     (this.inner) { malloc() };
    343     ?{}( *this.inner, *(const string_res *)chars.inner );
    344 }
    345 
    346 void ?{}( charclass & this, const char * chars ) {
    347     (this.inner) { malloc() };
    348     ?{}( *this.inner, chars );
    349 }
    350 
    351 void ?{}( charclass & this, const char * chars, size_t charssize ) {
    352     (this.inner) { malloc() };
    353     ?{}( *this.inner, chars, charssize );
    354 }
    355 
    356 void ^?{}( charclass & this ) {
    357     ^(*this.inner){};
    358     free( this.inner );
    359     this.inner = 0p;
     341void ?{}( charclass & s, const string & chars) {
     342    (s.inner) { malloc() };
     343    ?{}( *s.inner, *(const string_res *)chars.inner );
     344}
     345
     346void ?{}( charclass & s, const char * chars ) {
     347    (s.inner) { malloc() };
     348    ?{}( *s.inner, chars );
     349}
     350
     351void ?{}( charclass & s, const char * chars, size_t charssize ) {
     352    (s.inner) { malloc() };
     353    ?{}( *s.inner, chars, charssize );
     354}
     355
     356void ^?{}( charclass & s ) {
     357    ^(*s.inner){};
     358    free( s.inner );
     359    s.inner = 0p;
    360360}
    361361
  • libcfa/src/collections/string.hfa

    r8b4faf6 r681e12f  
    1010// Created On       : Fri Sep 03 11:00:00 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Sep  2 11:26:28 2023
    13 // Update Count     : 55
     12// Last Modified On : Thu Jan  4 11:27:35 2024
     13// Update Count     : 75
    1414//
    1515
     
    2929// Getters
    3030size_t size(const string & s);
     31static inline size_t strlen(const string & s) { return size( s ); }
    3132
    3233// RAII, assignment
    33 void ?{}(string & this); // empty string
     34void ?{}(string & s); // empty string
    3435void ?{}(string & s, const char * initial); // copy from string literal (NULL-terminated)
    3536void ?{}(string & s, const char * buffer, size_t bsize); // copy specific length from buffer
     
    3839void ?{}(string & s, string & s2);
    3940
    40 void ?=?(string & s, const char * other); // copy assignment from literal
    41 void ?=?(string & s, const string & other);
    42 void ?=?(string & s, char other);
    43 string & ?=?(string & s, string & other);  // surprising ret seems to help avoid calls to autogen
     41void ?=?(string & s, const char * c); // copy assignment from literal
     42static inline string & strcpy(string & s, const char * c) { s = c; return s; }
     43void ?=?(string & s, const string & c);
     44static inline string & strcpy(string & s, const string c) { s = c; return s; }
     45void ?=?(string & s, char c);
     46string & ?=?(string & s, string & c);  // surprising ret seems to help avoid calls to autogen
    4447//string ?=?( string &, string ) = void;
    4548void ^?{}(string & s);
     
    4952    string * s;
    5053};
    51 string_WithSharedEdits ?`shareEdits( string & this );
    52 void ?{}( string & this, string_WithSharedEdits src );
     54string_WithSharedEdits ?`shareEdits( string & s );
     55void ?{}( string & s, string_WithSharedEdits src );
    5356
    5457// IO Operator
     
    5659void ?|?(ofstream & out, const string & s);
    5760ifstream & ?|?(ifstream & in, string & s);
    58 void ?|?( ifstream & in, string & this );
     61void ?|?( ifstream & in, string & s );
    5962
    6063static inline {
     
    8184        _Istream_Sstr wdi( unsigned int rwd, string & s ) { return (_Istream_Sstr)@{ s, {{0p}, rwd, {.flags.rwd : true}} }; }
    8285        _Istream_Sstr getline( string & s, const char delimiter = '\n' ) {
    83                 return (_Istream_Sstr)@{ s, {{.delimiter : { delimiter, '\0' } }, -1, {.flags.delimiter : true, .flags.inex : true}} };
     86                return (_Istream_Sstr)@{ s, {{.delimiters : { delimiter, '\0' } }, -1, {.flags.delimiter : true, .flags.inex : true}} };
    8487        }
    8588        _Istream_Sstr & getline( _Istream_Sstr & fmt, const char delimiter = '\n' ) {
    86                 fmt.delimiter[0] = delimiter; fmt.delimiter[1] = '\0'; fmt.flags.delimiter = true; fmt.flags.inex = true; return fmt;
     89                fmt.delimiters[0] = delimiter; fmt.delimiters[1] = '\0'; fmt.flags.delimiter = true; fmt.flags.inex = true; return fmt;
    8790        }
    8891        _Istream_Sstr incl( const char scanset[], string & s ) { return (_Istream_Sstr)@{ s, {{scanset}, -1, {.flags.inex : false}} }; }
     
    97100
    98101// Concatenation
    99 void ?+=?(string & s, char other); // append a character
     102void ?+=?(string & s, char c); // append a character
    100103void ?+=?(string & s, const string & s2); // append-concatenate to first string
    101 void ?+=?(string & s, const char * other); // append-concatenate to first string
    102 string ?+?(const string & s, char other); // add a character to a copy of the string
     104static inline string & strcat(string & s, const string & s2) { s += s2; return s; }
     105void ?+=?(string & s, const char * s2); // append-concatenate to first string
     106static inline string & strcat(string & s, const char * c) { s += c; return s; }
     107string ?+?(const string & s, char c); // add a character to a copy of the string
    103108string ?+?(const string & s, const string & s2); // copy and concatenate both strings
    104109string ?+?(const char * s1, const char * s2); // concatenate both strings
    105 string ?+?(const string & s, const char * other); // copy and concatenate with NULL-terminated string
     110string ?+?(const string & s, const char * c); // copy and concatenate with NULL-terminated string
    106111
    107112// Repetition
     
    116121
    117122// Comparisons
    118 int  cmp (const string &, const string &);
     123int  strcmp (const string &, const string &);
    119124bool ?==?(const string &, const string &);
    120125bool ?!=?(const string &, const string &);
     
    124129bool ?<? (const string &, const string &);
    125130
    126 int  cmp (const string &, const char*);
    127 bool ?==?(const string &, const char*);
    128 bool ?!=?(const string &, const char*);
    129 bool ?>? (const string &, const char*);
    130 bool ?>=?(const string &, const char*);
    131 bool ?<=?(const string &, const char*);
    132 bool ?<? (const string &, const char*);
    133 
    134 int  cmp (const char*, const string &);
    135 bool ?==?(const char*, const string &);
    136 bool ?!=?(const char*, const string &);
    137 bool ?>? (const char*, const string &);
    138 bool ?>=?(const char*, const string &);
    139 bool ?<=?(const char*, const string &);
    140 bool ?<? (const char*, const string &);
     131int  strcmp (const string &, const char *);
     132bool ?==?(const string &, const char *);
     133bool ?!=?(const string &, const char *);
     134bool ?>? (const string &, const char *);
     135bool ?>=?(const string &, const char *);
     136bool ?<=?(const string &, const char *);
     137bool ?<? (const string &, const char *);
     138
     139int  strcmp (const char *, const string &);
     140bool ?==?(const char *, const string &);
     141bool ?!=?(const char *, const string &);
     142bool ?>? (const char *, const string &);
     143bool ?>=?(const char *, const string &);
     144bool ?<=?(const char *, const string &);
     145bool ?<? (const char *, const string &);
    141146
    142147
    143148// Slicing
    144 string ?()( string & this, size_t start, size_t end );  // TODO const?
    145 string ?()( string & this, size_t start);
     149string ?()( string & s, size_t start, size_t end );  // TODO const?
     150string ?()( string & s, size_t start);
    146151
    147152// String search
     
    177182
    178183
    179 
    180184struct charclass {
    181185    charclass_res * inner;
  • libcfa/src/collections/string_res.cfa

    r8b4faf6 r681e12f  
    1010// Created On       : Fri Sep 03 11:00:00 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Oct 18 21:54:54 2023
    13 // Update Count     : 15
     12// Last Modified On : Tue Jan  2 13:20:27 2024
     13// Update Count     : 34
    1414//
    1515
     
    2222// Workaround is:  EndVbyte = TEMP_ALLOC(char, CurrSize)
    2323// Should be:      EndVbyte = alloc(CurrSize)
    24 #define TEMP_ALLOC(T, n) (( T* ) malloc( n * sizeof( T ) ))
     24#define TEMP_ALLOC(T, n) (( T * ) malloc( n * sizeof( T ) ))
    2525
    2626#include <assert.h>
     
    3333
    3434struct VbyteHeap {
    35 
    36     int NoOfCompactions;                                // number of compactions of the byte area
    37     int NoOfExtensions;                                 // number of extensions in the size of the byte area
    38     int NoOfReductions;                                 // number of reductions in the size of the byte area
     35    int NoOfCompactions;                                                // number of compactions of the byte area
     36    int NoOfExtensions;                                                 // number of extensions in the size of the byte area
     37    int NoOfReductions;                                                 // number of reductions in the size of the byte area
    3938   
    40     int InitSize;                                       // initial number of bytes in the byte-string area
    41     int CurrSize;                                       // current number of bytes in the byte-string area
    42     char *StartVbyte;                                   // pointer to the `st byte of the start of the byte-string area
    43     char *EndVbyte;                                     // pointer to the next byte after the end of the currently used portion of byte-string area
    44     void *ExtVbyte;                                     // pointer to the next byte after the end of the byte-string area
    45 
    46     HandleNode Header;                                  // header node for handle list
     39    int InitSize;                                                               // initial number of bytes in the byte-string area
     40    int CurrSize;                                                               // current number of bytes in the byte-string area
     41    char *StartVbyte;                                                   // pointer to the `st byte of the start of the byte-string area
     42    char *EndVbyte;                                                             // pointer to the next byte after the end of the currently used portion of byte-string area
     43    void *ExtVbyte;                                                             // pointer to the next byte after the end of the byte-string area
     44
     45    HandleNode Header;                                                  // header node for handle list
    4746}; // VbyteHeap
    4847
    4948   
    50 static void compaction( VbyteHeap & );                          // compaction of the byte area
    51 static void garbage( VbyteHeap &, int );                                // garbage collect the byte area
     49static void compaction( VbyteHeap & );                  // compaction of the byte area
     50static void garbage( VbyteHeap &, int );                // garbage collect the byte area
    5251static void extend( VbyteHeap &, int );                 // extend the size of the byte area
    5352static void reduce( VbyteHeap &, int );                 // reduce the size of the byte area
     
    6766// Allocate the storage for the variable sized area and intialize the heap variables.
    6867
    69 static void ?{}( VbyteHeap & this, size_t Size ) with(this) {
    70 #ifdef VbyteDebug
    71     serr | "enter:VbyteHeap::VbyteHeap, this:" | &this | " Size:" | Size;
     68static void ?{}( VbyteHeap & s, size_t Size ) with(s) {
     69#ifdef VbyteDebug
     70    serr | "enter:VbyteHeap::VbyteHeap, s:" | &s | " Size:" | Size;
    7271#endif // VbyteDebug
    7372    NoOfCompactions = NoOfExtensions = NoOfReductions = 0;
     
    7675    ExtVbyte = (void *)( StartVbyte + CurrSize );
    7776    Header.flink = Header.blink = &Header;
    78     Header.ulink = & this;
     77    Header.ulink = &s;
    7978#ifdef VbyteDebug
    8079    HeaderPtr = &Header;
    81     serr | "exit:VbyteHeap::VbyteHeap, this:" | &this;
     80    serr | "exit:VbyteHeap::VbyteHeap, s:" | &s;
    8281#endif // VbyteDebug
    8382} // VbyteHeap
     
    8685// Release the dynamically allocated storage for the byte area.
    8786
    88 static void ^?{}( VbyteHeap & this ) with(this) {
     87static void ^?{}( VbyteHeap & s ) with(s) {
    8988    free( StartVbyte );
    9089} // ~VbyteHeap
     
    9796// creator.
    9897
    99 static void ?{}( HandleNode & this ) with(this) {
    100 #ifdef VbyteDebug
    101     serr | "enter:HandleNode::HandleNode, this:" | &this;
     98static void ?{}( HandleNode & s ) with(s) {
     99#ifdef VbyteDebug
     100    serr | "enter:HandleNode::HandleNode, s:" | &s;
    102101#endif // VbyteDebug
    103102    s = 0;
    104103    lnth = 0;
    105104#ifdef VbyteDebug
    106     serr | "exit:HandleNode::HandleNode, this:" | &this;
     105    serr | "exit:HandleNode::HandleNode, s:" | &s;
    107106#endif // VbyteDebug
    108107} // HandleNode
     
    112111// collection.
    113112
    114 static void ?{}( HandleNode & this, VbyteHeap & vh ) with(this) {
    115 #ifdef VbyteDebug
    116     serr | "enter:HandleNode::HandleNode, this:" | &this;
     113static void ?{}( HandleNode & s, VbyteHeap & vh ) with(s) {
     114#ifdef VbyteDebug
     115    serr | "enter:HandleNode::HandleNode, s:" | &s;
    117116#endif // VbyteDebug
    118117    s = 0;
    119118    lnth = 0;
    120119    ulink = &vh;
    121     AddThisAfter( this, *vh.Header.blink );
    122 #ifdef VbyteDebug
    123     serr | "exit:HandleNode::HandleNode, this:" | &this;
     120    AddThisAfter( s, *vh.Header.blink );
     121#ifdef VbyteDebug
     122    serr | "exit:HandleNode::HandleNode, s:" | &s;
    124123#endif // VbyteDebug
    125124} // HandleNode
     
    129128// is the responsibility of the creator to destroy it.
    130129
    131 static void ^?{}( HandleNode & this ) with(this) {
    132 #ifdef VbyteDebug
    133     serr | "enter:HandleNode::~HandleNode, this:" | & this;
     130static void ^?{}( HandleNode & s ) with(s) {
     131#ifdef VbyteDebug
     132    serr | "enter:HandleNode::~HandleNode, s:" | & s;
    134133    {
    135134        serr | nlOff;
     
    142141    }
    143142#endif // VbyteDebug
    144     DeleteNode( this );
     143    DeleteNode( s );
    145144} // ~HandleNode
    146145
     
    151150static string_sharectx default_string_sharectx = {NEW_SHARING}; // stable bottom of stack
    152151
    153 void ?{}( string_sharectx & this, StringSharectx_Mode mode ) with( this ) {
     152void ?{}( string_sharectx & s, StringSharectx_Mode mode ) with( s ) {
    154153    (older){ ambient_string_sharectx };
    155154    if ( mode == NEW_SHARING ) {
     
    159158        (activeHeap){ 0p };
    160159    }
    161     ambient_string_sharectx = & this;
    162 }
    163 
    164 void ^?{}( string_sharectx & this ) with( this ) {
     160    ambient_string_sharectx = & s;
     161}
     162
     163void ^?{}( string_sharectx & s ) with( s ) {
    165164    if ( activeHeap ) delete( activeHeap );
    166165
    167     // unlink this from older-list starting from ambient_string_sharectx
    168     // usually, this==ambient_string_sharectx and the loop runs zero times
     166    // unlink s from older-list starting from ambient_string_sharectx
     167    // usually, s==ambient_string_sharectx and the loop runs zero times
    169168    string_sharectx *& c = ambient_string_sharectx;
    170     while ( c != &this ) &c = &c->older;              // find this
    171     c = this.older;                                   // unlink
     169    while ( c != &s ) &c = &c->older;              // find s
     170    c = s.older;                                   // unlink
    172171}
    173172
     
    193192
    194193// Returns the size of the string in bytes
    195 size_t size(const string_res &s) with(s) {
     194size_t size(const string_res & s) with(s) {
    196195    return Handle.lnth;
    197196}
    198197
    199198// Output operator
    200 ofstream & ?|?(ofstream &out, const string_res &s) {
     199ofstream & ?|?(ofstream & out, const string_res & s) {
    201200        // CFA string is NOT null terminated, so print exactly lnth characters in a minimum width of 0.
    202201        out | wd( 0, s.Handle.lnth, s.Handle.s ) | nonl;
     
    204203}
    205204
    206 void ?|?(ofstream &out, const string_res &s) {
     205void ?|?(ofstream & out, const string_res & s) {
    207206        (ofstream &)(out | s); ends( out );
    208207}
    209208
    210209// Input operator
    211 ifstream & ?|?(ifstream &in, string_res &s) {
    212 
     210ifstream & ?|?(ifstream & in, string_res & s) {
    213211    // Reading into a temp before assigning to s is near zero overhead in typical cases because of sharing.
    214212    // If s is a substring of something larger, simple assignment takes care of that case correctly.
     
    238236                        *(temp.Handle.ulink->EndVbyte) = '\0';   // pre-assign empty cstring
    239237            in | wdi( lenReadable, temp.Handle.ulink->EndVbyte );
    240         } catch (cstring_length*) {
     238        } catch (cstring_length *) {
    241239            cont = true;
    242240        }
     
    252250}
    253251
    254 void ?|?( ifstream & in, string_res & this ) {
    255     (ifstream &)(in | this);
     252void ?|?( ifstream & in, string_res & s ) {
     253    (ifstream &)(in | s);
    256254}
    257255
     
    274272                cont = true;
    275273        } finally {
    276                 if ( ! cf.flags.ignore &&                                               // ok to initialize string
    277                                 cstr[0] != '\0' ) {                                             // something was read
     274                if ( ! cf.flags.ignore                                                  // ok to initialize string
     275//                       &&     cstr[0] != '\0'                                                 // something was read
     276                        ) {
    278277                        *(f.s) = cstr;
    279278                }
     
    287286                        cont = true;                                                            // continue not allowed
    288287                } finally {
    289                         if ( ! cf.flags.ignore &&
    290                                         cstr[0] != '\0' ) {                                     // something was read
     288                        if ( ! cf.flags.ignore && cstr[0] != '\0' ) { // something was read
    291289                                *(f.s) += cstr;                                                 // build string chunk at a time
    292290                        }
     
    302300
    303301// Empty constructor
    304 void ?{}(string_res &s) with(s) {
     302void ?{}(string_res & s) with(s) {
    305303    if( ambient_string_sharectx->activeHeap ) {
    306304        (Handle){ * ambient_string_sharectx->activeHeap };
     
    317315}
    318316
    319 static void eagerCopyCtorHelper(string_res &s, const char* rhs, size_t rhslnth) with(s) {
     317static void eagerCopyCtorHelper(string_res & s, const char* rhs, size_t rhslnth) with(s) {
    320318    if( ambient_string_sharectx->activeHeap ) {
    321319        (Handle){ * ambient_string_sharectx->activeHeap };
     
    333331
    334332// Constructor from a raw buffer and size
    335 void ?{}(string_res &s, const char* rhs, size_t rhslnth) with(s) {
     333void ?{}(string_res & s, const char* rhs, size_t rhslnth) with(s) {
    336334    eagerCopyCtorHelper(s, rhs, rhslnth);
    337335}
    338336
    339337// private ctor (not in header): use specified heap (ignore ambient) and copy chars in
    340 void ?{}( string_res &s, VbyteHeap & heap, const char* rhs, size_t rhslnth ) with(s) {
     338void ?{}( string_res & s, VbyteHeap & heap, const char* rhs, size_t rhslnth ) with(s) {
    341339    (Handle){ heap };
    342340    Handle.s = VbyteAlloc(*Handle.ulink, rhslnth);
     
    349347
    350348// General copy constructor
    351 void ?{}(string_res &s, const string_res & s2, StrResInitMode mode, size_t start, size_t end ) {
     349void ?{}(string_res & s, const string_res & s2, StrResInitMode mode, size_t start, size_t end ) {
    352350
    353351    verify( start <= end && end <= s2.Handle.lnth );
     
    394392}
    395393
    396 static void assignEditSet(string_res & this, string_res * shareEditSetStartPeer, string_res * shareEditSetEndPeer,
     394static void assignEditSet(string_res & s, string_res * shareEditSetStartPeer, string_res * shareEditSetEndPeer,
    397395    char * resultSesStart,
    398396    size_t resultSesLnth,
     
    400398
    401399    char * beforeBegin = shareEditSetStartPeer->Handle.s;
    402     size_t beforeLen = this.Handle.s - beforeBegin;
    403 
    404     char * afterBegin = this.Handle.s + this.Handle.lnth;
     400    size_t beforeLen = s.Handle.s - beforeBegin;
     401
     402    char * afterBegin = s.Handle.s + s.Handle.lnth;
    405403    size_t afterLen = shareEditSetEndPeer->Handle.s + shareEditSetEndPeer->Handle.lnth - afterBegin;
    406404
    407     size_t oldLnth = this.Handle.lnth;
    408 
    409     this.Handle.s = resultSesStart + beforeLen;
    410     this.Handle.lnth = bsize;
     405    size_t oldLnth = s.Handle.lnth;
     406
     407    s.Handle.s = resultSesStart + beforeLen;
     408    s.Handle.lnth = bsize;
    411409    if (resultPadPosition)
    412         MoveThisAfter( this.Handle, *resultPadPosition );
     410        MoveThisAfter( s.Handle, *resultPadPosition );
    413411
    414412    // adjust all substring string and handle locations, and check if any substring strings are outside the new base string
    415413    char *limit = resultSesStart + resultSesLnth;
    416     for ( string_res * p = this.shareEditSet_next; p != &this; p = p->shareEditSet_next ) {
     414    for ( string_res * p = s.shareEditSet_next; p != &s; p = p->shareEditSet_next ) {
    417415        verify (p->Handle.s >= beforeBegin);
    418416        if ( p->Handle.s >= afterBegin ) {
     
    439437                // take end as end-anchored
    440438                // stretch-shrink p according to the edit
    441                 p->Handle.lnth += this.Handle.lnth;
     439                p->Handle.lnth += s.Handle.lnth;
    442440                p->Handle.lnth -= oldLnth;
    443441            }
     
    452450                // p ends during the edit; p does not include the last character replaced
    453451                // set p to empty string at start of edit
    454                 p->Handle.s = this.Handle.s;
     452                p->Handle.s = s.Handle.s;
    455453                p->Handle.lnth = 0;
    456454            } else {
     
    458456                // clip start of p to start at end of edit
    459457                int charsToClip = afterBegin - p->Handle.s;
    460                 p->Handle.s = this.Handle.s + this.Handle.lnth;
     458                p->Handle.s = s.Handle.s + s.Handle.lnth;
    461459                p->Handle.lnth -= charsToClip;
    462460            }
     
    467465}
    468466
    469 // traverse the share-edit set (SES) to recover the range of a base string to which `this` belongs
    470 static void locateInShareEditSet( string_res &this, string_res *&shareEditSetStartPeer, string_res *&shareEditSetEndPeer ) {
    471     shareEditSetStartPeer = & this;
    472     shareEditSetEndPeer = & this;
    473     for (string_res * editPeer = this.shareEditSet_next; editPeer != &this; editPeer = editPeer->shareEditSet_next) {
     467// traverse the share-edit set (SES) to recover the range of a base string to which `s` belongs
     468static void locateInShareEditSet( string_res & s, string_res *& shareEditSetStartPeer, string_res *& shareEditSetEndPeer ) {
     469    shareEditSetStartPeer = & s;
     470    shareEditSetEndPeer = & s;
     471    for (string_res * editPeer = s.shareEditSet_next; editPeer != &s; editPeer = editPeer->shareEditSet_next) {
    474472        if ( editPeer->Handle.s < shareEditSetStartPeer->Handle.s ) {
    475473            shareEditSetStartPeer = editPeer;
     
    481479}
    482480
    483 static string_res & assign_(string_res &this, const char* buffer, size_t bsize, const string_res & valSrc) {
     481static string_res & assign_(string_res & s, const char* buffer, size_t bsize, const string_res & valSrc) {
    484482
    485483    string_res * shareEditSetStartPeer;
    486484    string_res * shareEditSetEndPeer;
    487     locateInShareEditSet( this, shareEditSetStartPeer, shareEditSetEndPeer );
     485    locateInShareEditSet( s, shareEditSetStartPeer, shareEditSetEndPeer );
    488486
    489487    verify( shareEditSetEndPeer->Handle.s >= shareEditSetStartPeer->Handle.s );
    490488    size_t origEditSetLength = shareEditSetEndPeer->Handle.s + shareEditSetEndPeer->Handle.lnth - shareEditSetStartPeer->Handle.s;
    491     verify( origEditSetLength >= this.Handle.lnth );
    492 
    493     if ( this.shareEditSet_owns_ulink ) {                 // assigning to private context
     489    verify( origEditSetLength >= s.Handle.lnth );
     490
     491    if ( s.shareEditSet_owns_ulink ) {                 // assigning to private context
    494492        // ok to overwrite old value within LHS
    495493        char * prefixStartOrig = shareEditSetStartPeer->Handle.s;
    496         int prefixLen = this.Handle.s - prefixStartOrig;
    497         char * suffixStartOrig = this.Handle.s + this.Handle.lnth;
     494        int prefixLen = s.Handle.s - prefixStartOrig;
     495        char * suffixStartOrig = s.Handle.s + s.Handle.lnth;
    498496        int suffixLen = shareEditSetEndPeer->Handle.s + shareEditSetEndPeer->Handle.lnth - suffixStartOrig;
    499497
    500         int delta = bsize - this.Handle.lnth;
    501         if ( char * oldBytes = VbyteTryAdjustLast( *this.Handle.ulink, delta ) ) {
     498        int delta = bsize - s.Handle.lnth;
     499        if ( char * oldBytes = VbyteTryAdjustLast( *s.Handle.ulink, delta ) ) {
    502500            // growing: copy from old to new
    503             char * dest = VbyteAlloc( *this.Handle.ulink, origEditSetLength + delta );
     501            char * dest = VbyteAlloc( *s.Handle.ulink, origEditSetLength + delta );
    504502            char *destCursor = dest;  memcpy(destCursor, prefixStartOrig, prefixLen);
    505503            destCursor += prefixLen;  memcpy(destCursor, buffer         , bsize    );
    506504            destCursor += bsize;      memcpy(destCursor, suffixStartOrig, suffixLen);
    507             assignEditSet(this, shareEditSetStartPeer, shareEditSetEndPeer,
     505            assignEditSet(s, shareEditSetStartPeer, shareEditSetEndPeer,
    508506                dest,
    509507                origEditSetLength + delta,
     
    513511            // room is already allocated in-place: bubble suffix and overwite middle
    514512            memmove( suffixStartOrig + delta, suffixStartOrig, suffixLen );
    515             memcpy( this.Handle.s, buffer, bsize );
    516 
    517             assignEditSet(this, shareEditSetStartPeer, shareEditSetEndPeer,
     513            memcpy( s.Handle.s, buffer, bsize );
     514
     515            assignEditSet(s, shareEditSetStartPeer, shareEditSetEndPeer,
    518516                shareEditSetStartPeer->Handle.s,
    519517                origEditSetLength + delta,
     
    522520
    523521    } else if (                                           // assigning to shared context
    524         this.Handle.lnth == origEditSetLength &&          // overwriting entire run of SES
     522        s.Handle.lnth == origEditSetLength &&          // overwriting entire run of SES
    525523        & valSrc &&                                       // sourcing from a managed string
    526         valSrc.Handle.ulink == this.Handle.ulink  ) {     // sourcing from same heap
     524        valSrc.Handle.ulink == s.Handle.ulink  ) {     // sourcing from same heap
    527525
    528526        // SES's result will only use characters from the source string => reuse source
    529         assignEditSet(this, shareEditSetStartPeer, shareEditSetEndPeer,
     527        assignEditSet(s, shareEditSetStartPeer, shareEditSetEndPeer,
    530528            valSrc.Handle.s,
    531529            valSrc.Handle.lnth,
     
    537535
    538536        // full string is from start of shareEditSetStartPeer thru end of shareEditSetEndPeer
    539         // `this` occurs in the middle of it, to be replaced
     537        // `s` occurs in the middle of it, to be replaced
    540538        // build up the new text in `pasting`
    541539
    542540        string_res pasting = {
    543             * this.Handle.ulink,                               // maintain same heap, regardless of context
     541            * s.Handle.ulink,                               // maintain same heap, regardless of context
    544542            shareEditSetStartPeer->Handle.s,                   // start of SES
    545             this.Handle.s - shareEditSetStartPeer->Handle.s }; // length of SES, before this
     543            s.Handle.s - shareEditSetStartPeer->Handle.s }; // length of SES, before s
    546544        append( pasting,
    547             buffer,                                            // start of replacement for this
    548             bsize );                                           // length of replacement for this
     545            buffer,                                            // start of replacement for s
     546            bsize );                                           // length of replacement for s
    549547        append( pasting,
    550             this.Handle.s + this.Handle.lnth,                  // start of SES after this
     548            s.Handle.s + s.Handle.lnth,                  // start of SES after s
    551549            shareEditSetEndPeer->Handle.s + shareEditSetEndPeer->Handle.lnth -
    552             (this.Handle.s + this.Handle.lnth) );              // length of SES, after this
     550            (s.Handle.s + s.Handle.lnth) );              // length of SES, after s
    553551
    554552        // The above string building can trigger compaction.
    555553        // The reference points (that are arguments of the string building) may move during that building.
    556         // From this point on, they are stable.
    557 
    558         assignEditSet(this, shareEditSetStartPeer, shareEditSetEndPeer,
     554        // From s point on, they are stable.
     555
     556        assignEditSet(s, shareEditSetStartPeer, shareEditSetEndPeer,
    559557            pasting.Handle.s,
    560558            pasting.Handle.lnth,
     
    562560    }
    563561
    564     return this;
    565 }
    566 
    567 string_res & assign(string_res &this, const char* buffer, size_t bsize) {
    568     return assign_(this, buffer, bsize, *0p);
    569 }
    570 
    571 string_res & ?=?(string_res &s, char other) {
    572     return assign(s, &other, 1);
     562    return s;
     563}
     564
     565string_res & assign(string_res & s, const char* buffer, size_t bsize) {
     566    return assign_(s, buffer, bsize, *0p);
     567}
     568
     569string_res & ?=?(string_res & s, char c) {
     570    return assign(s, &c, 1);
    573571}
    574572
    575573// Copy assignment operator
    576 string_res & ?=?(string_res & this, const string_res & rhs) with( this ) {
    577     return assign_(this, rhs.Handle.s, rhs.Handle.lnth, rhs);
    578 }
    579 
    580 string_res & ?=?(string_res & this, string_res & rhs) with( this ) {
     574string_res & ?=?(string_res & s, const string_res & rhs) with( s ) {
     575    return assign_(s, rhs.Handle.s, rhs.Handle.lnth, rhs);
     576}
     577
     578string_res & ?=?(string_res & s, string_res & rhs) with( s ) {
    581579    const string_res & rhs2 = rhs;
    582     return this = rhs2;
     580    return s = rhs2;
    583581}
    584582
    585583
    586584// Destructor
    587 void ^?{}(string_res &s) with(s) {
     585void ^?{}(string_res & s) with(s) {
    588586    // much delegated to implied ^VbyteSM
    589587
     
    603601// With unicode support, this may be different from just the byte at the given
    604602// offset from the start of the string.
    605 char ?[?](const string_res &s, size_t index) with(s) {
     603char ?[?](const string_res & s, size_t index) with(s) {
    606604    //TODO: Check if index is valid (no exceptions yet)
    607605    return Handle.s[index];
    608606}
    609607
    610 void assignAt(const string_res &s, size_t index, char val) {
     608void assignAt(const string_res & s, size_t index, char val) {
    611609    string_res editZone = { s, SHARE_EDITS, index, index+1 };
    612610    assign(editZone, &val, 1);
     
    617615// Concatenation
    618616
    619 void append(string_res &str1, const char * buffer, size_t bsize) {
     617void append(string_res & str1, const char * buffer, size_t bsize) {
    620618    size_t clnth = str1.Handle.lnth + bsize;
    621619    if ( str1.Handle.s + str1.Handle.lnth == buffer ) { // already juxtapose ?
     
    635633}
    636634
    637 void ?+=?(string_res &str1, const string_res &str2) {
     635void ?+=?(string_res & str1, const string_res & str2) {
    638636    append( str1, str2.Handle.s, str2.Handle.lnth );
    639637}
    640638
    641 void ?+=?(string_res &s, char other) {
    642     append( s, &other, 1 );
    643 }
    644 
    645 
    646 
     639void ?+=?(string_res & s, char c) {
     640    append( s, & c, 1 );
     641}
    647642
    648643
     
    650645// Comparisons
    651646
    652 int cmp(const string_res &s1, const string_res &s2) {
     647int strcmp(const string_res & s1, const string_res & s2) {
    653648    // return 0;
    654649    int ans1 = memcmp(s1.Handle.s, s2.Handle.s, min(s1.Handle.lnth, s2.Handle.lnth));
     
    657652}
    658653
    659 bool ?==?(const string_res &s1, const string_res &s2) { return cmp(s1, s2) == 0; }
    660 bool ?!=?(const string_res &s1, const string_res &s2) { return cmp(s1, s2) != 0; }
    661 bool ?>? (const string_res &s1, const string_res &s2) { return cmp(s1, s2) >  0; }
    662 bool ?>=?(const string_res &s1, const string_res &s2) { return cmp(s1, s2) >= 0; }
    663 bool ?<=?(const string_res &s1, const string_res &s2) { return cmp(s1, s2) <= 0; }
    664 bool ?<? (const string_res &s1, const string_res &s2) { return cmp(s1, s2) <  0; }
    665 
    666 int cmp (const string_res &s1, const char* s2) {
     654bool ?==?(const string_res & s1, const string_res & s2) { return strcmp(s1, s2) == 0; }
     655bool ?!=?(const string_res & s1, const string_res & s2) { return strcmp(s1, s2) != 0; }
     656bool ?>? (const string_res & s1, const string_res & s2) { return strcmp(s1, s2) >  0; }
     657bool ?>=?(const string_res & s1, const string_res & s2) { return strcmp(s1, s2) >= 0; }
     658bool ?<=?(const string_res & s1, const string_res & s2) { return strcmp(s1, s2) <= 0; }
     659bool ?<? (const string_res & s1, const string_res & s2) { return strcmp(s1, s2) <  0; }
     660
     661int strcmp (const string_res & s1, const char* s2) {
    667662    string_res s2x = s2;
    668     return cmp(s1, s2x);
    669 }
    670 
    671 bool ?==?(const string_res &s1, const char* s2) { return cmp(s1, s2) == 0; }
    672 bool ?!=?(const string_res &s1, const char* s2) { return cmp(s1, s2) != 0; }
    673 bool ?>? (const string_res &s1, const char* s2) { return cmp(s1, s2) >  0; }
    674 bool ?>=?(const string_res &s1, const char* s2) { return cmp(s1, s2) >= 0; }
    675 bool ?<=?(const string_res &s1, const char* s2) { return cmp(s1, s2) <= 0; }
    676 bool ?<? (const string_res &s1, const char* s2) { return cmp(s1, s2) <  0; }
    677 
    678 int cmp (const char* s1, const string_res & s2) {
     663    return strcmp(s1, s2x);
     664}
     665
     666bool ?==?(const string_res & s1, const char* s2) { return strcmp(s1, s2) == 0; }
     667bool ?!=?(const string_res & s1, const char* s2) { return strcmp(s1, s2) != 0; }
     668bool ?>? (const string_res & s1, const char* s2) { return strcmp(s1, s2) >  0; }
     669bool ?>=?(const string_res & s1, const char* s2) { return strcmp(s1, s2) >= 0; }
     670bool ?<=?(const string_res & s1, const char* s2) { return strcmp(s1, s2) <= 0; }
     671bool ?<? (const string_res & s1, const char* s2) { return strcmp(s1, s2) <  0; }
     672
     673int strcmp (const char* s1, const string_res & s2) {
    679674    string_res s1x = s1;
    680     return cmp(s1x, s2);
    681 }
    682 
    683 bool ?==?(const char* s1, const string_res &s2) { return cmp(s1, s2) == 0; }
    684 bool ?!=?(const char* s1, const string_res &s2) { return cmp(s1, s2) != 0; }
    685 bool ?>? (const char* s1, const string_res &s2) { return cmp(s1, s2) >  0; }
    686 bool ?>=?(const char* s1, const string_res &s2) { return cmp(s1, s2) >= 0; }
    687 bool ?<=?(const char* s1, const string_res &s2) { return cmp(s1, s2) <= 0; }
    688 bool ?<? (const char* s1, const string_res &s2) { return cmp(s1, s2) <  0; }
     675    return strcmp(s1x, s2);
     676}
     677
     678bool ?==?(const char* s1, const string_res & s2) { return strcmp(s1, s2) == 0; }
     679bool ?!=?(const char* s1, const string_res & s2) { return strcmp(s1, s2) != 0; }
     680bool ?>? (const char* s1, const string_res & s2) { return strcmp(s1, s2) >  0; }
     681bool ?>=?(const char* s1, const string_res & s2) { return strcmp(s1, s2) >= 0; }
     682bool ?<=?(const char* s1, const string_res & s2) { return strcmp(s1, s2) <= 0; }
     683bool ?<? (const char* s1, const string_res & s2) { return strcmp(s1, s2) <  0; }
    689684
    690685
     
    693688// Search
    694689
    695 bool contains(const string_res &s, char ch) {
     690bool contains(const string_res & s, char ch) {
    696691    for ( i; size(s) ) {
    697692        if (s[i] == ch) return true;
     
    700695}
    701696
    702 int find(const string_res &s, char search) {
     697int find(const string_res & s, char search) {
    703698    return findFrom(s, 0, search);
    704699}
    705700
    706 int findFrom(const string_res &s, size_t fromPos, char search) {
     701int findFrom(const string_res & s, size_t fromPos, char search) {
    707702    // FIXME: This paricular overload (find of single char) is optimized to use memchr.
    708703    // The general overload (find of string, memchr applying to its first character) and `contains` should be adjusted to match.
     
    715710}
    716711
    717 int find(const string_res &s, const string_res &search) {
     712int find(const string_res & s, const string_res & search) {
    718713    return findFrom(s, 0, search);
    719714}
    720715
    721 int findFrom(const string_res &s, size_t fromPos, const string_res &search) {
     716int findFrom(const string_res & s, size_t fromPos, const string_res & search) {
    722717    return findFrom(s, fromPos, search.Handle.s, search.Handle.lnth);
    723718}
    724719
    725 int find(const string_res &s, const char* search) {
     720int find(const string_res & s, const char* search) {
    726721    return findFrom(s, 0, search);
    727722}
    728 int findFrom(const string_res &s, size_t fromPos, const char* search) {
     723int findFrom(const string_res & s, size_t fromPos, const char* search) {
    729724    return findFrom(s, fromPos, search, strlen(search));
    730725}
    731726
    732 int find(const string_res &s, const char* search, size_t searchsize) {
     727int find(const string_res & s, const char* search, size_t searchsize) {
    733728    return findFrom(s, 0, search, searchsize);
    734729}
    735730
    736 int findFrom(const string_res &s, size_t fromPos, const char* search, size_t searchsize) {
     731int findFrom(const string_res & s, size_t fromPos, const char* search, size_t searchsize) {
    737732
    738733    /* Remaining implementations essentially ported from Sunjay's work */
     
    771766}
    772767
    773 bool includes(const string_res &s, const string_res &search) {
     768bool includes(const string_res & s, const string_res & search) {
    774769    return includes(s, search.Handle.s, search.Handle.lnth);
    775770}
    776771
    777 bool includes(const string_res &s, const char* search) {
     772bool includes(const string_res & s, const char* search) {
    778773    return includes(s, search, strlen(search));
    779774}
    780775
    781 bool includes(const string_res &s, const char* search, size_t searchsize) {
     776bool includes(const string_res & s, const char* search, size_t searchsize) {
    782777    return find(s, search, searchsize) < s.Handle.lnth;
    783778}
    784779
    785 bool startsWith(const string_res &s, const string_res &prefix) {
     780bool startsWith(const string_res & s, const string_res & prefix) {
    786781    return startsWith(s, prefix.Handle.s, prefix.Handle.lnth);
    787782}
    788783
    789 bool startsWith(const string_res &s, const char* prefix) {
     784bool startsWith(const string_res & s, const char* prefix) {
    790785    return startsWith(s, prefix, strlen(prefix));
    791786}
    792787
    793 bool startsWith(const string_res &s, const char* prefix, size_t prefixsize) {
     788bool startsWith(const string_res & s, const char* prefix, size_t prefixsize) {
    794789    if (s.Handle.lnth < prefixsize) {
    795790        return false;
     
    798793}
    799794
    800 bool endsWith(const string_res &s, const string_res &suffix) {
     795bool endsWith(const string_res & s, const string_res & suffix) {
    801796    return endsWith(s, suffix.Handle.s, suffix.Handle.lnth);
    802797}
    803798
    804 bool endsWith(const string_res &s, const char* suffix) {
     799bool endsWith(const string_res & s, const char* suffix) {
    805800    return endsWith(s, suffix, strlen(suffix));
    806801}
    807802
    808 bool endsWith(const string_res &s, const char* suffix, size_t suffixsize) {
     803bool endsWith(const string_res & s, const char* suffix, size_t suffixsize) {
    809804    if (s.Handle.lnth < suffixsize) {
    810805        return false;
     
    822817// charclass, include, exclude
    823818
    824 void ?{}( charclass_res & this, const string_res & chars) {
    825     (this){ chars.Handle.s, chars.Handle.lnth };
    826 }
    827 
    828 void ?{}( charclass_res & this, const char * chars ) {
    829     (this){ chars, strlen(chars) };
    830 }
    831 
    832 void ?{}( charclass_res & this, const char * chars, size_t charssize ) {
    833     (this.chars){ chars, charssize };
     819void ?{}( charclass_res & s, const string_res & chars) {
     820    (s){ chars.Handle.s, chars.Handle.lnth };
     821}
     822
     823void ?{}( charclass_res & s, const char * chars ) {
     824    (s){ chars, strlen(chars) };
     825}
     826
     827void ?{}( charclass_res & s, const char * chars, size_t charssize ) {
     828    (s.chars){ chars, charssize };
    834829    // now sort it ?
    835830}
    836831
    837 void ^?{}( charclass_res & this ) {
    838     ^(this.chars){};
     832void ^?{}( charclass_res & s ) {
     833    ^(s.chars){};
    839834}
    840835
     
    844839}
    845840
    846 int exclude(const string_res &s, const charclass_res &mask) {
     841int exclude(const string_res & s, const charclass_res & mask) {
    847842    for ( i; size(s) ) {
    848843        if ( test(mask, s[i]) ) return i;
     
    851846}
    852847
    853 int include(const string_res &s, const charclass_res &mask) {
     848int include(const string_res & s, const charclass_res & mask) {
    854849    for ( i; size(s) ) {
    855850        if ( ! test(mask, s[i]) ) return i;
     
    863858// Add a new HandleNode node n after the current HandleNode node.
    864859
    865 static void AddThisAfter( HandleNode & this, HandleNode & n ) with(this) {
    866 #ifdef VbyteDebug
    867     serr | "enter:AddThisAfter, this:" | &this | " n:" | &n;
     860static void AddThisAfter( HandleNode & s, HandleNode & n ) with(s) {
     861#ifdef VbyteDebug
     862    serr | "enter:AddThisAfter, s:" | &s | " n:" | &n;
    868863#endif // VbyteDebug
    869864    // Performance note: we are on the critical path here. MB has ensured that the verifies don't contribute to runtime (are compiled away, like they're supposed to be).
    870865    verify( n.ulink != 0p );
    871     verify( this.ulink == n.ulink );
     866    verify( s.ulink == n.ulink );
    872867    flink = n.flink;
    873868    blink = &n;
    874     n.flink->blink = &this;
    875     n.flink = &this;
     869    n.flink->blink = &s;
     870    n.flink = &s;
    876871#ifdef VbyteDebug
    877872    {
     
    894889// Delete the current HandleNode node.
    895890
    896 static void DeleteNode( HandleNode & this ) with(this) {
    897 #ifdef VbyteDebug
    898     serr | "enter:DeleteNode, this:" | &this;
     891static void DeleteNode( HandleNode & s ) with(s) {
     892#ifdef VbyteDebug
     893    serr | "enter:DeleteNode, s:" | &s;
    899894#endif // VbyteDebug
    900895    flink->blink = blink;
     
    906901
    907902
    908 
    909903// Allocates specified storage for a string from byte-string area. If not enough space remains to perform the
    910904// allocation, the garbage collection routine is called.
    911905
    912 static char * VbyteAlloc( VbyteHeap & this, int size ) with(this) {
     906static char * VbyteAlloc( VbyteHeap & s, int size ) with(s) {
    913907#ifdef VbyteDebug
    914908    serr | "enter:VbyteAlloc, size:" | size;
     
    918912
    919913    NoBytes = ( uintptr_t )EndVbyte + size;
    920     if ( NoBytes > ( uintptr_t )ExtVbyte ) {            // enough room for new byte-string ?
    921                 garbage( this, size );                                  // firer up the garbage collector
     914    if ( NoBytes > ( uintptr_t )ExtVbyte ) {                    // enough room for new byte-string ?
     915                garbage( s, size );                                                             // firer up the garbage collector
    922916                verify( (( uintptr_t )EndVbyte + size) <= ( uintptr_t )ExtVbyte  && "garbage run did not free up required space" );
    923917    } // if
     
    939933// VbyteAlloc to claim the new space, while doing optimal copying from old to new, then free old.
    940934
    941 static char * VbyteTryAdjustLast( VbyteHeap & this, int delta ) with(this) {
    942 
     935static char * VbyteTryAdjustLast( VbyteHeap & s, int delta ) with(s) {
    943936    if ( ( uintptr_t )EndVbyte + delta <= ( uintptr_t )ExtVbyte ) {
    944937        // room available
     
    961954// the address in the byte string area.
    962955
    963 static void MoveThisAfter( HandleNode & this, const HandleNode  & h ) with(this) {
    964 #ifdef VbyteDebug
    965     serr | "enter:MoveThisAfter, this:" | & this | " h:" | & h;
     956static void MoveThisAfter( HandleNode & s, const HandleNode  & h ) with(s) {
     957#ifdef VbyteDebug
     958    serr | "enter:MoveThisAfter, s:" | & s | " h:" | & h;
    966959#endif // VbyteDebug
    967960    verify( h.ulink != 0p );
    968     verify( this.ulink == h.ulink );
     961    verify( s.ulink == h.ulink );
    969962    if ( s < h.s ) {                                    // check argument values
    970963                // serr | "VbyteSM: Error - Cannot move byte string starting at:" | s | " after byte string starting at:"
     
    976969    HandleNode *i;
    977970    for ( i = h.flink; i->s != 0 && s > ( i->s ); i = i->flink ); // find the position for this node after h
    978     if ( & this != i->blink ) {
    979                 DeleteNode( this );
    980                 AddThisAfter( this, *i->blink );
     971    if ( & s != i->blink ) {
     972                DeleteNode( s );
     973                AddThisAfter( s, *i->blink );
    981974    } // if
    982975#ifdef VbyteDebug
     
    10581051// the containing string has been moved. Hence, they only require that their string pointers be adjusted.
    10591052
    1060 void compaction(VbyteHeap & this) with(this) {
     1053void compaction(VbyteHeap & s) with(s) {
    10611054    HandleNode *h;
    10621055    char *obase, *nbase, *limit;
     
    10981091// the heap.  The heap is then compacted in the existing heap or into the newly allocated heap.
    10991092
    1100 void garbage(VbyteHeap & this, int minreq ) with(this) {
     1093void garbage(VbyteHeap & s, int minreq ) with(s) {
    11011094#ifdef VbyteDebug
    11021095    serr | "enter:garbage";
     
    11241117    if ( ( double ) AmountFree < ( CurrSize * heap_expansion_freespace_threshold ) || AmountFree < minreq ) {   // free space less than threshold or not enough to serve cur request
    11251118
    1126                 extend( this, max( CurrSize, minreq ) );                                // extend the heap
     1119                extend( s, max( CurrSize, minreq ) );                           // extend the heap
    11271120
    11281121                        //  Peter says, "This needs work before it should be used."
     
    11331126
    11341127    } else {
    1135         compaction(this);                                       // in-place
     1128        compaction(s);                                  // in-place
    11361129    }// if
    11371130#ifdef VbyteDebug
     
    11591152// area is deleted.
    11601153
    1161 void extend( VbyteHeap & this, int size ) with (this) {
     1154void extend( VbyteHeap & s, int size ) with (s) {
    11621155#ifdef VbyteDebug
    11631156    serr | "enter:extend, size:" | size;
     
    11711164    StartVbyte = EndVbyte = TEMP_ALLOC(char, CurrSize);
    11721165    ExtVbyte = (void *)( StartVbyte + CurrSize );
    1173     compaction(this);                                   // copy from old heap to new & adjust pointers to new heap
     1166    compaction(s);                                      // copy from old heap to new & adjust pointers to new heap
    11741167    free( OldStartVbyte );                              // release old heap
    11751168#ifdef VbyteDebug
  • libcfa/src/collections/string_res.hfa

    r8b4faf6 r681e12f  
    1010// Created On       : Fri Sep 03 11:00:00 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Aug 12 15:45:47 2023
    13 // Update Count     : 2
     12// Last Modified On : Thu Jan  4 11:28:06 2024
     13// Update Count     : 27
    1414//
    1515
     
    7070
    7171// Getters
    72 size_t size(const string_res &s);
     72size_t size(const string_res & s);
    7373
    7474// Constructors, Assignment Operators, Destructor
    75 void ?{}(string_res &s); // empty string
    76 void ?{}(string_res &s, const char* buffer, size_t bsize); // copy specific length from buffer
    77 static inline void ?{}(string_res &s, const char* rhs) { // copy from string literal (NULL-terminated)
     75void ?{}(string_res & s); // empty string
     76void ?{}(string_res & s, const char * buffer, size_t bsize); // copy specific length from buffer
     77static inline void ?{}(string_res & s, const char * rhs) { // copy from string literal (NULL-terminated)
    7878    (s){ rhs, strlen(rhs) };
    7979}
    8080
    81 void ?{}(string_res &s, const string_res & s2) = void;
    82 void ?{}(string_res &s, string_res & s2) = void;
     81void ?{}(string_res & s, const string_res & s2) = void;
     82void ?{}(string_res & s, string_res & s2) = void;
    8383
    8484enum StrResInitMode { COPY_VALUE, SHARE_EDITS };
    85 void ?{}(string_res &s, const string_res & src, StrResInitMode, size_t start, size_t end );
    86 static inline void ?{}(string_res &s, const string_res & src, StrResInitMode mode ) {
     85void ?{}(string_res & s, const string_res & src, StrResInitMode, size_t start, size_t end );
     86static inline void ?{}(string_res & s, const string_res & src, StrResInitMode mode ) {
    8787    ?{}( s, src, mode, 0, size(src));
    8888}
    8989
    90 string_res & assign(string_res &s, const char* buffer, size_t bsize); // copy specific length from buffer
    91 static inline string_res & ?=?(string_res &s, const char* other) {  // copy from string literal (NULL-terminated)
    92     return assign(s, other, strlen(other));
    93 }
    94 string_res & ?=?(string_res &s, const string_res &other);
    95 string_res & ?=?(string_res &s, string_res &other);
    96 string_res & ?=?(string_res &s, char other);
    97 
    98 void ^?{}(string_res &s);
     90string_res & assign(string_res & s, const char * buffer, size_t bsize); // copy specific length from buffer
     91static inline string_res & ?=?(string_res & s, const char * c) {  // copy from string literal (NULL-terminated)
     92    return assign(s, c, strlen(c));
     93}
     94string_res & ?=?(string_res & s, const string_res & c);
     95string_res & ?=?(string_res & s, string_res & c);
     96string_res & ?=?(string_res & s, char c);
     97
     98void ^?{}(string_res & s);
    9999
    100100// IO Operator
    101 ofstream & ?|?(ofstream &out, const string_res &s);
    102 void ?|?(ofstream &out, const string_res &s);
    103 ifstream & ?|?(ifstream &in, string_res &s);
    104 void ?|?( ifstream & in, string_res & this );
     101ofstream & ?|?(ofstream & out, const string_res & s);
     102void ?|?(ofstream & out, const string_res & s);
     103ifstream & ?|?(ifstream & in, string_res & s);
     104void ?|?( ifstream & in, string_res & s );
    105105
    106106struct _Istream_Rstr {
     
    113113        _Istream_Rstr wdi( unsigned int rwd, string_res & s ) { return (_Istream_Rstr)@{ &s, {{0p}, rwd, {.flags.rwd : true}} }; }
    114114        _Istream_Rstr getline( string_res & s, const char delimiter = '\n' ) {
    115                 return (_Istream_Rstr)@{ &s, {{.delimiter : { delimiter, '\0' } }, -1, {.flags.delimiter : true, .flags.inex : true}} };
     115                return (_Istream_Rstr)@{ &s, {{.delimiters : { delimiter, '\0' } }, -1, {.flags.delimiter : true, .flags.inex : true}} };
    116116        }
    117117        _Istream_Rstr & getline( _Istream_Rstr & fmt, const char delimiter = '\n' ) {
    118                 fmt.delimiter[0] = delimiter; fmt.delimiter[1] = '\0'; fmt.flags.delimiter = true; fmt.flags.inex = true; return fmt;
     118                fmt.delimiters[0] = delimiter; fmt.delimiters[1] = '\0'; fmt.flags.delimiter = true; fmt.flags.inex = true; return fmt;
    119119        }
    120120        _Istream_Rstr incl( const char scanset[], string_res & s ) { return (_Istream_Rstr)@{ &s, {{scanset}, -1, {.flags.inex : false}} }; }
     
    129129
    130130// Concatenation
    131 void append(string_res &s, const char* buffer, size_t bsize);
    132 void ?+=?(string_res &s, char other); // append a character
    133 void ?+=?(string_res &s, const string_res &s2); // append-concatenate to first string
    134 static inline void ?+=?(string_res &s, const char* other) {
    135     append( s, other, strlen(other) );
     131void append(string_res & s, const char * buffer, size_t bsize);
     132void ?+=?(string_res & s, char c); // append a character
     133void ?+=?(string_res & s, const string_res & s2); // append-concatenate to first string
     134static inline void ?+=?(string_res & s, const char * c) {
     135    append( s, c, strlen(c) );
    136136}
    137137
    138138// Character access
    139 void assignAt(const string_res &s, size_t index, char val);
    140 char ?[?](const string_res &s, size_t index); // Mike changed to ret by val from Sunjay's ref, to match Peter's
    141 //char codePointAt(const string_res &s, size_t index); // revisit under Unicode
     139void assignAt(const string_res & s, size_t index, char val);
     140char ?[?](const string_res & s, size_t index); // Mike changed to ret by val from Sunjay's ref, to match Peter's
     141//char codePointAt(const string_res & s, size_t index); // revisit under Unicode
    142142
    143143// Comparisons
    144 int  cmp (const string_res &, const string_res &);
     144int  strcmp (const string_res &, const string_res &);
    145145bool ?==?(const string_res &, const string_res &);
    146146bool ?!=?(const string_res &, const string_res &);
     
    150150bool ?<? (const string_res &, const string_res &);
    151151
    152 int  cmp (const string_res &, const char*);
    153 bool ?==?(const string_res &, const char*);
    154 bool ?!=?(const string_res &, const char*);
    155 bool ?>? (const string_res &, const char*);
    156 bool ?>=?(const string_res &, const char*);
    157 bool ?<=?(const string_res &, const char*);
    158 bool ?<? (const string_res &, const char*);
    159 
    160 int  cmp (const char*, const string_res &);
    161 bool ?==?(const char*, const string_res &);
    162 bool ?!=?(const char*, const string_res &);
    163 bool ?>? (const char*, const string_res &);
    164 bool ?>=?(const char*, const string_res &);
    165 bool ?<=?(const char*, const string_res &);
    166 bool ?<? (const char*, const string_res &);
     152int  strcmp(const string_res &, const char *);
     153bool ?==?(const string_res &, const char *);
     154bool ?!=?(const string_res &, const char *);
     155bool ?>? (const string_res &, const char *);
     156bool ?>=?(const string_res &, const char *);
     157bool ?<=?(const string_res &, const char *);
     158bool ?<? (const string_res &, const char *);
     159
     160int  strcmp(const char *, const string_res &);
     161bool ?==?(const char *, const string_res &);
     162bool ?!=?(const char *, const string_res &);
     163bool ?>? (const char *, const string_res &);
     164bool ?>=?(const char *, const string_res &);
     165bool ?<=?(const char *, const string_res &);
     166bool ?<? (const char *, const string_res &);
    167167
    168168// String search
    169 bool contains(const string_res &s, char ch); // single character
    170 
    171 int find(const string_res &s, char search);
    172 int find(const string_res &s, const string_res &search);
    173 int find(const string_res &s, const char* search);
    174 int find(const string_res &s, const char* search, size_t searchsize);
    175 
    176 int findFrom(const string_res &s, size_t fromPos, char search);
    177 int findFrom(const string_res &s, size_t fromPos, const string_res &search);
    178 int findFrom(const string_res &s, size_t fromPos, const char* search);
    179 int findFrom(const string_res &s, size_t fromPos, const char* search, size_t searchsize);
    180 
    181 bool includes(const string_res &s, const string_res &search);
    182 bool includes(const string_res &s, const char* search);
    183 bool includes(const string_res &s, const char* search, size_t searchsize);
    184 
    185 bool startsWith(const string_res &s, const string_res &prefix);
    186 bool startsWith(const string_res &s, const char* prefix);
    187 bool startsWith(const string_res &s, const char* prefix, size_t prefixsize);
    188 
    189 bool endsWith(const string_res &s, const string_res &suffix);
    190 bool endsWith(const string_res &s, const char* suffix);
    191 bool endsWith(const string_res &s, const char* suffix, size_t suffixsize);
    192 
    193 int include(const string_res &s, const charclass_res &mask);
    194 int exclude(const string_res &s, const charclass_res &mask);
     169bool contains(const string_res & s, char ch); // single character
     170
     171int find(const string_res & s, char search);
     172int find(const string_res & s, const string_res & search);
     173int find(const string_res & s, const char * search);
     174int find(const string_res & s, const char * search, size_t searchsize);
     175
     176int findFrom(const string_res & s, size_t fromPos, char search);
     177int findFrom(const string_res & s, size_t fromPos, const string_res & search);
     178int findFrom(const string_res & s, size_t fromPos, const char * search);
     179int findFrom(const string_res & s, size_t fromPos, const char * search, size_t searchsize);
     180
     181bool includes(const string_res & s, const string_res & search);
     182bool includes(const string_res & s, const char * search);
     183bool includes(const string_res & s, const char * search, size_t searchsize);
     184
     185bool startsWith(const string_res & s, const string_res & prefix);
     186bool startsWith(const string_res & s, const char * prefix);
     187bool startsWith(const string_res & s, const char * prefix, size_t prefixsize);
     188
     189bool endsWith(const string_res & s, const string_res & suffix);
     190bool endsWith(const string_res & s, const char * suffix);
     191bool endsWith(const string_res & s, const char * suffix, size_t suffixsize);
     192
     193int include(const string_res & s, const charclass_res & mask);
     194int exclude(const string_res & s, const charclass_res & mask);
    195195
    196196// Modifiers
    197 void padStart(string_res &s, size_t n);
    198 void padStart(string_res &s, size_t n, char padding);
    199 void padEnd(string_res &s, size_t n);
     197void padStart(string_res & s, size_t n);
     198void padStart(string_res & s, size_t n, char padding);
     199void padEnd(string_res & s, size_t n);
    200200void padEnd(string_res &s, size_t n, char padding);
    201201
Note: See TracChangeset for help on using the changeset viewer.