Ignore:
Timestamp:
Aug 5, 2024, 11:13:27 PM (3 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
1c957a11, c4d6c90
Parents:
0e6cf54c
Message:

formatting, add str conversion routines, add more combinations of ?+? routines

File:
1 edited

Legend:

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

    r0e6cf54c r4dab7e8  
    1010// Created On       : Fri Sep 03 11:00:00 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Feb  6 20:59:18 2024
    13 // Update Count     : 118
     12// Last Modified On : Mon Aug  5 23:06:14 2024
     13// Update Count     : 128
    1414//
    1515
     
    2828
    2929// Getters
    30 size_t size(const string & s);
    31 static inline size_t strlen(const string & s) { return size( s ); }
     30size_t size( const string & s );
     31static inline size_t strlen( const string & s ) { return size( s ); }
    3232
    3333// RAII, assignment
    34 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
     34void ?{}( string & s ); // empty string
     35void ?{}( string & s, const string & s2 );
     36void ?{}( string & s, const string & s2, size_t maxlen );
     37void ?{}( string & s, string & s2 );
     38
     39void ?{}( string & s, char );
     40void ?{}( string & s, const char * c );                                 // copy from string literal (NULL-terminated)
     41void ?{}( string & s, const char * c, size_t size );    // copy specific length from buffer
    4242
    4343void ?{}( string & s, ssize_t rhs );
     
    4848void ?{}( string & s, long double _Complex rhs );
    4949
    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; }
     50string str( ssize_t rhs );
     51string str( size_t rhs );
     52string str( double rhs );
     53string str( long double rhs );
     54string str( double _Complex rhs );
     55string str( long double _Complex rhs );
     56
     57string & ?=?( string & s, const string & c );
     58string & ?=?( string & s, string & c );
     59string & ?=?( string & s, const char * c );                             // copy from "literal"
     60string & ?=?( string & s, char c );                                             // copy from 'l'
     61string & assign( string & s, const string & c, size_t n );
     62string & assign( string & s, const char * c, size_t n );
     63
     64static inline string & strcpy( string & s, const char * c ) { s = c; return s; }
     65static inline string & strncpy( string & s, const char * c, size_t n ) { assign( s, c, n ); return s; }
     66static inline string & strcpy( string & s, const string & c ) { s = c; return s; }
     67static inline string & strncpy( string & s, const string & c, size_t n ) { assign( s, c, n ); return s; }
    6168
    6269string & ?=?( string & s, ssize_t rhs );
     
    6774string & ?=?( string & s, long double _Complex rhs );
    6875
    69 void ^?{}(string & s);
     76void ^?{}( string & s );
    7077
    7178// Alternate construction: request shared edits
     
    7784
    7885// IO Operator
    79 ofstream & ?|?(ofstream & out, const string & s);
    80 void ?|?(ofstream & out, const string & s);
    81 ifstream & ?|?(ifstream & in, string & s);
     86ofstream & ?|?( ofstream & out, const string & s );
     87void ?|?( ofstream & out, const string & s );
     88ifstream & ?|?( ifstream & in, string & s );
    8289
    8390static inline {
     
    145152
    146153// 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; }
     154void ?+=?( string & s, char c );                                                // append a character
     155void ?+=?( string & s, const string & s2 );                             // append-concatenate to first string
     156void append( string & s, const string & s2, size_t maxlen );  // append-concatenate to first string, up to maxlen
     157void ?+=?( string & s, const char * s2 );                               // append-concatenate NULL-terminated string to first string
     158void append( string & s, const char * buffer, size_t bsize ); // append-concatenate given range to first string
     159
     160string ?+?( const string & s, char c );                                 // add a character to a copy of the string
     161string ?+?( char c, const string & s );                                 // add a character to a copy of the string
     162string ?+?( const string & s, const string & s2 );              // copy and concatenate both strings
     163string ?+?( const char * s, char c );                                   // copy and concatenate both strings
     164string ?+?( char c, const char * s );                                   // copy and concatenate both strings
     165string ?+?( const char * s1, const char * s2 );                 // copy and concatenate both strings
     166string ?+?( const char * s1, string & s2 );                             // copy and concatenate both strings
     167string ?+?( const string & s, const char * c );                 // copy and concatenate with NULL-terminated string
     168
     169static inline string & strcat( string & s, const string & s2 ) { s += s2; return s; }
     170static inline string & strcat( string & s, const char * c ) { s += c; return s; }
     171static inline string & strncat( string & s, const string & s2, size_t maxlen ) { append( s, s2, maxlen ); return s; }
     172static inline string & strncat( string & s, const char * buffer, size_t bsize ) { append( s, buffer, bsize ); return s; }
    162173
    163174// 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);
     175string ?*?( const string & s, size_t factor );
     176void ?*=?( string & s, size_t factor );
     177string ?*?( char c, size_t factor );
     178string ?*?( const char *s, size_t factor );
    168179
    169180// Character access
    170 char ?[?](const string & s, size_t index);
    171 string ?[?](string & s, size_t index);  // mutable length-1 slice of original
    172 //char codePointAt(const string & s, size_t index);  // to revisit under Unicode
     181char ?[?]( const string & s, size_t index );
     182string ?[?]( string & s, size_t index );                                // mutable length-1 slice of original
     183//char codePointAt(const string & s, size_t index );            // to revisit under Unicode
    173184
    174185// 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 &);
     186int strcmp ( const string &, const string &);
     187bool ?==?( const string &, const string &);
     188bool ?!=?( const string &, const string &);
     189bool ?>? ( const string &, const string &);
     190bool ?>=?( const string &, const string &);
     191bool ?<=?( const string &, const string &);
     192bool ?<? ( const string &, const string &);
     193
     194int strcmp( const string &, const char *);
     195bool ?==?( const string &, const char *);
     196bool ?!=?( const string &, const char *);
     197bool ?>? ( const string &, const char *);
     198bool ?>=?( const string &, const char *);
     199bool ?<=?( const string &, const char *);
     200bool ?<? ( const string &, const char *);
     201
     202int strcmp( const char *, const string &);
     203bool ?==?( const char *, const string &);
     204bool ?!=?( const char *, const string &);
     205bool ?>? ( const char *, const string &);
     206bool ?>=?( const char *, const string &);
     207bool ?<=?( const char *, const string &);
     208bool ?<? ( const char *, const string &);
    198209
    199210
    200211// Slicing
    201 string ?()( string & s, size_t start, size_t len );  // TODO const?
    202 string ?()( string & s, size_t start);
     212string ?()( string & s, size_t start, size_t len );             // TODO const?
     213string ?()( string & s, size_t start );
    203214
    204215// String search
    205 bool contains(const string & s, char ch); // single character
    206 
    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);
     216bool contains( const string & s, char ch );                             // single character
     217
     218int find( const string & s, char search );
     219int find( const string & s, const string & search );
     220int find( const string & s, const char * search );
     221int find( const string & s, const char * search, size_t searchsize );
     222
     223int findFrom( const string & s, size_t fromPos, char search );
     224int findFrom( const string & s, size_t fromPos, const string & search );
     225int findFrom( const string & s, size_t fromPos, const char * search );
     226int findFrom( const string & s, size_t fromPos, const char * search, size_t searchsize );
     227
     228bool includes( const string & s, const string & search );
     229bool includes( const string & s, const char * search );
     230bool includes( const string & s, const char * search, size_t searchsize );
     231
     232bool startsWith( const string & s, const string & prefix );
     233bool startsWith( const string & s, const char * prefix );
     234bool startsWith( const string & s, const char * prefix, size_t prefixsize );
     235
     236bool endsWith( const string & s, const string & suffix );
     237bool endsWith( const string & s, const char * suffix );
     238bool endsWith( const string & s, const char * suffix, size_t suffixsize );
    228239
    229240// 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);
     241void padStart( string & s, size_t n );
     242void padStart( string & s, size_t n, char padding );
     243void padEnd( string & s, size_t n );
     244void padEnd( string & s, size_t n, char padding );
    234245
    235246
     
    239250
    240251void ?{}( charclass & ) = void;
    241 void ?{}( charclass &, charclass) = void;
    242 charclass ?=?( charclass &, charclass) = void;
    243 
    244 void ?{}( charclass &, const string & chars);
     252void ?{}( charclass &, charclass ) = void;
     253charclass ?=?( charclass &, charclass ) = void;
     254
     255void ?{}( charclass &, const string & chars );
    245256void ?{}( charclass &, const char * chars );
    246257void ?{}( charclass &, const char * chars, size_t charssize );
    247258void ^?{}( charclass & );
    248259
    249 int include(const string & s, const charclass & mask);
    250 
    251 int exclude(const string & s, const charclass & mask);
     260int include( const string & s, const charclass & mask );
     261
     262int exclude( const string & s, const charclass & mask );
    252263
    253264/*
    254265What to do with?
    255 StrRet include(string & s, const charclass & mask);
    256 StrRet exclude(string & s, const charclass & mask);
     266StrRet include( string & s, const charclass & mask );
     267StrRet exclude( string & s, const charclass & mask );
    257268*/
Note: See TracChangeset for help on using the changeset viewer.