Changeset 4dab7e8 for libcfa/src/collections/string.hfa
- Timestamp:
- Aug 5, 2024, 11:13:27 PM (3 months ago)
- Branches:
- master
- Children:
- 1c957a11, c4d6c90
- Parents:
- 0e6cf54c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/collections/string.hfa
r0e6cf54c r4dab7e8 10 10 // Created On : Fri Sep 03 11:00:00 2021 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Feb 6 20:59:18202413 // Update Count : 1 1812 // Last Modified On : Mon Aug 5 23:06:14 2024 13 // Update Count : 128 14 14 // 15 15 … … 28 28 29 29 // Getters 30 size_t size( const string & s);31 static inline size_t strlen( const string & s) { return size( s ); }30 size_t size( const string & s ); 31 static inline size_t strlen( const string & s ) { return size( s ); } 32 32 33 33 // RAII, assignment 34 void ?{}( string & s); // empty string35 void ?{}( string & s, const string & s2);36 void ?{}( string & s, const string & s2, size_t maxlen);37 void ?{}( string & s, string & s2);38 39 void ?{}( string & s, char);40 void ?{}( string & s, const char * c);// copy from string literal (NULL-terminated)41 void ?{}( string & s, const char * c, size_t size);// copy specific length from buffer34 void ?{}( string & s ); // empty string 35 void ?{}( string & s, const string & s2 ); 36 void ?{}( string & s, const string & s2, size_t maxlen ); 37 void ?{}( string & s, string & s2 ); 38 39 void ?{}( string & s, char ); 40 void ?{}( string & s, const char * c ); // copy from string literal (NULL-terminated) 41 void ?{}( string & s, const char * c, size_t size ); // copy specific length from buffer 42 42 43 43 void ?{}( string & s, ssize_t rhs ); … … 48 48 void ?{}( string & s, long double _Complex rhs ); 49 49 50 string & ?=?(string & s, const string & c); 51 string & ?=?(string & s, string & c); 52 string & ?=?(string & s, const char * c); // copy from "literal" 53 string & ?=?(string & s, char c); // copy from 'l' 54 string & assign(string & s, const string & c, size_t n); 55 string & assign(string & s, const char * c, size_t n); 56 57 static inline string & strcpy(string & s, const char * c) { s = c; return s; } 58 static inline string & strncpy(string & s, const char * c, size_t n) { assign( s, c, n); return s; } 59 static inline string & strcpy(string & s, const string & c) { s = c; return s; } 60 static inline string & strncpy(string & s, const string & c, size_t n) { assign(s, c, n); return s; } 50 string str( ssize_t rhs ); 51 string str( size_t rhs ); 52 string str( double rhs ); 53 string str( long double rhs ); 54 string str( double _Complex rhs ); 55 string str( long double _Complex rhs ); 56 57 string & ?=?( string & s, const string & c ); 58 string & ?=?( string & s, string & c ); 59 string & ?=?( string & s, const char * c ); // copy from "literal" 60 string & ?=?( string & s, char c ); // copy from 'l' 61 string & assign( string & s, const string & c, size_t n ); 62 string & assign( string & s, const char * c, size_t n ); 63 64 static inline string & strcpy( string & s, const char * c ) { s = c; return s; } 65 static inline string & strncpy( string & s, const char * c, size_t n ) { assign( s, c, n ); return s; } 66 static inline string & strcpy( string & s, const string & c ) { s = c; return s; } 67 static inline string & strncpy( string & s, const string & c, size_t n ) { assign( s, c, n ); return s; } 61 68 62 69 string & ?=?( string & s, ssize_t rhs ); … … 67 74 string & ?=?( string & s, long double _Complex rhs ); 68 75 69 void ^?{}( string & s);76 void ^?{}( string & s ); 70 77 71 78 // Alternate construction: request shared edits … … 77 84 78 85 // IO Operator 79 ofstream & ?|?( ofstream & out, const string & s);80 void ?|?( ofstream & out, const string & s);81 ifstream & ?|?( ifstream & in, string & s);86 ofstream & ?|?( ofstream & out, const string & s ); 87 void ?|?( ofstream & out, const string & s ); 88 ifstream & ?|?( ifstream & in, string & s ); 82 89 83 90 static inline { … … 145 152 146 153 // Concatenation 147 void ?+=?(string & s, char c); // append a character 148 void ?+=?(string & s, const string & s2); // append-concatenate to first string 149 void append(string & s, const string & s2, size_t maxlen); // append-concatenate to first string, up to maxlen 150 void ?+=?(string & s, const char * s2); // append-concatenate NULL-terminated string to first string 151 void append(string & s, const char * buffer, size_t bsize); // append-concatenate given range to first string 152 153 string ?+?(const string & s, char c); // add a character to a copy of the string 154 string ?+?(const string & s, const string & s2); // copy and concatenate both strings 155 string ?+?(const char * s1, const char * s2); // copy and concatenate both strings 156 string ?+?(const string & s, const char * c); // copy and concatenate with NULL-terminated string 157 158 static inline string & strcat(string & s, const string & s2) { s += s2; return s; } 159 static inline string & strcat(string & s, const char * c) { s += c; return s; } 160 static inline string & strncat(string & s, const string & s2, size_t maxlen) { append(s, s2, maxlen); return s; } 161 static inline string & strncat(string & s, const char * buffer, size_t bsize) { append(s, buffer, bsize); return s; } 154 void ?+=?( string & s, char c ); // append a character 155 void ?+=?( string & s, const string & s2 ); // append-concatenate to first string 156 void append( string & s, const string & s2, size_t maxlen ); // append-concatenate to first string, up to maxlen 157 void ?+=?( string & s, const char * s2 ); // append-concatenate NULL-terminated string to first string 158 void append( string & s, const char * buffer, size_t bsize ); // append-concatenate given range to first string 159 160 string ?+?( const string & s, char c ); // add a character to a copy of the string 161 string ?+?( char c, const string & s ); // add a character to a copy of the string 162 string ?+?( const string & s, const string & s2 ); // copy and concatenate both strings 163 string ?+?( const char * s, char c ); // copy and concatenate both strings 164 string ?+?( char c, const char * s ); // copy and concatenate both strings 165 string ?+?( const char * s1, const char * s2 ); // copy and concatenate both strings 166 string ?+?( const char * s1, string & s2 ); // copy and concatenate both strings 167 string ?+?( const string & s, const char * c ); // copy and concatenate with NULL-terminated string 168 169 static inline string & strcat( string & s, const string & s2 ) { s += s2; return s; } 170 static inline string & strcat( string & s, const char * c ) { s += c; return s; } 171 static inline string & strncat( string & s, const string & s2, size_t maxlen ) { append( s, s2, maxlen ); return s; } 172 static inline string & strncat( string & s, const char * buffer, size_t bsize ) { append( s, buffer, bsize ); return s; } 162 173 163 174 // Repetition 164 string ?*?( const string & s, size_t factor);165 void ?*=?( string & s, size_t factor);166 string ?*?( char c, size_t factor);167 string ?*?( const char *s, size_t factor);175 string ?*?( const string & s, size_t factor ); 176 void ?*=?( string & s, size_t factor ); 177 string ?*?( char c, size_t factor ); 178 string ?*?( const char *s, size_t factor ); 168 179 169 180 // Character access 170 char ?[?]( const string & s, size_t index);171 string ?[?]( string & s, size_t index);// mutable length-1 slice of original172 //char codePointAt(const string & s, size_t index );// to revisit under Unicode181 char ?[?]( const string & s, size_t index ); 182 string ?[?]( string & s, size_t index ); // mutable length-1 slice of original 183 //char codePointAt(const string & s, size_t index ); // to revisit under Unicode 173 184 174 185 // Comparisons 175 int strcmp (const string &, const string &);176 bool ?==?( const string &, const string &);177 bool ?!=?( const string &, const string &);178 bool ?>? ( const string &, const string &);179 bool ?>=?( const string &, const string &);180 bool ?<=?( const string &, const string &);181 bool ?<? ( const string &, const string &);182 183 int strcmp (const string &, const char *);184 bool ?==?( const string &, const char *);185 bool ?!=?( const string &, const char *);186 bool ?>? ( const string &, const char *);187 bool ?>=?( const string &, const char *);188 bool ?<=?( const string &, const char *);189 bool ?<? ( const string &, const char *);190 191 int strcmp (const char *, const string &);192 bool ?==?( const char *, const string &);193 bool ?!=?( const char *, const string &);194 bool ?>? ( const char *, const string &);195 bool ?>=?( const char *, const string &);196 bool ?<=?( const char *, const string &);197 bool ?<? ( const char *, const string &);186 int strcmp ( const string &, const string &); 187 bool ?==?( const string &, const string &); 188 bool ?!=?( const string &, const string &); 189 bool ?>? ( const string &, const string &); 190 bool ?>=?( const string &, const string &); 191 bool ?<=?( const string &, const string &); 192 bool ?<? ( const string &, const string &); 193 194 int strcmp( const string &, const char *); 195 bool ?==?( const string &, const char *); 196 bool ?!=?( const string &, const char *); 197 bool ?>? ( const string &, const char *); 198 bool ?>=?( const string &, const char *); 199 bool ?<=?( const string &, const char *); 200 bool ?<? ( const string &, const char *); 201 202 int strcmp( const char *, const string &); 203 bool ?==?( const char *, const string &); 204 bool ?!=?( const char *, const string &); 205 bool ?>? ( const char *, const string &); 206 bool ?>=?( const char *, const string &); 207 bool ?<=?( const char *, const string &); 208 bool ?<? ( const char *, const string &); 198 209 199 210 200 211 // Slicing 201 string ?()( string & s, size_t start, size_t len ); 202 string ?()( string & s, size_t start );212 string ?()( string & s, size_t start, size_t len ); // TODO const? 213 string ?()( string & s, size_t start ); 203 214 204 215 // String search 205 bool contains( const string & s, char ch);// single character206 207 int find( const string & s, char search);208 int find( const string & s, const string & search);209 int find( const string & s, const char * search);210 int find( const string & s, const char * search, size_t searchsize);211 212 int findFrom( const string & s, size_t fromPos, char search);213 int findFrom( const string & s, size_t fromPos, const string & search);214 int findFrom( const string & s, size_t fromPos, const char * search);215 int findFrom( const string & s, size_t fromPos, const char * search, size_t searchsize);216 217 bool includes( const string & s, const string & search);218 bool includes( const string & s, const char * search);219 bool includes( const string & s, const char * search, size_t searchsize);220 221 bool startsWith( const string & s, const string & prefix);222 bool startsWith( const string & s, const char * prefix);223 bool startsWith( const string & s, const char * prefix, size_t prefixsize);224 225 bool endsWith( const string & s, const string & suffix);226 bool endsWith( const string & s, const char * suffix);227 bool endsWith( const string & s, const char * suffix, size_t suffixsize);216 bool contains( const string & s, char ch ); // single character 217 218 int find( const string & s, char search ); 219 int find( const string & s, const string & search ); 220 int find( const string & s, const char * search ); 221 int find( const string & s, const char * search, size_t searchsize ); 222 223 int findFrom( const string & s, size_t fromPos, char search ); 224 int findFrom( const string & s, size_t fromPos, const string & search ); 225 int findFrom( const string & s, size_t fromPos, const char * search ); 226 int findFrom( const string & s, size_t fromPos, const char * search, size_t searchsize ); 227 228 bool includes( const string & s, const string & search ); 229 bool includes( const string & s, const char * search ); 230 bool includes( const string & s, const char * search, size_t searchsize ); 231 232 bool startsWith( const string & s, const string & prefix ); 233 bool startsWith( const string & s, const char * prefix ); 234 bool startsWith( const string & s, const char * prefix, size_t prefixsize ); 235 236 bool endsWith( const string & s, const string & suffix ); 237 bool endsWith( const string & s, const char * suffix ); 238 bool endsWith( const string & s, const char * suffix, size_t suffixsize ); 228 239 229 240 // Modifiers 230 void padStart( string & s, size_t n);231 void padStart( string & s, size_t n, char padding);232 void padEnd( string & s, size_t n);233 void padEnd( string & s, size_t n, char padding);241 void padStart( string & s, size_t n ); 242 void padStart( string & s, size_t n, char padding ); 243 void padEnd( string & s, size_t n ); 244 void padEnd( string & s, size_t n, char padding ); 234 245 235 246 … … 239 250 240 251 void ?{}( charclass & ) = void; 241 void ?{}( charclass &, charclass ) = void;242 charclass ?=?( charclass &, charclass ) = void;243 244 void ?{}( charclass &, const string & chars );252 void ?{}( charclass &, charclass ) = void; 253 charclass ?=?( charclass &, charclass ) = void; 254 255 void ?{}( charclass &, const string & chars ); 245 256 void ?{}( charclass &, const char * chars ); 246 257 void ?{}( charclass &, const char * chars, size_t charssize ); 247 258 void ^?{}( charclass & ); 248 259 249 int include( const string & s, const charclass & mask);250 251 int exclude( const string & s, const charclass & mask);260 int include( const string & s, const charclass & mask ); 261 262 int exclude( const string & s, const charclass & mask ); 252 263 253 264 /* 254 265 What to do with? 255 StrRet include( string & s, const charclass & mask);256 StrRet exclude( string & s, const charclass & mask);266 StrRet include( string & s, const charclass & mask ); 267 StrRet exclude( string & s, const charclass & mask ); 257 268 */
Note: See TracChangeset
for help on using the changeset viewer.