Ignore:
Timestamp:
Oct 17, 2023, 12:12:00 PM (8 months ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
master
Children:
5e0bba5
Parents:
1b41219
Message:

Change string-read semantics so that reading nothing leaves the original value unmodified.

Logically revert #8cffa4f21, and apply the change onto work done since.

At cstring layer, libcfa change is a simplification, and test suite change is merely a different expectation.

At var-len-string layer, libcfa change is a patch to enable detecting the nothing-read case,
and test sute change (shows the different expectation but also) puts a similar patch into its "stop trying if nothing read" loop exits.

File:
1 edited

Legend:

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

    r1b41219 r37ceccb  
    236236        // get bytes
    237237        try {
     238                        *(temp.Handle.ulink->EndVbyte) = '\0';   // pre-assign empty cstring
    238239            in | wdi( lenReadable, temp.Handle.ulink->EndVbyte );
    239240        } catch (cstring_length*) {
     
    247248    }
    248249
    249     s = temp;
     250        if ( temp.Handle.lnth > 0 ) s = temp;
    250251    return in;
    251252}
     
    268269        cstr[wd] = '\0';                                                                        // guard null terminate string
    269270        try {
     271                cstr[0] = '\0';                                                                 // pre-assign as empty cstring
    270272                is | cf;
    271273        } catch( cstring_length * ) {
    272274                cont = true;
    273275        } finally {
    274         if ( ! cf.flags.ignore ) *(f.s) = cstr;                 // ok to initialize string
     276                if ( ! cf.flags.ignore &&                                               // ok to initialize string
     277                                cstr[0] != '\0' ) {                                             // something was read
     278                        *(f.s) = cstr;
     279                }
    275280        } // try
    276281        for ( ; cont; )  {                                                                      // overflow read ?
    277282                cont = false;
    278283                try {
     284                        cstr[0] = '\0';                                                         // pre-assign as empty cstring
    279285                        is | cf;
    280286                } catch( cstring_length * ) {
    281287                        cont = true;                                                            // continue not allowed
    282288                } finally {
    283                         if ( ! cf.flags.ignore ) *(f.s) += cstr;        // build string chunk at a time
     289                        if ( ! cf.flags.ignore &&
     290                                        cstr[0] != '\0' ) {                                     // something was read
     291                                *(f.s) += cstr;                                                 // build string chunk at a time
     292                        }
    284293                } // try
    285294        } // for
Note: See TracChangeset for help on using the changeset viewer.