Changeset ee70ff5 for libcfa


Ignore:
Timestamp:
Apr 2, 2025, 11:12:18 PM (6 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
9aa8dcc
Parents:
f8913b7c
Message:

harmonize length computations to function name "len"

Location:
libcfa/src/collections
Files:
5 edited

Legend:

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

    rf8913b7c ree70ff5  
    137137        }
    138138
    139         static inline size_t ?`len( arpk( N, S, Timmed, Tbase ) & ) {
     139        static inline size_t len( arpk( N, S, Timmed, Tbase ) & ) {
    140140                return N;
    141141        }
     
    282282
    283283// desired:
    284 // forall(A &, Tv &, [N])
     284// forall( A &, Tv &, [N] )
    285285// 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     );
    289289//                                 ...
    290 //       size_t ?`len( A& );
     290//       size_t len( A & );
    291291//       void __taglen( tag(C), tag(N) );
    292292// };
     
    295295
    296296#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 & );                                      \
    304304        void __taglen( tag(A), tag(N) );        \
    305305}
  • libcfa/src/collections/string.cfa

    rf8913b7c ree70ff5  
    1010// Created On       : Fri Sep 03 11:00:00 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Apr  1 09:17:34 2025
    13 // Update Count     : 288
     12// Last Modified On : Wed Apr  2 14:12:35 2025
     13// Update Count     : 295
    1414//
    1515
     
    223223
    224224ofstream & ?|?( ofstream & os, _Ostream_Manip(string) f ) {
    225         size_t len = size( f.val );
    226         char cstr[len + 1];                                                                     // room for null terminator
    227         for ( i; len ) cstr[i] = f.val[i];                                      // copy string
    228         cstr[len] = '\0';                                                                       // terminate
     225        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
    229229        _Ostream_Manip(const char *) cf @= { cstr, f.wd, f.pc, f.base, {f.all} };
    230230        return os | cf | nonl;
     
    254254
    255255string ?()( string & s, ssize_t start, ssize_t len ) {
    256         if ( start < 0 ) { start += s`len; }
     256        if ( start < 0 ) { start += len( s ); }
    257257        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;
    260260        string ret = { *s.inner, start, len };
    261261        return ret`share;
     
    263263
    264264string ?()( 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 };
    267267        return ret`share;
    268268}
     
    299299// Getter
    300300
    301 size_t size( const string & s ) {
    302         return size( *s.inner );
     301size_t len( const string & s ) {
     302        return len( *s.inner );
    303303}
    304304
     
    362362}
    363363
    364 string ?+?( const char * s1, string & s2 ) {
     364string ?+?( const char * s1, const string & s2 ) {
    365365        string ret = s1;
    366366        ret += s2;
     
    371371        string ret = s;
    372372        ret += c;
     373        return ret;
     374}
     375
     376string ?+?( char c1, char c2 ) {
     377        string ret = c1;
     378        ret += c2;
    373379        return ret;
    374380}
  • libcfa/src/collections/string.hfa

    rf8913b7c ree70ff5  
    1010// Created On       : Fri Sep 03 11:00:00 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Apr  1 09:16:39 2025
    13 // Update Count     : 155
     12// Last Modified On : Wed Apr  2 23:09:11 2025
     13// Update Count     : 161
    1414//
    1515
     
    2828
    2929// 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 ); }
     30static inline size_t len( const char * cs ) { return strlen( cs ); };
     31size_t len( const string & s );
     32static inline size_t strlen( const string & s ) { return len( s ); }
    3733
    3834// RAII, assignment
     
    169165string ?+?( char c, const char * s );                                   // add a character to a copy of the string
    170166string ?+?( 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 string
     167string ?+?( const char * c, const string & s );                 // copy and add with NULL-terminated string
    172168string ?+?( const string & s, const char * c );                 // copy and add with NULL-terminated string
     169string ?+?( char c1, char c2 );                                                 // add two characters
    173170
    174171static inline string & strcat( string & s, const string & s2 ) { s += s2; return s; }
  • libcfa/src/collections/string_res.cfa

    rf8913b7c ree70ff5  
    1010// Created On       : Fri Sep 03 11:00:00 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Mar 14 15:45:24 2025
    13 // Update Count     : 88
     12// Last Modified On : Tue Apr  1 23:29:58 2025
     13// Update Count     : 91
    1414//
    1515
     
    193193
    194194// Returns the size of the string in bytes
    195 size_t size(const string_res & s) with(s) {
     195size_t len(const string_res & s) with(s) {
    196196        return Handle.lnth;
    197197}
     
    255255  fini: {
    256256                char rfmt[5] = { ' ', delimiters[0], '%', 'n', '\0' };
    257                 int len = -1;                                                                   // may not be set in fmt
    258                 args = fmt( is, rfmt, &len );                                   // remove leading whitespace and quote
    259           if ( eof( is ) || len == -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;
    260260
    261261                // Change the remainder of the read into a getline by reseting the closing delimiter.
     
    353353void ?{}( string_res & s, ssize_t rhs ) {
    354354        char buf[64];
    355         int len;
    356         snprintf( buf, sizeof(buf)-1, "%zd%n", rhs, &len );
    357         ( s ){ buf, len };
     355        int l;
     356        snprintf( buf, sizeof(buf)-1, "%zd%n", rhs, &l );
     357        ( s ){ buf, l };
    358358}
    359359void ?{}( string_res & s, size_t rhs ) {
    360360        char buf[64];
    361         int len;
    362         snprintf( buf, sizeof(buf)-1, "%zu%n", rhs, &len );
    363         ( s ){ buf, len };
     361        int l;
     362        snprintf( buf, sizeof(buf)-1, "%zu%n", rhs, &l );
     363        ( s ){ buf, l };
    364364}
    365365void ?{}( string_res & s, double rhs ) {
    366366        char buf[64];
    367         int len;
    368         snprintf( buf, sizeof(buf)-1, "%g%n", rhs, &len );
    369         ( s ){ buf, len };
     367        int l;
     368        snprintf( buf, sizeof(buf)-1, "%g%n", rhs, &l );
     369        ( s ){ buf, l };
    370370}
    371371void ?{}( string_res & s, long double rhs ) {
    372372        char buf[64];
    373         int len;
    374         snprintf( buf, sizeof(buf)-1, "%Lg%n", rhs, &len );
    375         ( s ){ buf, len };
     373        int l;
     374        snprintf( buf, sizeof(buf)-1, "%Lg%n", rhs, &l );
     375        ( s ){ buf, l };
    376376}
    377377void ?{}( string_res & s, double _Complex rhs ) {
    378378        char buf[64];
    379         int len;
    380         snprintf( buf, sizeof(buf)-1, "%g+%gi%n", creal( rhs ), cimag( rhs ), &len );
    381         ( s ){ buf, len };
     379        int l;
     380        snprintf( buf, sizeof(buf)-1, "%g+%gi%n", creal( rhs ), cimag( rhs ), &l );
     381        ( s ){ buf, l };
    382382}
    383383void ?{}( string_res & s, long double _Complex rhs ) {
    384384        char buf[64];
    385         int len;
    386         snprintf( buf, sizeof(buf)-1, "%Lg+%Lgi%n", creall( rhs ), cimagl( rhs ), &len );
    387         ( s ){ buf, len };
     385        int l;
     386        snprintf( buf, sizeof(buf)-1, "%Lg+%Lgi%n", creall( rhs ), cimagl( rhs ), &l );
     387        ( s ){ buf, l };
    388388}
    389389
     
    794794
    795795bool contains(const string_res & s, char ch) {
    796         for ( i; size(s) ) {
     796        for ( i; len(s) ) {
    797797                if (s[i] == ch) return true;
    798798        }
     
    941941
    942942int exclude(const string_res & s, const charclass_res & mask) {
    943         for ( i; size(s) ) {
     943        for ( i; len(s) ) {
    944944                if ( test(mask, s[i]) ) return i;
    945945        }
    946         return size(s);
     946        return len(s);
    947947}
    948948
    949949int include(const string_res & s, const charclass_res & mask) {
    950         for ( i; size(s) ) {
     950        for ( i; len(s) ) {
    951951                if ( ! test(mask, s[i]) ) return i;
    952952        }
    953         return size(s);
     953        return len(s);
    954954}
    955955
  • libcfa/src/collections/string_res.hfa

    rf8913b7c ree70ff5  
    1010// Created On       : Fri Sep 03 11:00:00 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Mar 14 15:44:01 2025
    13 // Update Count     : 61
     12// Last Modified On : Tue Apr  1 23:24:20 2025
     13// Update Count     : 62
    1414//
    1515
     
    7070
    7171// Getters
    72 size_t size(const string_res & s);
     72size_t len(const string_res & s);
    7373
    7474// Constructors, Assignment Operators, Destructor
     
    8989void ?{}(string_res & s, const string_res & src, StrResInitMode, size_t start, size_t len );
    9090static 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));
    9292}
    9393static 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) );
    9595}
    9696void ?{}( string_res & s, ssize_t rhs );
Note: See TracChangeset for help on using the changeset viewer.