Ignore:
Timestamp:
Jan 19, 2024, 2:44:41 AM (8 months ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
ac939461
Parents:
59c8dff (diff), e8b3717 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/collections/string_res.hfa

    r59c8dff rf988834  
    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}
    80 
    81 void ?{}(string_res &s, const string_res & s2) = void;
    82 void ?{}(string_res &s, string_res & s2) = void;
     80static inline void ?{}(string_res & s, char c ) {
     81    ?{}( s, &c, 1);
     82}
     83
     84// Deleting the copy constructors makes the compiler reject an attempt to call/return by value
     85void ?{}(string_res & s, const string_res & s2) = void;
     86void ?{}(string_res & s, string_res & s2) = void;
    8387
    8488enum 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 ) {
     89void ?{}(string_res & s, const string_res & src, StrResInitMode, size_t start, size_t len );
     90static inline void ?{}(string_res & s, const string_res & src, StrResInitMode mode ) {
    8791    ?{}( s, src, mode, 0, size(src));
    8892}
    89 
    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);
     93static inline void ?{}(string_res & s, const string_res & src, StrResInitMode mode, size_t maxlen ) {
     94    ?{}( s, src, mode, 0, (size(src) > maxlen)?maxlen:size(src) );
     95}
     96
     97string_res & assign(string_res & s, const string_res & src, size_t maxlen); // copy specific length from other string
     98string_res & assign(string_res & s, const char * buffer, size_t bsize); // copy specific length from buffer
     99static inline string_res & ?=?(string_res & s, const char * c) {  // copy from string literal (NULL-terminated)
     100    return assign(s, c, strlen(c));
     101}
     102string_res & ?=?(string_res & s, const string_res & c);
     103string_res & ?=?(string_res & s, string_res & c);
     104string_res & ?=?(string_res & s, char c);
     105
     106void ^?{}(string_res & s);
    99107
    100108// 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 );
     109ofstream & ?|?(ofstream & out, const string_res & s);
     110void ?|?(ofstream & out, const string_res & s);
     111ifstream & ?|?(ifstream & in, string_res & s);
     112void ?|?( ifstream & in, string_res & s );
    105113
    106114struct _Istream_Rstr {
     
    113121        _Istream_Rstr wdi( unsigned int rwd, string_res & s ) { return (_Istream_Rstr)@{ &s, {{0p}, rwd, {.flags.rwd : true}} }; }
    114122        _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}} };
     123                return (_Istream_Rstr)@{ &s, {{.delimiters : { delimiter, '\0' } }, -1, {.flags.delimiter : true, .flags.inex : true}} };
    116124        }
    117125        _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;
     126                fmt.delimiters[0] = delimiter; fmt.delimiters[1] = '\0'; fmt.flags.delimiter = true; fmt.flags.inex = true; return fmt;
    119127        }
    120128        _Istream_Rstr incl( const char scanset[], string_res & s ) { return (_Istream_Rstr)@{ &s, {{scanset}, -1, {.flags.inex : false}} }; }
     
    129137
    130138// 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) );
    136 }
     139void ?+=?(string_res & s, const string_res & s2);
     140void ?+=?(string_res & s, char c);
     141void append(string_res & s, const string_res & s2, size_t maxlen);
     142void ?+=?(string_res & s, const char * c);
     143void append(string_res & s, const char * buffer, size_t bsize);
     144
     145static inline string_res & strcat(string_res & s, const string_res & s2) { s += s2; return s; }
     146static inline string_res & strcat(string_res & s, const char * c) { s += c; return s; }
     147static inline string_res & strncat(string_res & s, const string_res & s2, size_t maxlen) { append(s, s2, maxlen); return s; }
     148static inline string_res & strncat(string_res & s, const char * buffer, size_t bsize) { append(s, buffer, bsize); return s; }
     149
     150// Repetition
     151void ?*=?(string_res & s, size_t factor);
    137152
    138153// 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
     154void assignAt(const string_res & s, size_t index, char val);
     155char ?[?](const string_res & s, size_t index); // Mike changed to ret by val from Sunjay's ref, to match Peter's
     156//char codePointAt(const string_res & s, size_t index); // revisit under Unicode
    142157
    143158// Comparisons
    144 int  cmp (const string_res &, const string_res &);
     159int  strcmp (const string_res &, const string_res &);
    145160bool ?==?(const string_res &, const string_res &);
    146161bool ?!=?(const string_res &, const string_res &);
     
    150165bool ?<? (const string_res &, const string_res &);
    151166
    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 &);
     167int  strcmp(const string_res &, const char *);
     168bool ?==?(const string_res &, const char *);
     169bool ?!=?(const string_res &, const char *);
     170bool ?>? (const string_res &, const char *);
     171bool ?>=?(const string_res &, const char *);
     172bool ?<=?(const string_res &, const char *);
     173bool ?<? (const string_res &, const char *);
     174
     175int  strcmp(const char *, const string_res &);
     176bool ?==?(const char *, const string_res &);
     177bool ?!=?(const char *, const string_res &);
     178bool ?>? (const char *, const string_res &);
     179bool ?>=?(const char *, const string_res &);
     180bool ?<=?(const char *, const string_res &);
     181bool ?<? (const char *, const string_res &);
    167182
    168183// 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);
     184bool contains(const string_res & s, char ch); // single character
     185
     186int find(const string_res & s, char search);
     187int find(const string_res & s, const string_res & search);
     188int find(const string_res & s, const char * search);
     189int find(const string_res & s, const char * search, size_t searchsize);
     190
     191int findFrom(const string_res & s, size_t fromPos, char search);
     192int findFrom(const string_res & s, size_t fromPos, const string_res & search);
     193int findFrom(const string_res & s, size_t fromPos, const char * search);
     194int findFrom(const string_res & s, size_t fromPos, const char * search, size_t searchsize);
     195
     196bool includes(const string_res & s, const string_res & search);
     197bool includes(const string_res & s, const char * search);
     198bool includes(const string_res & s, const char * search, size_t searchsize);
     199
     200bool startsWith(const string_res & s, const string_res & prefix);
     201bool startsWith(const string_res & s, const char * prefix);
     202bool startsWith(const string_res & s, const char * prefix, size_t prefixsize);
     203
     204bool endsWith(const string_res & s, const string_res & suffix);
     205bool endsWith(const string_res & s, const char * suffix);
     206bool endsWith(const string_res & s, const char * suffix, size_t suffixsize);
     207
     208int include(const string_res & s, const charclass_res & mask);
     209int exclude(const string_res & s, const charclass_res & mask);
    195210
    196211// 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);
     212void padStart(string_res & s, size_t n);
     213void padStart(string_res & s, size_t n, char padding);
     214void padEnd(string_res & s, size_t n);
    200215void padEnd(string_res &s, size_t n, char padding);
    201216
Note: See TracChangeset for help on using the changeset viewer.