- Timestamp:
- Apr 2, 2025, 11:12:18 PM (6 months ago)
- Branches:
- master
- Children:
- 9aa8dcc
- Parents:
- f8913b7c
- Location:
- libcfa/src/collections
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/collections/array.hfa
rf8913b7c ree70ff5 137 137 } 138 138 139 static inline size_t ?`len( arpk( N, S, Timmed, Tbase ) & ) {139 static inline size_t len( arpk( N, S, Timmed, Tbase ) & ) { 140 140 return N; 141 141 } … … 282 282 283 283 // desired: 284 // forall( A &, Tv &, [N])284 // forall( A &, Tv &, [N] ) 285 285 // trait ar { 286 // Tv& ?[?]( A &, zero_t );287 // Tv& ?[?]( A &, one_t );288 // Tv& ?[?]( A &, int );286 // Tv& ?[?]( A &, zero_t ); 287 // Tv& ?[?]( A &, one_t ); 288 // Tv& ?[?]( A &, int ); 289 289 // ... 290 // size_t ?`len( A& );290 // size_t len( A & ); 291 291 // void __taglen( tag(C), tag(N) ); 292 292 // }; … … 295 295 296 296 #define ar( A, Tv, N ) { \ 297 Tv& ?[?]( A &, zero_t );\298 Tv& ?[?]( A &, one_t ); \299 Tv& ?[?]( A &, int ); \300 Tv& ?[?]( A &, unsigned int ); \301 Tv& ?[?]( A &, long int ); \302 Tv& ?[?]( A &, unsigned long int ); \303 size_t ?`len( A& ); \297 Tv& ?[?]( A &, zero_t ); \ 298 Tv& ?[?]( A &, one_t ); \ 299 Tv& ?[?]( A &, int ); \ 300 Tv& ?[?]( A &, unsigned int ); \ 301 Tv& ?[?]( A &, long int ); \ 302 Tv& ?[?]( A &, unsigned long int ); \ 303 size_t len( A & ); \ 304 304 void __taglen( tag(A), tag(N) ); \ 305 305 } -
libcfa/src/collections/string.cfa
rf8913b7c ree70ff5 10 10 // Created On : Fri Sep 03 11:00:00 2021 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Apr 1 09:17:34202513 // Update Count : 2 8812 // Last Modified On : Wed Apr 2 14:12:35 2025 13 // Update Count : 295 14 14 // 15 15 … … 223 223 224 224 ofstream & ?|?( ofstream & os, _Ostream_Manip(string) f ) { 225 size_t l en = size( f.val );226 char cstr[l en+ 1]; // room for null terminator227 for ( i; l en) cstr[i] = f.val[i]; // copy string228 cstr[l en] = '\0';// terminate225 size_t l = len( f.val ); 226 char cstr[l + 1]; // room for null terminator 227 for ( i; l ) cstr[i] = f.val[i]; // copy string 228 cstr[l] = '\0'; // terminate 229 229 _Ostream_Manip(const char *) cf @= { cstr, f.wd, f.pc, f.base, {f.all} }; 230 230 return os | cf | nonl; … … 254 254 255 255 string ?()( string & s, ssize_t start, ssize_t len ) { 256 if ( start < 0 ) { start += s`len; }256 if ( start < 0 ) { start += len( s ); } 257 257 if ( len < 0 ) { len = -len; start -= len; } 258 if ( start > s`len) return (string){ "" };259 if ( start + len > s`len ) len = s`len- start;258 if ( start > len( s ) ) return (string){ "" }; 259 if ( start + len > len( s ) ) len = len( s ) - start; 260 260 string ret = { *s.inner, start, len }; 261 261 return ret`share; … … 263 263 264 264 string ?()( string & s, ssize_t start ) { 265 if ( start < 0 ) { start += s`len; }266 string ret = { *s.inner, start, size( s ) - start };265 if ( start < 0 ) { start += len( s ); } 266 string ret = { *s.inner, start, len( s ) - start }; 267 267 return ret`share; 268 268 } … … 299 299 // Getter 300 300 301 size_t size( const string & s ) {302 return size( *s.inner );301 size_t len( const string & s ) { 302 return len( *s.inner ); 303 303 } 304 304 … … 362 362 } 363 363 364 string ?+?( const char * s1, string & s2 ) {364 string ?+?( const char * s1, const string & s2 ) { 365 365 string ret = s1; 366 366 ret += s2; … … 371 371 string ret = s; 372 372 ret += c; 373 return ret; 374 } 375 376 string ?+?( char c1, char c2 ) { 377 string ret = c1; 378 ret += c2; 373 379 return ret; 374 380 } -
libcfa/src/collections/string.hfa
rf8913b7c ree70ff5 10 10 // Created On : Fri Sep 03 11:00:00 2021 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Apr 1 09:16:39202513 // Update Count : 1 5512 // Last Modified On : Wed Apr 2 23:09:11 2025 13 // Update Count : 161 14 14 // 15 15 … … 28 28 29 29 // Getters 30 //static size_t inline __attribute__((always_inline)) size( char c ) { return sizeof( c ); }; // base case 31 //static size_t inline __attribute__((always_inline)) size( wchar_t wc ) { return sizeof( wc ); }; // base case 32 static inline size_t size( const char * cs ) { return strlen( cs ); }; 33 static inline size_t ?`len( const char * cs ) { return size( cs ); }; 34 size_t size( const string & s ); 35 size_t ?`len( const string & s ) { return size( s ); } 36 static inline size_t strlen( const string & s ) { return size( s ); } 30 static inline size_t len( const char * cs ) { return strlen( cs ); }; 31 size_t len( const string & s ); 32 static inline size_t strlen( const string & s ) { return len( s ); } 37 33 38 34 // RAII, assignment … … 169 165 string ?+?( char c, const char * s ); // add a character to a copy of the string 170 166 string ?+?( const char * c, const char * s ); // copy and add with two NULL-terminated string 171 string ?+?( const char * c, string & s );// copy and add with NULL-terminated string167 string ?+?( const char * c, const string & s ); // copy and add with NULL-terminated string 172 168 string ?+?( const string & s, const char * c ); // copy and add with NULL-terminated string 169 string ?+?( char c1, char c2 ); // add two characters 173 170 174 171 static inline string & strcat( string & s, const string & s2 ) { s += s2; return s; } -
libcfa/src/collections/string_res.cfa
rf8913b7c ree70ff5 10 10 // Created On : Fri Sep 03 11:00:00 2021 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Mar 14 15:45:24202513 // Update Count : 8812 // Last Modified On : Tue Apr 1 23:29:58 2025 13 // Update Count : 91 14 14 // 15 15 … … 193 193 194 194 // Returns the size of the string in bytes 195 size_t size(const string_res & s) with(s) {195 size_t len(const string_res & s) with(s) { 196 196 return Handle.lnth; 197 197 } … … 255 255 fini: { 256 256 char rfmt[5] = { ' ', delimiters[0], '%', 'n', '\0' }; 257 int l en = -1;// may not be set in fmt258 args = fmt( is, rfmt, &l en );// remove leading whitespace and quote259 if ( eof( is ) || l en== -1 ) break fini;257 int l = -1; // may not be set in fmt 258 args = fmt( is, rfmt, &l ); // remove leading whitespace and quote 259 if ( eof( is ) || l == -1 ) break fini; 260 260 261 261 // Change the remainder of the read into a getline by reseting the closing delimiter. … … 353 353 void ?{}( string_res & s, ssize_t rhs ) { 354 354 char buf[64]; 355 int l en;356 snprintf( buf, sizeof(buf)-1, "%zd%n", rhs, &l en);357 ( s ){ buf, l en};355 int l; 356 snprintf( buf, sizeof(buf)-1, "%zd%n", rhs, &l ); 357 ( s ){ buf, l }; 358 358 } 359 359 void ?{}( string_res & s, size_t rhs ) { 360 360 char buf[64]; 361 int l en;362 snprintf( buf, sizeof(buf)-1, "%zu%n", rhs, &l en);363 ( s ){ buf, l en};361 int l; 362 snprintf( buf, sizeof(buf)-1, "%zu%n", rhs, &l ); 363 ( s ){ buf, l }; 364 364 } 365 365 void ?{}( string_res & s, double rhs ) { 366 366 char buf[64]; 367 int l en;368 snprintf( buf, sizeof(buf)-1, "%g%n", rhs, &l en);369 ( s ){ buf, l en};367 int l; 368 snprintf( buf, sizeof(buf)-1, "%g%n", rhs, &l ); 369 ( s ){ buf, l }; 370 370 } 371 371 void ?{}( string_res & s, long double rhs ) { 372 372 char buf[64]; 373 int l en;374 snprintf( buf, sizeof(buf)-1, "%Lg%n", rhs, &l en);375 ( s ){ buf, l en};373 int l; 374 snprintf( buf, sizeof(buf)-1, "%Lg%n", rhs, &l ); 375 ( s ){ buf, l }; 376 376 } 377 377 void ?{}( string_res & s, double _Complex rhs ) { 378 378 char buf[64]; 379 int l en;380 snprintf( buf, sizeof(buf)-1, "%g+%gi%n", creal( rhs ), cimag( rhs ), &l en);381 ( s ){ buf, l en};379 int l; 380 snprintf( buf, sizeof(buf)-1, "%g+%gi%n", creal( rhs ), cimag( rhs ), &l ); 381 ( s ){ buf, l }; 382 382 } 383 383 void ?{}( string_res & s, long double _Complex rhs ) { 384 384 char buf[64]; 385 int l en;386 snprintf( buf, sizeof(buf)-1, "%Lg+%Lgi%n", creall( rhs ), cimagl( rhs ), &l en);387 ( s ){ buf, l en};385 int l; 386 snprintf( buf, sizeof(buf)-1, "%Lg+%Lgi%n", creall( rhs ), cimagl( rhs ), &l ); 387 ( s ){ buf, l }; 388 388 } 389 389 … … 794 794 795 795 bool contains(const string_res & s, char ch) { 796 for ( i; size(s) ) {796 for ( i; len(s) ) { 797 797 if (s[i] == ch) return true; 798 798 } … … 941 941 942 942 int exclude(const string_res & s, const charclass_res & mask) { 943 for ( i; size(s) ) {943 for ( i; len(s) ) { 944 944 if ( test(mask, s[i]) ) return i; 945 945 } 946 return size(s);946 return len(s); 947 947 } 948 948 949 949 int include(const string_res & s, const charclass_res & mask) { 950 for ( i; size(s) ) {950 for ( i; len(s) ) { 951 951 if ( ! test(mask, s[i]) ) return i; 952 952 } 953 return size(s);953 return len(s); 954 954 } 955 955 -
libcfa/src/collections/string_res.hfa
rf8913b7c ree70ff5 10 10 // Created On : Fri Sep 03 11:00:00 2021 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Mar 14 15:44:01202513 // Update Count : 6 112 // Last Modified On : Tue Apr 1 23:24:20 2025 13 // Update Count : 62 14 14 // 15 15 … … 70 70 71 71 // Getters 72 size_t size(const string_res & s);72 size_t len(const string_res & s); 73 73 74 74 // Constructors, Assignment Operators, Destructor … … 89 89 void ?{}(string_res & s, const string_res & src, StrResInitMode, size_t start, size_t len ); 90 90 static inline void ?{}(string_res & s, const string_res & src, StrResInitMode mode ) { 91 ?{}( s, src, mode, 0, size(src));91 ?{}( s, src, mode, 0, len(src)); 92 92 } 93 93 static 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) );94 ?{}( s, src, mode, 0, (len(src) > maxlen)?maxlen:len(src) ); 95 95 } 96 96 void ?{}( string_res & s, ssize_t rhs );
Note:
See TracChangeset
for help on using the changeset viewer.