Changeset 6264087
- Timestamp:
- Aug 14, 2023, 9:29:40 PM (15 months ago)
- Branches:
- master
- Children:
- 329487c
- Parents:
- b5e725a
- Location:
- libcfa/src/containers
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/containers/string.cfa
rb5e725a r6264087 10 10 // Created On : Fri Sep 03 11:00:00 2021 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : S at Aug 12 15:24:18 202313 // Update Count : 612 // Last Modified On : Sun Aug 13 22:50:08 2023 13 // Update Count : 7 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 ); … … 110 110 } 111 111 112 ifstream & ?|?(ifstream & in, string &this) {112 ifstream & ?|?(ifstream & in, string & this) { 113 113 return in | (*this.inner); // read to internal string_res 114 114 } 115 115 116 void ?|?( ifstream & in, string & this ) { 117 (ifstream &)(in | this); ends( in ); 118 } 116 119 117 120 //////////////////////////////////////////////////////// … … 131 134 // Comparison 132 135 133 bool ?==?(const string & s, const string &other) {136 bool ?==?(const string & s, const string & other) { 134 137 return *s.inner == *other.inner; 135 138 } 136 139 137 bool ?!=?(const string & s, const string &other) {140 bool ?!=?(const string & s, const string & other) { 138 141 return *s.inner != *other.inner; 139 142 } 140 143 141 bool ?==?(const string & s, const char* other) {144 bool ?==?(const string & s, const char * other) { 142 145 return *s.inner == other; 143 146 } 144 147 145 bool ?!=?(const string & s, const char* other) {148 bool ?!=?(const string & s, const char * other) { 146 149 return *s.inner != other; 147 150 } … … 150 153 // Getter 151 154 152 size_t size(const string & s) {155 size_t size(const string & s) { 153 156 return size( * s.inner ); 154 157 } … … 157 160 // Concatenation 158 161 159 void ?+=?(string & s, char other) {162 void ?+=?(string & s, char other) { 160 163 (*s.inner) += other; 161 164 } 162 165 163 void ?+=?(string & s, const string &s2) {166 void ?+=?(string & s, const string & s2) { 164 167 (*s.inner) += (*s2.inner); 165 168 } 166 169 167 void ?+=?(string & s, const char* other) {170 void ?+=?(string & s, const char * other) { 168 171 (*s.inner) += other; 169 172 } 170 173 171 string ?+?(const string & s, char other) {174 string ?+?(const string & s, char other) { 172 175 string ret = s; 173 176 ret += other; … … 175 178 } 176 179 177 string ?+?(const string & s, const string &s2) {180 string ?+?(const string & s, const string & s2) { 178 181 string ret = s; 179 182 ret += s2; … … 181 184 } 182 185 183 string ?+?(const char * s1, const char* s2) {186 string ?+?(const char * s1, const char * s2) { 184 187 string ret = s1; 185 188 ret += s2; … … 187 190 } 188 191 189 string ?+?(const string & s, const char* other) {192 string ?+?(const string & s, const char * other) { 190 193 string ret = s; 191 194 ret += other; … … 196 199 // Repetition 197 200 198 string ?*?(const string & s, size_t factor) {201 string ?*?(const string & s, size_t factor) { 199 202 string ret = ""; 200 203 for (factor) ret += s; … … 216 219 // Character access 217 220 218 char ?[?](const string & s, size_t index) {221 char ?[?](const string & s, size_t index) { 219 222 return (*s.inner)[index]; 220 223 } 221 224 222 string ?[?](string & s, size_t index) {225 string ?[?](string & s, size_t index) { 223 226 string ret = { *s.inner, index, index + 1 }; 224 227 return ret`shareEdits; … … 228 231 // Search 229 232 230 bool contains(const string & s, char ch) {233 bool contains(const string & s, char ch) { 231 234 return contains( *s.inner, ch ); 232 235 } 233 236 234 int find(const string & s, char search) {237 int find(const string & s, char search) { 235 238 return find( *s.inner, search ); 236 239 } 237 240 238 int find(const string & s, const string &search) {241 int find(const string & s, const string & search) { 239 242 return find( *s.inner, *search.inner ); 240 243 } 241 244 242 int find(const string & s, const char* search) {245 int find(const string & s, const char * search) { 243 246 return find( *s.inner, search); 244 247 } 245 248 246 int find(const string & s, const char* search, size_t searchsize) {249 int find(const string & s, const char * search, size_t searchsize) { 247 250 return find( *s.inner, search, searchsize); 248 251 } 249 252 250 int findFrom(const string & s, size_t fromPos, char search) {253 int findFrom(const string & s, size_t fromPos, char search) { 251 254 return findFrom( *s.inner, fromPos, search ); 252 255 } 253 256 254 int findFrom(const string & s, size_t fromPos, const string &search) {257 int findFrom(const string & s, size_t fromPos, const string & search) { 255 258 return findFrom( *s.inner, fromPos, *search.inner ); 256 259 } 257 260 258 int findFrom(const string & s, size_t fromPos, const char* search) {261 int findFrom(const string & s, size_t fromPos, const char * search) { 259 262 return findFrom( *s.inner, fromPos, search ); 260 263 } 261 264 262 int findFrom(const string & s, size_t fromPos, const char* search, size_t searchsize) {265 int findFrom(const string & s, size_t fromPos, const char * search, size_t searchsize) { 263 266 return findFrom( *s.inner, fromPos, search, searchsize ); 264 267 } 265 268 266 bool includes(const string & s, const string &search) {269 bool includes(const string & s, const string & search) { 267 270 return includes( *s.inner, *search.inner ); 268 271 } 269 272 270 bool includes(const string & s, const char* search) {273 bool includes(const string & s, const char * search) { 271 274 return includes( *s.inner, search ); 272 275 } 273 276 274 bool includes(const string & s, const char* search, size_t searchsize) {277 bool includes(const string & s, const char * search, size_t searchsize) { 275 278 return includes( *s.inner, search, searchsize ); 276 279 } 277 280 278 bool startsWith(const string & s, const string &prefix) {281 bool startsWith(const string & s, const string & prefix) { 279 282 return startsWith( *s.inner, *prefix.inner ); 280 283 } 281 284 282 bool startsWith(const string & s, const char* prefix) {285 bool startsWith(const string & s, const char * prefix) { 283 286 return startsWith( *s.inner, prefix ); 284 287 } 285 288 286 bool startsWith(const string & s, const char* prefix, size_t prefixsize) {289 bool startsWith(const string & s, const char * prefix, size_t prefixsize) { 287 290 return startsWith( *s.inner, prefix, prefixsize ); 288 291 } 289 292 290 bool endsWith(const string & s, const string &suffix) {293 bool endsWith(const string & s, const string & suffix) { 291 294 return endsWith( *s.inner, *suffix.inner ); 292 295 } 293 296 294 bool endsWith(const string & s, const char* suffix) {297 bool endsWith(const string & s, const char * suffix) { 295 298 return endsWith( *s.inner, suffix ); 296 299 } 297 300 298 bool endsWith(const string & s, const char* suffix, size_t suffixsize) {301 bool endsWith(const string & s, const char * suffix, size_t suffixsize) { 299 302 return endsWith( *s.inner, suffix, suffixsize ); 300 303 } … … 326 329 327 330 328 int exclude(const string & s, const charclass &mask) {331 int exclude(const string & s, const charclass & mask) { 329 332 return exclude( *s.inner, *mask.inner ); 330 333 } 331 334 /* 332 StrSlice exclude(string & s, const charclass &mask) {335 StrSlice exclude(string & s, const charclass & mask) { 333 336 } 334 337 */ 335 338 336 int include(const string & s, const charclass &mask) {339 int include(const string & s, const charclass & mask) { 337 340 return include( *s.inner, *mask.inner ); 338 341 } 339 342 340 343 /* 341 StrSlice include(string & s, const charclass &mask) {344 StrSlice include(string & s, const charclass & mask) { 342 345 } 343 346 */ -
libcfa/src/containers/string.hfa
rb5e725a r6264087 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 : 111 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Aug 13 22:46:46 2023 13 // Update Count : 4 14 14 // 15 15 … … 28 28 29 29 // Getters 30 size_t size(const string & s);30 size_t size(const string & s); 31 31 32 32 // RAII, assignment 33 void ?{}( string & this); // empty string34 void ?{}(string & s, const char* initial); // copy from string literal (NULL-terminated)35 void ?{}(string & s, const char* buffer, size_t bsize); // copy specific length from buffer33 void ?{}(string & this); // empty string 34 void ?{}(string & s, const char * initial); // copy from string literal (NULL-terminated) 35 void ?{}(string & s, const char * buffer, size_t bsize); // copy specific length from buffer 36 36 37 void ?{}(string & s, const string & s2);38 void ?{}(string & s, string & s2);37 void ?{}(string & s, const string & s2); 38 void ?{}(string & s, string & s2); 39 39 40 void ?=?(string & s, const char* other); // copy assignment from literal41 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 autogen40 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 44 44 //string ?=?( string &, string ) = void; 45 void ^?{}(string & s);45 void ^?{}(string & s); 46 46 47 47 // Alternate construction: request shared edits … … 53 53 54 54 // IO Operator 55 ofstream & ?|?(ofstream &out, const string &s); 56 void ?|?(ofstream &out, const string &s); 57 ifstream & ?|?(ifstream &in, string &s); 55 ofstream & ?|?(ofstream & out, const string & s); 56 void ?|?(ofstream & out, const string & s); 57 ifstream & ?|?(ifstream & in, string & s); 58 void ?|?( ifstream & in, string & this ); 58 59 59 60 // Concatenation 60 void ?+=?(string & s, char other); // append a character61 void ?+=?(string & s, const string &s2); // append-concatenate to first string62 void ?+=?(string & s, const char* other); // append-concatenate to first string63 string ?+?(const string & s, char other); // add a character to a copy of the string64 string ?+?(const string & s, const string &s2); // copy and concatenate both strings65 string ?+?(const char * s1, const char* s2); // concatenate both strings66 string ?+?(const string & s, const char* other); // copy and concatenate with NULL-terminated string61 void ?+=?(string & s, char other); // append a character 62 void ?+=?(string & s, const string & s2); // append-concatenate to first string 63 void ?+=?(string & s, const char * other); // append-concatenate to first string 64 string ?+?(const string & s, char other); // add a character to a copy of the string 65 string ?+?(const string & s, const string & s2); // copy and concatenate both strings 66 string ?+?(const char * s1, const char * s2); // concatenate both strings 67 string ?+?(const string & s, const char * other); // copy and concatenate with NULL-terminated string 67 68 68 69 // Repetition 69 string ?*?(const string & s, size_t factor);70 string ?*?(const string & s, size_t factor); 70 71 string ?*?(char c, size_t size); 71 72 string ?*?(const char *s, size_t size); 72 73 73 74 // Character access 74 char ?[?](const string & s, size_t index);75 string ?[?](string & s, size_t index); // mutable length-1 slice of original76 //char codePointAt(const string & s, size_t index); // to revisit under Unicode75 char ?[?](const string & s, size_t index); 76 string ?[?](string & s, size_t index); // mutable length-1 slice of original 77 //char codePointAt(const string & s, size_t index); // to revisit under Unicode 77 78 78 79 // Comparisons 79 bool ?==?(const string & s, const string &other);80 bool ?!=?(const string & s, const string &other);81 bool ?==?(const string & s, const char* other);82 bool ?!=?(const string & s, const char* other);80 bool ?==?(const string & s, const string & other); 81 bool ?!=?(const string & s, const string & other); 82 bool ?==?(const string & s, const char * other); 83 bool ?!=?(const string & s, const char * other); 83 84 84 85 // Slicing … … 87 88 88 89 // String search 89 bool contains(const string & s, char ch); // single character90 bool contains(const string & s, char ch); // single character 90 91 91 int find(const string & s, char search);92 int find(const string & s, const string &search);93 int find(const string & s, const char* search);94 int find(const string & s, const char* search, size_t searchsize);92 int find(const string & s, char search); 93 int find(const string & s, const string & search); 94 int find(const string & s, const char * search); 95 int find(const string & s, const char * search, size_t searchsize); 95 96 96 int findFrom(const string & s, size_t fromPos, char search);97 int findFrom(const string & s, size_t fromPos, const string &search);98 int findFrom(const string & s, size_t fromPos, const char* search);99 int findFrom(const string & s, size_t fromPos, const char* search, size_t searchsize);97 int findFrom(const string & s, size_t fromPos, char search); 98 int findFrom(const string & s, size_t fromPos, const string & search); 99 int findFrom(const string & s, size_t fromPos, const char * search); 100 int findFrom(const string & s, size_t fromPos, const char * search, size_t searchsize); 100 101 101 bool includes(const string & s, const string &search);102 bool includes(const string & s, const char* search);103 bool includes(const string & s, const char* search, size_t searchsize);102 bool includes(const string & s, const string & search); 103 bool includes(const string & s, const char * search); 104 bool includes(const string & s, const char * search, size_t searchsize); 104 105 105 bool startsWith(const string & s, const string &prefix);106 bool startsWith(const string & s, const char* prefix);107 bool startsWith(const string & s, const char* prefix, size_t prefixsize);106 bool startsWith(const string & s, const string & prefix); 107 bool startsWith(const string & s, const char * prefix); 108 bool startsWith(const string & s, const char * prefix, size_t prefixsize); 108 109 109 bool endsWith(const string & s, const string &suffix);110 bool endsWith(const string & s, const char* suffix);111 bool endsWith(const string & s, const char* suffix, size_t suffixsize);110 bool endsWith(const string & s, const string & suffix); 111 bool endsWith(const string & s, const char * suffix); 112 bool endsWith(const string & s, const char * suffix, size_t suffixsize); 112 113 113 114 // Modifiers 114 void padStart(string & s, size_t n);115 void padStart(string & s, size_t n, char padding);116 void padEnd(string & s, size_t n);117 void padEnd(string & s, size_t n, char padding);115 void padStart(string & s, size_t n); 116 void padStart(string & s, size_t n, char padding); 117 void padEnd(string & s, size_t n); 118 void padEnd(string & s, size_t n, char padding); 118 119 119 120 … … 132 133 void ^?{}( charclass & ); 133 134 134 int include(const string & s, const charclass &mask);135 int include(const string & s, const charclass & mask); 135 136 136 int exclude(const string & s, const charclass &mask);137 int exclude(const string & s, const charclass & mask); 137 138 138 139 /* 139 140 What to do with? 140 StrRet include(string & s, const charclass &mask);141 StrRet exclude(string & s, const charclass &mask);141 StrRet include(string & s, const charclass & mask); 142 StrRet exclude(string & s, const charclass & mask); 142 143 */ 143 144
Note: See TracChangeset
for help on using the changeset viewer.