Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/iostream.cfa

    r4aae2bd r8c13ca8  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jan  3 10:53:13 2024
    13 // Update Count     : 1898
     12// Last Modified On : Fri Nov 17 13:33:12 2023
     13// Update Count     : 1853
    1414//
    1515
     
    984984        }
    985985
    986         istype & ?|?( istype & is, _Istream_Cquoted f ) with( f ) {
     986        istype & ?|?( istype & is, _Istream_Cquoted f ) {
    987987                char fmtstr[32];                                                                // storage scanset and format codes
    988988                fmtstr[0] = '%';
     
    992992                bool check = true;
    993993
    994                 if ( cstr.flags.ignore ) { check = false; fmtstr[1] = '*'; pos += 1; }
    995                 int rwd = cstr.wd;
    996                 if ( cstr.wd != -1 ) {                                          // => just ignore versus ignore with width
     994                if ( f.flags.ignore ) { check = false; fmtstr[1] = '*'; pos += 1; }
     995                int rwd = f.wd;
     996                if ( f.wd != -1 ) {                                                             // => just ignore versus ignore with width
    997997                        // wd is buffer bytes available (for input chars + null terminator)
    998998                        // rwd is count of input chars
    999999                        // no maximum width necessary because text ignored => width is read width
    1000                         if ( cstr.flags.rwd ) check = false;
    1001                         else rwd = cstr.wd - 1;
     1000                        if ( f.flags.rwd ) check = false;
     1001                        else rwd = f.wd - 1;
    10021002                        pos += sprintf( &fmtstr[pos], "%d", rwd );
    10031003                } // if
    10041004
    10051005                int len = 0;                                                                    // may not be set in fmt
    1006                 char enddelim;
    1007                 if ( ! cstr.flags.inex ) {                                              // => quoted getline
     1006                if ( ! f.flags.inex ) {                                                 // => quoted getline
     1007                        // fprintf( stderr, "quoted\n" );
    10081008                        args = fmt( is, "%*[ \f\n\r\t\v]" );            // remove leading whitespace
    10091009                        if ( eof( is ) ) goto Eof;
    1010                         char rfmt[4] = { cstr.delimiters[0], '%', 'n', '\0' };
    1011                         args = fmt( is, rfmt, &len );                           // remove leading quote
     1010//                      args = fmt( is, (const char *)f.delimiter ); // remove leading quote
     1011                        args = fmt( is, "'%n", &len ); // remove leading quote
     1012                        fprintf( stderr, "quoted %d %d\n", args, len );
    10121013                        if ( len == 0 || eof( is ) ) goto Eof;
    10131014                } // if
    1014                 enddelim = cstr.delimiters[1] == '\0' ? cstr.delimiters[0] : cstr.delimiters[1];
    1015                 sprintf( &fmtstr[pos], "[^%c]%%n", enddelim );
    1016                 if ( cstr.flags.ignore ) args = fmt( is, fmtstr, &len ); // no string argument for '*'
    1017                 else args = fmt( is, fmtstr, cstr.s, &len );
     1015                sprintf( &fmtstr[pos], "[^%c]%%n", f.delimiter[0] );
     1016                // fprintf( stderr, "getline %s %d\n", fmtstr, f.wd );
     1017                if ( f.flags.ignore ) args = fmt( is, fmtstr, &len ); // no string argument for '*'
     1018                else args = fmt( is, fmtstr, f.s, &len );
     1019                // fprintf( stderr, "getline %s %d %d %d\n", fmtstr, args, f.wd, eof( is ) );
    10181020                if ( check && len == rwd && ! eof( is ) ) {             // might not fit
    10191021                        char peek;
    10201022                        fmt( is, "%c", &peek );                                         // check for delimiter
     1023                        // fprintf( stderr, "peek %d '%c'\n", args, peek );
    10211024                        if ( ! eof( is ) ) {
    1022                                 if ( peek != enddelim ) {
     1025                                if ( peek != f.delimiter[0] ) {
    10231026                                        ungetc( is, peek );
    10241027                                        throwResume ExceptionInst( cstring_length );
     
    10271030                } else fmt( is, "%*c" );                                                // remove delimiter
    10281031          Eof: ;
    1029                 if ( rwd > 0 && args == 0 ) cstr.s[0] = '\0';   // read failed => no pattern match => set string to null
     1032                if ( rwd > 0 && args == 0 ) f.s[0] = '\0';              // read failed => no pattern match => set string to null
    10301033                if ( args == 1 && eof( is ) ) {                                 // data but scan ended at EOF
     1034                        // fprintf( stderr, "clear\n" );
    10311035                        clear( is );                                                            // => reset EOF => detect again on next read
    10321036                } // if
     
    10341038        }
    10351039
    1036         istype & ?|?( istype & is, _Istream_Cstr f ) with( f ) {
     1040        istype & ?|?( istype & is, _Istream_Cstr f ) {
    10371041                const char * scanset;
    10381042                size_t nscanset = 0;
    1039                 if ( flags.delimiter ) scanset = delimiters;    // getline ?
     1043                if ( f.flags.delimiter ) scanset = f.delimiter; // getline ?
    10401044                else scanset = f.scanset;
    10411045                if ( scanset ) nscanset = strlen( scanset );
     
    10801084                        if ( f.flags.delimiter ) {                                      // getline
    10811085                                int len = 0;                                                    // may not be set in fmt
    1082                                 sprintf( &fmtstr[pos], "[^%c]%%n", f.delimiters[0] );
     1086                                if ( ! f.flags.inex ) {                                 // => quoted getline
     1087                                        // fprintf( stderr, "quoted\n" );
     1088                                        args = fmt( is, "%*[ \f\n\r\t\v]" ); // remove leading whitespace
     1089                                        if ( eof( is ) ) goto X;
     1090                                        args = fmt( is, "\"" );                         // remove leading quote
     1091                                        if ( eof( is ) ) goto X;
     1092                                } // if
     1093                                // fprintf( stderr, "getline\n" );
     1094                                // sprintf( &fmtstr[pos], "[%s%s]%%n", f.flags.inex ? "^" : "", scanset );
     1095                                sprintf( &fmtstr[pos], "[^%s]%%n", scanset );
     1096                                // fprintf( stderr, "getline %s %d\n", fmtstr, f.wd );
    10831097                                if ( f.flags.ignore ) args = fmt( is, fmtstr, &len ); // no string argument for '*'
    10841098                                else args = fmt( is, fmtstr, f.s, &len );
     1099                                // fprintf( stderr, "getline %s %d %d %d\n", fmtstr, args, f.wd, eof( is ) );
    10851100                                if ( check && len == rwd && ! eof( is ) ) {     // might not fit
    1086                                         fmtstr[0] = f.delimiters[0]; fmtstr[1] = '%'; fmtstr[2] = 'n'; fmtstr[3] = '\0';
    1087                                         fmt( is, fmtstr, &len );                        // remove delimiter
     1101                                        char peek;
     1102                                        fmt( is, "%c", &peek );                         // check for delimiter
     1103                                        // fprintf( stderr, "peek %d '%c'\n", args, peek );
    10881104                                        if ( ! eof( is ) ) {
    1089 //                                              if ( peek != f.delimiter[0] ) {
    1090                                                 if ( len != 1 ) {
    1091 //                                                      ungetc( is, peek );
     1105                                                if ( peek != f.delimiter[0] ) {
     1106                                                        ungetc( is, peek );
    10921107                                                        throwResume ExceptionInst( cstring_length );
    10931108                                                } // if
    10941109                                        } // if
    1095                                 } else fmt( is, "%*c" );                                // remove delimiter
     1110                                } else fmt( is, "%*c" );                        // remove delimiter
     1111                          X: ;
    10961112                        } else {
    10971113                                // incl %[xxx],  %*[xxx],  %w[xxx],  %*w[xxx]
Note: See TracChangeset for help on using the changeset viewer.