Ignore:
Timestamp:
Aug 31, 2023, 11:31:15 PM (2 years ago)
Author:
JiadaL <j82liang@…>
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.
Message:

Resolve conflict

File:
1 moved

Legend:

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

    r92355883 r2a301ff  
    99// Author           : Michael L. Brooks
    1010// Created On       : Fri Sep 03 11:00:00 2021
    11 // Last Modified By : Michael L. Brooks
    12 // Last Modified On : Fri Sep 03 11:00:00 2021
    13 // 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
    1414//
    1515
     
    5555}
    5656
    57 void ?{}( string & this, const char* buffer, size_t bsize) {
     57void ?{}( string & this, const char * buffer, size_t bsize) {
    5858    (this.inner) { malloc() };
    5959    ?{}( *this.inner, buffer, bsize );
     
    100100
    101101////////////////////////////////////////////////////////
    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
     104ofstream & ?|?( ofstream & out, const string & this ) {
     105    return out | (*this.inner); // print internal string_res
     106}
     107
     108void ?|?( ofstream & out, const string & this ) {
     109    (ofstream &)(out | (*this.inner)); ends( out );
     110}
     111
     112ifstream & ?|?(ifstream & in, string & this) {
     113    return in | (*this.inner); // read to internal string_res
     114}
     115
     116void ?|?( ifstream & in, string & this ) {
     117    (ifstream &)(in | this); ends( in );
     118}
     119
     120ifstream & ?|?( 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
     160void ?|?( ifstream & in, _Istream_str f ) {
     161    (ifstream &)(in | f); ends( in );
    110162}
    111163
     
    118170}
    119171
     172string ?()( string & this, size_t start ) {
     173    string ret = { *this.inner, start, size( this ) };
     174    return ret`shareEdits;
     175}
     176
    120177////////////////////////////////////////////////////////
    121178// Comparison
    122179
    123 bool ?==?(const string &s, const string &other) {
     180bool ?==?(const string & s, const string & other) {
    124181    return *s.inner == *other.inner;
    125182}
    126183
    127 bool ?!=?(const string &s, const string &other) {
     184bool ?!=?(const string & s, const string & other) {
    128185    return *s.inner != *other.inner;
    129186}
    130187
    131 bool ?==?(const string &s, const char* other) {
     188bool ?==?(const string & s, const char * other) {
    132189    return *s.inner == other;
    133190}
    134191
    135 bool ?!=?(const string &s, const char* other) {
     192bool ?!=?(const string & s, const char * other) {
    136193    return *s.inner != other;
    137194}
     
    140197// Getter
    141198
    142 size_t size(const string &s) {
     199size_t size(const string & s) {
    143200    return size( * s.inner );
    144201}
     
    147204// Concatenation
    148205
    149 void ?+=?(string &s, char other) {
     206void ?+=?(string & s, char other) {
    150207    (*s.inner) += other;
    151208}
    152209
    153 void ?+=?(string &s, const string &s2) {
     210void ?+=?(string & s, const string & s2) {
    154211    (*s.inner) += (*s2.inner);
    155212}
    156213
    157 void ?+=?(string &s, const char* other) {
     214void ?+=?(string & s, const char * other) {
    158215    (*s.inner) += other;
    159216}
    160217
    161 string ?+?(const string &s, char other) {
     218string ?+?(const string & s, char other) {
    162219    string ret = s;
    163220    ret += other;
     
    165222}
    166223
    167 string ?+?(const string &s, const string &s2) {
     224string ?+?(const string & s, const string & s2) {
    168225    string ret = s;
    169226    ret += s2;
     
    171228}
    172229
    173 string ?+?(const char* s1, const char* s2) {
     230string ?+?(const char * s1, const char * s2) {
    174231    string ret = s1;
    175232    ret += s2;
     
    177234}
    178235
    179 string ?+?(const string &s, const char* other) {
     236string ?+?(const string & s, const char * other) {
    180237    string ret = s;
    181238    ret += other;
     
    186243// Repetition
    187244
    188 string ?*?(const string &s, size_t factor) {
     245string ?*?(const string & s, size_t factor) {
    189246    string ret = "";
    190247    for (factor) ret += s;
     
    206263// Character access
    207264
    208 char ?[?](const string &s, size_t index) {
     265char ?[?](const string & s, size_t index) {
    209266    return (*s.inner)[index];
    210267}
    211268
    212 string ?[?](string &s, size_t index) {
     269string ?[?](string & s, size_t index) {
    213270    string ret = { *s.inner, index, index + 1 };
    214271    return ret`shareEdits;
     
    218275// Search
    219276
    220 bool contains(const string &s, char ch) {
     277bool contains(const string & s, char ch) {
    221278    return contains( *s.inner, ch );
    222279}
    223280
    224 int find(const string &s, char search) {
     281int find(const string & s, char search) {
    225282    return find( *s.inner, search );
    226283}
    227284
    228 int find(const string &s, const string &search) {
     285int find(const string & s, const string & search) {
    229286    return find( *s.inner, *search.inner );
    230287}
    231288
    232 int find(const string &s, const char* search) {
     289int find(const string & s, const char * search) {
    233290    return find( *s.inner, search);
    234291}
    235292
    236 int find(const string &s, const char* search, size_t searchsize) {
     293int find(const string & s, const char * search, size_t searchsize) {
    237294    return find( *s.inner, search, searchsize);
    238295}
    239296
    240 int findFrom(const string &s, size_t fromPos, char search) {
     297int findFrom(const string & s, size_t fromPos, char search) {
    241298    return findFrom( *s.inner, fromPos, search );
    242299}
    243300
    244 int findFrom(const string &s, size_t fromPos, const string &search) {
     301int findFrom(const string & s, size_t fromPos, const string & search) {
    245302    return findFrom( *s.inner, fromPos, *search.inner );
    246303}
    247304
    248 int findFrom(const string &s, size_t fromPos, const char* search) {
     305int findFrom(const string & s, size_t fromPos, const char * search) {
    249306    return findFrom( *s.inner, fromPos, search );
    250307}
    251308
    252 int findFrom(const string &s, size_t fromPos, const char* search, size_t searchsize) {
     309int findFrom(const string & s, size_t fromPos, const char * search, size_t searchsize) {
    253310    return findFrom( *s.inner, fromPos, search, searchsize );
    254311}
    255312
    256 bool includes(const string &s, const string &search) {
     313bool includes(const string & s, const string & search) {
    257314    return includes( *s.inner, *search.inner );
    258315}
    259316
    260 bool includes(const string &s, const char* search) {
     317bool includes(const string & s, const char * search) {
    261318    return includes( *s.inner, search );
    262319}
    263320
    264 bool includes(const string &s, const char* search, size_t searchsize) {
     321bool includes(const string & s, const char * search, size_t searchsize) {
    265322    return includes( *s.inner, search, searchsize );
    266323}
    267324
    268 bool startsWith(const string &s, const string &prefix) {
     325bool startsWith(const string & s, const string & prefix) {
    269326    return startsWith( *s.inner, *prefix.inner );
    270327}
    271328
    272 bool startsWith(const string &s, const char* prefix) {
     329bool startsWith(const string & s, const char * prefix) {
    273330    return startsWith( *s.inner, prefix );
    274331}
    275332
    276 bool startsWith(const string &s, const char* prefix, size_t prefixsize) {
     333bool startsWith(const string & s, const char * prefix, size_t prefixsize) {
    277334    return startsWith( *s.inner, prefix, prefixsize );
    278335}
    279336
    280 bool endsWith(const string &s, const string &suffix) {
     337bool endsWith(const string & s, const string & suffix) {
    281338    return endsWith( *s.inner, *suffix.inner );
    282339}
    283340
    284 bool endsWith(const string &s, const char* suffix) {
     341bool endsWith(const string & s, const char * suffix) {
    285342    return endsWith( *s.inner, suffix );
    286343}
    287344
    288 bool endsWith(const string &s, const char* suffix, size_t suffixsize) {
     345bool endsWith(const string & s, const char * suffix, size_t suffixsize) {
    289346    return endsWith( *s.inner, suffix, suffixsize );
    290347}
     
    316373
    317374
    318 int exclude(const string &s, const charclass &mask) {
     375int exclude(const string & s, const charclass & mask) {
    319376    return exclude( *s.inner, *mask.inner );
    320377}
    321378/*
    322 StrSlice exclude(string &s, const charclass &mask) {
     379StrSlice exclude(string & s, const charclass & mask) {
    323380}
    324381*/
    325382
    326 int include(const string &s, const charclass &mask) {
     383int include(const string & s, const charclass & mask) {
    327384    return include( *s.inner, *mask.inner );
    328385}
    329386
    330387/*
    331 StrSlice include(string &s, const charclass &mask) {
     388StrSlice include(string & s, const charclass & mask) {
    332389}
    333390*/
Note: See TracChangeset for help on using the changeset viewer.