Ignore:
Timestamp:
Aug 30, 2023, 11:20:14 AM (10 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
55b060d
Parents:
7e1dbd7
Message:

second attempt at input manipulators for strings

File:
1 edited

Legend:

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

    r7e1dbd7 r38de914  
    1010// Created On       : Fri Sep 03 11:00:00 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Aug 28 19:00:45 2023
    13 // Update Count     : 146
     12// Last Modified On : Tue Aug 29 18:32:34 2023
     13// Update Count     : 153
    1414//
    1515
     
    118118}
    119119
    120 static void readstr( ifstream & is, _Istream_str f, char fmtstr[], char cstr[] ) {
    121         int check = f.rwd - 1;
    122 
    123         if ( ! f.flags.rwd ) cstr[check] = '\0';                        // insert sentinel
    124         int len = fmt( is, fmtstr, cstr );
    125         // fprintf( stderr, "KK %s %zd %d %c %s\n", fmtstr, len, check, cstr[check], cstr );
    126 
    127         if ( ! f.flags.rwd && cstr[check] != '\0' )                     // sentinel overwritten ?
    128                 throw (cstring_length){ &cstring_length_vt };
    129 
    130         if ( f.flags.delimit ) {                                                        // getline ?
    131                 if ( len == 0 ) cstr[0] = '\0';                                 // empty read => argument unchanged => set empty
    132                 if ( ! eof( is ) ) fmt( is, "%*c" );                    // ignore delimiter
    133         } //if
    134 } // readstr
    135 
    136120ifstream & ?|?( ifstream & is, _Istream_str f ) {
    137121        // skip, same as for char *
    138122        if ( ! &f.s ) {
    139123                // fprintf( stderr,  "skip %s %d\n", f.scanset, f.wd );
    140                 if ( f.rwd == -1 ) fmt( is, f.scanset, "" ); // no input arguments
    141                 else for ( f.rwd ) fmt( is, "%*c" );
     124                if ( f.wd == -1 ) fmt( is, f.scanset, "" ); // no input arguments
     125                else for ( f.wd ) fmt( is, "%*c" );
    142126                return is;
    143127        } // if
    144128
    145         enum { gwd = 16 + 2, wd = gwd - 1 };                            // guarded and unguarded width
     129        enum { gwd = 128 + 2, wd = gwd - 1 };                           // guarded and unguarded width
    146130        char cstr[gwd];                                                                         // read in chunks
    147131        bool cont = false;;
    148132
    149         if ( f.rwd == -1 ) f.rwd = wd;
     133        if ( f.wd == -1 ) f.wd = wd;
    150134        const char * scanset = f.scanset;;
    151135        if ( f.flags.delimit ) scanset = f.delimit;                     // getline ?
     
    157141        fmtstr[0] = '%';
    158142        if ( f.flags.ignore ) { fmtstr[1] = '*'; start += 1; }
    159         if ( f.rwd != -1 ) { start += sprintf( &fmtstr[start], "%d", f.rwd ); }
     143        if ( f.wd != -1 ) { start += sprintf( &fmtstr[start], "%d", f.wd ); }
    160144
    161145        if ( ! scanset ) {
Note: See TracChangeset for help on using the changeset viewer.