Changeset 2a301ff for libcfa/src/collections/string.cfa
- Timestamp:
- Aug 31, 2023, 11:31:15 PM (2 years ago)
- Branches:
- master
- Children:
- 950c58e
- Parents:
- 92355883 (diff), 686912c (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. - File:
-
- 1 moved
-
libcfa/src/collections/string.cfa (moved) (moved from libcfa/src/containers/string.cfa ) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/collections/string.cfa
r92355883 r2a301ff 9 9 // Author : Michael L. Brooks 10 10 // Created On : Fri Sep 03 11:00:00 2021 11 // Last Modified By : Michael L. Brooks12 // Last Modified On : Fri Sep 03 11:00:00 202113 // Update Count : 1 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 31 13:20:41 2023 13 // Update Count : 161 14 14 // 15 15 … … 55 55 } 56 56 57 void ?{}( string & this, const char * buffer, size_t bsize) {57 void ?{}( string & this, const char * buffer, size_t bsize) { 58 58 (this.inner) { malloc() }; 59 59 ?{}( *this.inner, buffer, bsize ); … … 100 100 101 101 //////////////////////////////////////////////////////// 102 // Output 103 104 ofstream & ?|?( ofstream & fs, const string & this ) { 105 return fs | (*this.inner); 106 } 107 108 void ?|?( ofstream & fs, const string & this ) { 109 fs | (*this.inner); 102 // Input-Output 103 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 ); 110 } 111 112 ifstream & ?|?(ifstream & in, string & this) { 113 return in | (*this.inner); // read to internal string_res 114 } 115 116 void ?|?( ifstream & in, string & this ) { 117 (ifstream &)(in | this); ends( in ); 118 } 119 120 ifstream & ?|?( ifstream & is, _Istream_str f ) { 121 // skip, same as for char * 122 if ( ! &f.s ) { 123 // fprintf( stderr, "skip %s %d\n", f.scanset, f.wd ); 124 if ( f.wd == -1 ) fmt( is, f.scanset, "" ); // no input arguments 125 else for ( f.wd ) fmt( is, "%*c" ); 126 return is; 127 } // if 128 129 // .---------------, 130 // | | | | |...|0|0| check and guard 131 // `---------------' 132 enum { gwd = 128 + 2, wd = gwd - 1 }; // guarded and unguarded width 133 char cstr[gwd]; // read in chunks 134 bool cont = false; 135 136 if ( f.wd == -1 ) f.wd = wd; 137 _Istream_Cstr cfmt = { cstr, (_Istream_str_base)f }; 138 139 cstr[wd] = '\0'; // guard null terminate string 140 try { 141 is | cfmt; 142 } catch( cstring_length * ) { 143 cont = true; 144 } finally { 145 f.s = cstr; // ok to initialize string 146 } // try 147 for ( ; cont; ) { // overflow read ? 148 cont = false; 149 try { 150 is | cfmt; 151 } catch( cstring_length * ) { 152 cont = true; // continue not allowed 153 } finally { 154 f.s += cstr; // build string chunk at a time 155 } // try 156 } // for 157 return is; 158 } // ?|? 159 160 void ?|?( ifstream & in, _Istream_str f ) { 161 (ifstream &)(in | f); ends( in ); 110 162 } 111 163 … … 118 170 } 119 171 172 string ?()( string & this, size_t start ) { 173 string ret = { *this.inner, start, size( this ) }; 174 return ret`shareEdits; 175 } 176 120 177 //////////////////////////////////////////////////////// 121 178 // Comparison 122 179 123 bool ?==?(const string & s, const string &other) {180 bool ?==?(const string & s, const string & other) { 124 181 return *s.inner == *other.inner; 125 182 } 126 183 127 bool ?!=?(const string & s, const string &other) {184 bool ?!=?(const string & s, const string & other) { 128 185 return *s.inner != *other.inner; 129 186 } 130 187 131 bool ?==?(const string & s, const char* other) {188 bool ?==?(const string & s, const char * other) { 132 189 return *s.inner == other; 133 190 } 134 191 135 bool ?!=?(const string & s, const char* other) {192 bool ?!=?(const string & s, const char * other) { 136 193 return *s.inner != other; 137 194 } … … 140 197 // Getter 141 198 142 size_t size(const string & s) {199 size_t size(const string & s) { 143 200 return size( * s.inner ); 144 201 } … … 147 204 // Concatenation 148 205 149 void ?+=?(string & s, char other) {206 void ?+=?(string & s, char other) { 150 207 (*s.inner) += other; 151 208 } 152 209 153 void ?+=?(string & s, const string &s2) {210 void ?+=?(string & s, const string & s2) { 154 211 (*s.inner) += (*s2.inner); 155 212 } 156 213 157 void ?+=?(string & s, const char* other) {214 void ?+=?(string & s, const char * other) { 158 215 (*s.inner) += other; 159 216 } 160 217 161 string ?+?(const string & s, char other) {218 string ?+?(const string & s, char other) { 162 219 string ret = s; 163 220 ret += other; … … 165 222 } 166 223 167 string ?+?(const string & s, const string &s2) {224 string ?+?(const string & s, const string & s2) { 168 225 string ret = s; 169 226 ret += s2; … … 171 228 } 172 229 173 string ?+?(const char * s1, const char* s2) {230 string ?+?(const char * s1, const char * s2) { 174 231 string ret = s1; 175 232 ret += s2; … … 177 234 } 178 235 179 string ?+?(const string & s, const char* other) {236 string ?+?(const string & s, const char * other) { 180 237 string ret = s; 181 238 ret += other; … … 186 243 // Repetition 187 244 188 string ?*?(const string & s, size_t factor) {245 string ?*?(const string & s, size_t factor) { 189 246 string ret = ""; 190 247 for (factor) ret += s; … … 206 263 // Character access 207 264 208 char ?[?](const string & s, size_t index) {265 char ?[?](const string & s, size_t index) { 209 266 return (*s.inner)[index]; 210 267 } 211 268 212 string ?[?](string & s, size_t index) {269 string ?[?](string & s, size_t index) { 213 270 string ret = { *s.inner, index, index + 1 }; 214 271 return ret`shareEdits; … … 218 275 // Search 219 276 220 bool contains(const string & s, char ch) {277 bool contains(const string & s, char ch) { 221 278 return contains( *s.inner, ch ); 222 279 } 223 280 224 int find(const string & s, char search) {281 int find(const string & s, char search) { 225 282 return find( *s.inner, search ); 226 283 } 227 284 228 int find(const string & s, const string &search) {285 int find(const string & s, const string & search) { 229 286 return find( *s.inner, *search.inner ); 230 287 } 231 288 232 int find(const string & s, const char* search) {289 int find(const string & s, const char * search) { 233 290 return find( *s.inner, search); 234 291 } 235 292 236 int find(const string & s, const char* search, size_t searchsize) {293 int find(const string & s, const char * search, size_t searchsize) { 237 294 return find( *s.inner, search, searchsize); 238 295 } 239 296 240 int findFrom(const string & s, size_t fromPos, char search) {297 int findFrom(const string & s, size_t fromPos, char search) { 241 298 return findFrom( *s.inner, fromPos, search ); 242 299 } 243 300 244 int findFrom(const string & s, size_t fromPos, const string &search) {301 int findFrom(const string & s, size_t fromPos, const string & search) { 245 302 return findFrom( *s.inner, fromPos, *search.inner ); 246 303 } 247 304 248 int findFrom(const string & s, size_t fromPos, const char* search) {305 int findFrom(const string & s, size_t fromPos, const char * search) { 249 306 return findFrom( *s.inner, fromPos, search ); 250 307 } 251 308 252 int findFrom(const string & s, size_t fromPos, const char* search, size_t searchsize) {309 int findFrom(const string & s, size_t fromPos, const char * search, size_t searchsize) { 253 310 return findFrom( *s.inner, fromPos, search, searchsize ); 254 311 } 255 312 256 bool includes(const string & s, const string &search) {313 bool includes(const string & s, const string & search) { 257 314 return includes( *s.inner, *search.inner ); 258 315 } 259 316 260 bool includes(const string & s, const char* search) {317 bool includes(const string & s, const char * search) { 261 318 return includes( *s.inner, search ); 262 319 } 263 320 264 bool includes(const string & s, const char* search, size_t searchsize) {321 bool includes(const string & s, const char * search, size_t searchsize) { 265 322 return includes( *s.inner, search, searchsize ); 266 323 } 267 324 268 bool startsWith(const string & s, const string &prefix) {325 bool startsWith(const string & s, const string & prefix) { 269 326 return startsWith( *s.inner, *prefix.inner ); 270 327 } 271 328 272 bool startsWith(const string & s, const char* prefix) {329 bool startsWith(const string & s, const char * prefix) { 273 330 return startsWith( *s.inner, prefix ); 274 331 } 275 332 276 bool startsWith(const string & s, const char* prefix, size_t prefixsize) {333 bool startsWith(const string & s, const char * prefix, size_t prefixsize) { 277 334 return startsWith( *s.inner, prefix, prefixsize ); 278 335 } 279 336 280 bool endsWith(const string & s, const string &suffix) {337 bool endsWith(const string & s, const string & suffix) { 281 338 return endsWith( *s.inner, *suffix.inner ); 282 339 } 283 340 284 bool endsWith(const string & s, const char* suffix) {341 bool endsWith(const string & s, const char * suffix) { 285 342 return endsWith( *s.inner, suffix ); 286 343 } 287 344 288 bool endsWith(const string & s, const char* suffix, size_t suffixsize) {345 bool endsWith(const string & s, const char * suffix, size_t suffixsize) { 289 346 return endsWith( *s.inner, suffix, suffixsize ); 290 347 } … … 316 373 317 374 318 int exclude(const string & s, const charclass &mask) {375 int exclude(const string & s, const charclass & mask) { 319 376 return exclude( *s.inner, *mask.inner ); 320 377 } 321 378 /* 322 StrSlice exclude(string & s, const charclass &mask) {379 StrSlice exclude(string & s, const charclass & mask) { 323 380 } 324 381 */ 325 382 326 int include(const string & s, const charclass &mask) {383 int include(const string & s, const charclass & mask) { 327 384 return include( *s.inner, *mask.inner ); 328 385 } 329 386 330 387 /* 331 StrSlice include(string & s, const charclass &mask) {388 StrSlice include(string & s, const charclass & mask) { 332 389 } 333 390 */
Note:
See TracChangeset
for help on using the changeset viewer.