Changeset 416b443 for libcfa


Ignore:
Timestamp:
Sep 7, 2023, 1:02:54 AM (8 months ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
master
Children:
154672d
Parents:
01510fe
Message:

Implement full set of relational operators for strings

Location:
libcfa/src/collections
Files:
4 edited

Legend:

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

    r01510fe r416b443  
    157157// Comparison
    158158
    159 bool ?==?(const string & s, const string & other) {
    160     return *s.inner == *other.inner;
    161 }
    162 
    163 bool ?!=?(const string & s, const string & other) {
    164     return *s.inner != *other.inner;
    165 }
    166 
    167 bool ?==?(const string & s, const char * other) {
    168     return *s.inner == other;
    169 }
    170 
    171 bool ?!=?(const string & s, const char * other) {
    172     return *s.inner != other;
    173 }
     159int  cmp (const string &s1, const string &s2) { return cmp(*s1.inner ,  *s2.inner); }
     160bool ?==?(const string &s1, const string &s2) { return     *s1.inner == *s2.inner ; }
     161bool ?!=?(const string &s1, const string &s2) { return     *s1.inner != *s2.inner ; }
     162bool ?>? (const string &s1, const string &s2) { return     *s1.inner >  *s2.inner ; }
     163bool ?>=?(const string &s1, const string &s2) { return     *s1.inner >= *s2.inner ; }
     164bool ?<=?(const string &s1, const string &s2) { return     *s1.inner <= *s2.inner ; }
     165bool ?<? (const string &s1, const string &s2) { return     *s1.inner <  *s2.inner ; }
     166
     167int  cmp (const string &s1, const char*   s2) { return cmp(*s1.inner ,   s2      ); }
     168bool ?==?(const string &s1, const char*   s2) { return     *s1.inner ==  s2       ; }
     169bool ?!=?(const string &s1, const char*   s2) { return     *s1.inner !=  s2       ; }
     170bool ?>? (const string &s1, const char*   s2) { return     *s1.inner >   s2       ; }
     171bool ?>=?(const string &s1, const char*   s2) { return     *s1.inner >=  s2       ; }
     172bool ?<=?(const string &s1, const char*   s2) { return     *s1.inner <=  s2       ; }
     173bool ?<? (const string &s1, const char*   s2) { return     *s1.inner <   s2       ; }
     174
     175int  cmp (const char*   s1, const string &s2) { return cmp( s1       ,  *s2.inner); }
     176bool ?==?(const char*   s1, const string &s2) { return      s1       == *s2.inner ; }
     177bool ?!=?(const char*   s1, const string &s2) { return      s1       != *s2.inner ; }
     178bool ?>? (const char*   s1, const string &s2) { return      s1       >  *s2.inner ; }
     179bool ?>=?(const char*   s1, const string &s2) { return      s1       >= *s2.inner ; }
     180bool ?<=?(const char*   s1, const string &s2) { return      s1       <= *s2.inner ; }
     181bool ?<? (const char*   s1, const string &s2) { return      s1       <  *s2.inner ; }
     182
    174183
    175184////////////////////////////////////////////////////////
  • libcfa/src/collections/string.hfa

    r01510fe r416b443  
    116116
    117117// Comparisons
    118 bool ?==?(const string & s, const string & other);
    119 bool ?!=?(const string & s, const string & other);
    120 bool ?==?(const string & s, const char * other);
    121 bool ?!=?(const string & s, const char * other);
     118int  cmp (const string &, const string &);
     119bool ?==?(const string &, const string &);
     120bool ?!=?(const string &, const string &);
     121bool ?>? (const string &, const string &);
     122bool ?>=?(const string &, const string &);
     123bool ?<=?(const string &, const string &);
     124bool ?<? (const string &, const string &);
     125
     126int  cmp (const string &, const char*);
     127bool ?==?(const string &, const char*);
     128bool ?!=?(const string &, const char*);
     129bool ?>? (const string &, const char*);
     130bool ?>=?(const string &, const char*);
     131bool ?<=?(const string &, const char*);
     132bool ?<? (const string &, const char*);
     133
     134int  cmp (const char*, const string &);
     135bool ?==?(const char*, const string &);
     136bool ?!=?(const char*, const string &);
     137bool ?>? (const char*, const string &);
     138bool ?>=?(const char*, const string &);
     139bool ?<=?(const char*, const string &);
     140bool ?<? (const char*, const string &);
     141
    122142
    123143// Slicing
  • libcfa/src/collections/string_res.cfa

    r01510fe r416b443  
    637637// Comparisons
    638638
    639 
    640 bool ?==?(const string_res &s1, const string_res &s2) {
    641     return ByteCmp( s1.Handle.s, 0, s1.Handle.lnth, s2.Handle.s, 0, s2.Handle.lnth) == 0;
    642 }
    643 
    644 bool ?!=?(const string_res &s1, const string_res &s2) {
    645     return !(s1 == s2);
    646 }
    647 bool ?==?(const string_res &s, const char* other) {
    648     string_res sother = other;
    649     return s == sother;
    650 }
    651 bool ?!=?(const string_res &s, const char* other) {
    652     return !(s == other);
    653 }
     639int cmp(const string_res &s1, const string_res &s2) {
     640    // return 0;
     641    int ans1 = memcmp(s1.Handle.s, s2.Handle.s, min(s1.Handle.lnth, s2.Handle.lnth));
     642    if (ans1 != 0) return ans1;
     643    return s1.Handle.lnth - s2.Handle.lnth;
     644}
     645
     646bool ?==?(const string_res &s1, const string_res &s2) { return cmp(s1, s2) == 0; }
     647bool ?!=?(const string_res &s1, const string_res &s2) { return cmp(s1, s2) != 0; }
     648bool ?>? (const string_res &s1, const string_res &s2) { return cmp(s1, s2) >  0; }
     649bool ?>=?(const string_res &s1, const string_res &s2) { return cmp(s1, s2) >= 0; }
     650bool ?<=?(const string_res &s1, const string_res &s2) { return cmp(s1, s2) <= 0; }
     651bool ?<? (const string_res &s1, const string_res &s2) { return cmp(s1, s2) <  0; }
     652
     653int cmp (const string_res &s1, const char* s2) {
     654    string_res s2x = s2;
     655    return cmp(s1, s2x);
     656}
     657
     658bool ?==?(const string_res &s1, const char* s2) { return cmp(s1, s2) == 0; }
     659bool ?!=?(const string_res &s1, const char* s2) { return cmp(s1, s2) != 0; }
     660bool ?>? (const string_res &s1, const char* s2) { return cmp(s1, s2) >  0; }
     661bool ?>=?(const string_res &s1, const char* s2) { return cmp(s1, s2) >= 0; }
     662bool ?<=?(const string_res &s1, const char* s2) { return cmp(s1, s2) <= 0; }
     663bool ?<? (const string_res &s1, const char* s2) { return cmp(s1, s2) <  0; }
     664
     665int cmp (const char* s1, const string_res & s2) {
     666    string_res s1x = s1;
     667    return cmp(s1x, s2);
     668}
     669
     670bool ?==?(const char* s1, const string_res &s2) { return cmp(s1, s2) == 0; }
     671bool ?!=?(const char* s1, const string_res &s2) { return cmp(s1, s2) != 0; }
     672bool ?>? (const char* s1, const string_res &s2) { return cmp(s1, s2) >  0; }
     673bool ?>=?(const char* s1, const string_res &s2) { return cmp(s1, s2) >= 0; }
     674bool ?<=?(const char* s1, const string_res &s2) { return cmp(s1, s2) <= 0; }
     675bool ?<? (const char* s1, const string_res &s2) { return cmp(s1, s2) <  0; }
     676
    654677
    655678
  • libcfa/src/collections/string_res.hfa

    r01510fe r416b443  
    142142
    143143// Comparisons
    144 bool ?==?(const string_res &s, const string_res &other);
    145 bool ?!=?(const string_res &s, const string_res &other);
    146 bool ?==?(const string_res &s, const char* other);
    147 bool ?!=?(const string_res &s, const char* other);
     144int  cmp (const string_res &, const string_res &);
     145bool ?==?(const string_res &, const string_res &);
     146bool ?!=?(const string_res &, const string_res &);
     147bool ?>? (const string_res &, const string_res &);
     148bool ?>=?(const string_res &, const string_res &);
     149bool ?<=?(const string_res &, const string_res &);
     150bool ?<? (const string_res &, const string_res &);
     151
     152int  cmp (const string_res &, const char*);
     153bool ?==?(const string_res &, const char*);
     154bool ?!=?(const string_res &, const char*);
     155bool ?>? (const string_res &, const char*);
     156bool ?>=?(const string_res &, const char*);
     157bool ?<=?(const string_res &, const char*);
     158bool ?<? (const string_res &, const char*);
     159
     160int  cmp (const char*, const string_res &);
     161bool ?==?(const char*, const string_res &);
     162bool ?!=?(const char*, const string_res &);
     163bool ?>? (const char*, const string_res &);
     164bool ?>=?(const char*, const string_res &);
     165bool ?<=?(const char*, const string_res &);
     166bool ?<? (const char*, const string_res &);
    148167
    149168// String search
Note: See TracChangeset for help on using the changeset viewer.