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

Implement full set of relational operators for strings

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.