Ignore:
Timestamp:
Apr 6, 2025, 10:46:19 PM (9 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
0393fda8
Parents:
56ec508
Message:

fix substring error being outside of string, simplify comparison operations, start refactoring string search operations

File:
1 edited

Legend:

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

    r56ec508 red5023d1  
    1010// Created On       : Fri Sep 03 11:00:00 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Apr  1 23:29:58 2025
    13 // Update Count     : 91
     12// Last Modified On : Sun Apr  6 07:38:02 2025
     13// Update Count     : 111
    1414//
    1515
     
    724724}
    725725
    726 void ?+=?(string_res & str1, const string_res & str2) {
    727         append( str1, str2.Handle.s, str2.Handle.lnth );
    728 }
    729 
    730 void append(string_res & str1, const string_res & str2, size_t maxlen) {
    731         append( str1, str2.Handle.s, min(str2.Handle.lnth, maxlen) );
    732 }
    733 
    734 void ?+=?(string_res & s, char c) {
    735         append( s, & c, 1 );
    736 }
    737 void ?+=?(string_res & s, const char * c) {
    738         append( s, c, strlen(c) );
     726void append( string_res & s, const string_res & s2, size_t maxlen ) {
     727        append( s, s2.Handle.s, min( s2.Handle.lnth, maxlen ) );
    739728}
    740729
     
    751740// Comparisons
    752741
    753 int strcmp(const string_res & s1, const string_res & s2) {
    754         // return 0;
    755         int ans1 = memcmp(s1.Handle.s, s2.Handle.s, min(s1.Handle.lnth, s2.Handle.lnth));
    756         if (ans1 != 0) return ans1;
    757         return s1.Handle.lnth - s2.Handle.lnth;
    758 }
    759 
    760 bool ?==?(const string_res & s1, const string_res & s2) { return strcmp(s1, s2) == 0; }
    761 bool ?!=?(const string_res & s1, const string_res & s2) { return strcmp(s1, s2) != 0; }
    762 bool ?>? (const string_res & s1, const string_res & s2) { return strcmp(s1, s2) >  0; }
    763 bool ?>=?(const string_res & s1, const string_res & s2) { return strcmp(s1, s2) >= 0; }
    764 bool ?<=?(const string_res & s1, const string_res & s2) { return strcmp(s1, s2) <= 0; }
    765 bool ?<? (const string_res & s1, const string_res & s2) { return strcmp(s1, s2) <  0; }
    766 
    767 int strcmp (const string_res & s1, const char * s2) {
    768         string_res s2x = s2;
    769         return strcmp(s1, s2x);
    770 }
    771 
    772 bool ?==?(const string_res & s1, const char * s2) { return strcmp(s1, s2) == 0; }
    773 bool ?!=?(const string_res & s1, const char * s2) { return strcmp(s1, s2) != 0; }
    774 bool ?>? (const string_res & s1, const char * s2) { return strcmp(s1, s2) >  0; }
    775 bool ?>=?(const string_res & s1, const char * s2) { return strcmp(s1, s2) >= 0; }
    776 bool ?<=?(const string_res & s1, const char * s2) { return strcmp(s1, s2) <= 0; }
    777 bool ?<? (const string_res & s1, const char * s2) { return strcmp(s1, s2) <  0; }
    778 
    779 int strcmp (const char * s1, const string_res & s2) {
    780         string_res s1x = s1;
    781         return strcmp(s1x, s2);
    782 }
    783 
    784 bool ?==?(const char * s1, const string_res & s2) { return strcmp(s1, s2) == 0; }
    785 bool ?!=?(const char * s1, const string_res & s2) { return strcmp(s1, s2) != 0; }
    786 bool ?>? (const char * s1, const string_res & s2) { return strcmp(s1, s2) >  0; }
    787 bool ?>=?(const char * s1, const string_res & s2) { return strcmp(s1, s2) >= 0; }
    788 bool ?<=?(const char * s1, const string_res & s2) { return strcmp(s1, s2) <= 0; }
    789 bool ?<? (const char * s1, const string_res & s2) { return strcmp(s1, s2) <  0; }
    790 
     742int strcmp$( const char * s1, size_t l1, const char * s2, size_t l2 ) {
     743        int ret = memcmp( s1, s2, min( l1, l2 ) );
     744        if ( ret != 0 ) return ret;
     745        return l1 - l2;
     746}
    791747
    792748//////////////////////////////////////////////////////////
Note: See TracChangeset for help on using the changeset viewer.