Changeset baa1d5d for libcfa


Ignore:
Timestamp:
Jan 27, 2024, 11:29:57 PM (3 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
63e129c
Parents:
765ee42
Message:

update testing for manipulators

Location:
libcfa/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/iostream.cfa

    r765ee42 rbaa1d5d  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jan 25 08:39:31 2024
    13 // Update Count     : 1901
     12// Last Modified On : Sat Jan 27 18:02:40 2024
     13// Update Count     : 1909
    1414//
    1515
     
    10021002                        return is | *(_Istream_Cstr *)&f;
    10031003                } // fini
    1004                 if ( ! flags.ignore && args == 0 ) s[0] = '\0'; // read failed => no pattern match => set string to null
     1004                // read failed => no pattern match => set string to null
     1005                if ( ! flags.ignore && s != 0p && args == 0 ) s[0] = '\0';
    10051006                if ( args == 1 && eof( is ) ) {                                 // data but scan ended at EOF
    10061007                        clear( is );                                                            // => reset EOF => detect again on next read
     
    10551056                        if ( flags.delimiter ) {                                        // getline
    10561057                                int len = 0;                                                    // may not be set in fmt
    1057                                 sprintf( &fmtstr[pos], "[^%c]%%n", delimiters[0] );
     1058                                if ( delimiters[2] != '\0' ) {                  // read single character ?
     1059                                        sprintf( &fmtstr[pos], "c%%n" );
     1060                                } else {
     1061                                        sprintf( &fmtstr[pos], "[^%c]%%n", delimiters[0] );
     1062                                } // if
    10581063                                if ( flags.ignore ) args = fmt( is, fmtstr, &len ); // no string argument for '*'
    10591064                                else args = fmt( is, fmtstr, s, &len );
     
    10971102        } // ?|?
    10981103
    1099         istype & ?|?( istype & is, _Istream_Char f ) with(f) {
    1100                 if ( ignore ) {
    1101                         fmt( is, "%*c" );                                                       // argument variable unused
    1102                 } else {
    1103                         int len = -1, args = fmt( is, fmt, &c, &len );
    1104                         if ( args != -1 && len == -1 ) throwResume ExceptionInst( missing_data );
    1105                 } // if
    1106                 return is;
    1107         } // ?|?
     1104        // istype & ?|?( istype & is, _Istream_Char f ) with(f) {
     1105        //      if ( ignore ) {
     1106        //              fmt( is, "%*c" );                                                       // argument variable unused
     1107        //      } else {
     1108        //              int len = -1, args = fmt( is, fmt, &c, &len );
     1109        //              if ( args != -1 && len == -1 ) throwResume ExceptionInst( missing_data );
     1110        //      } // if
     1111        //      return is;
     1112        // } // ?|?
    11081113} // distribution
    11091114
     
    11241129} // distribution
    11251130
     1131INPUT_FMT_IMPL( char, "c" )
    11261132INPUT_FMT_IMPL( signed char, "hhi" )
    11271133INPUT_FMT_IMPL( unsigned char, "hhi" )
  • libcfa/src/iostream.hfa

    r765ee42 rbaa1d5d  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jan 25 08:39:04 2024
    13 // Update Count     : 696
     12// Last Modified On : Sat Jan 27 17:55:22 2024
     13// Update Count     : 732
    1414//
    1515
     
    366366        istype & nlOn( istype & );
    367367        istype & nlOff( istype & );
    368         istype & quoted( istype &, char & c );
    369368} // distribution
    370369
     
    398397                        unsigned char ignore:1;                                         // do not change input argument
    399398                        unsigned char inex:1;                                           // include/exclude characters in scanset
    400                         unsigned char delimiter:1;                                      // delimit character
     399                        unsigned char delimiter:1;                                      // delimit character(s)
    401400                        unsigned char rwd:1;                                            // read width
    402401                } flags;
     
    429428                return (_Istream_Cwidth)@{ .s : s, { {.scanset : 0p}, .wd : rwd, {.flags.rwd : true} } };
    430429        }
     430        _Istream_Cquoted quoted( char & ch, const char Ldelimiter = '\'', const char Rdelimiter = '\0' ) {
     431                return (_Istream_Cquoted)@{ { .s : &ch, { {.delimiters : { Ldelimiter, Rdelimiter, '\1' }}, .wd : 1, {.flags.rwd : true} } } };
     432        }
    431433        _Istream_Cquoted & quoted( _Istream_Cwidth & f, const char Ldelimiter = '"', const char Rdelimiter = '\0' ) {
    432434                f.delimiters[0] = Ldelimiter;  f.delimiters[1] = Rdelimiter;  f.delimiters[2] = '\0';
     
    438440        _Istream_Cstr & incl( const char scanset[], _Istream_Cwidth & f ) { f.scanset = scanset; f.flags.inex = false; return (_Istream_Cstr &)f; }
    439441        _Istream_Cstr & excl( const char scanset[], _Istream_Cwidth & f ) { f.scanset = scanset; f.flags.inex = true; return (_Istream_Cstr &)f; }
    440         _Istream_Cstr ignore( char s[] ) { return (_Istream_Cwidth)@{ .s : s, { {.scanset : 0p}, .wd : -1, {.flags.ignore : true} } }; }
     442        _Istream_Cstr ignore( const char s[] ) { return (_Istream_Cwidth)@{ .s : (char *)s, { {.scanset : 0p}, .wd : -1, {.flags.ignore : true} } }; }
    441443        _Istream_Cstr & ignore( _Istream_Cwidth & f ) { f.flags.ignore = true; return (_Istream_Cstr &)f; }
    442444        _Istream_Cquoted & ignore( _Istream_Cquoted & f ) { f.cstr.flags.ignore = true; return (_Istream_Cquoted &)f; }
     
    453455} // distribution
    454456
    455 struct _Istream_Char {
    456         char & c;
    457         bool ignore;                                                                            // do not change input argument
    458         char fmt[7];                                                                            // \L%c\R%n\0
    459 }; // _Istream_Char
    460 
    461 static inline {
    462         _Istream_Char quoted( char & c, const char Ldelimiter = '\'', const char Rdelimiter = '\0' ) {
    463                 return (_Istream_Char)@{ .c : c, .ignore : false,
    464                                 fmt : { Ldelimiter, '%', 'c', (Rdelimiter == '\0' ? Ldelimiter : Rdelimiter), '%', 'n', '\0' } };
    465         }
    466         _Istream_Char ignore( char ) {
    467                 return (_Istream_Char)@{ .c : *0p, .ignore : true };
    468         }
    469         _Istream_Char & ignore( _Istream_Char & fmt ) { fmt.ignore = true; return fmt; }
    470 } // distribution
    471 
    472 forall( istype & | basic_istream( istype ) ) {
    473         istype & ?|?( istype & is, _Istream_Char f );
    474 }
     457// struct _Istream_Char {
     458//      char & c;
     459//      bool ignore;                                                                            // do not change input argument
     460//      char fmt[7];                                                                            // \L%c\R%n\0
     461// }; // _Istream_Char
     462
     463// static inline {
     464//      _Istream_Char quoted( char & c, const char Ldelimiter = '\'', const char Rdelimiter = '\0' ) {
     465//              return (_Istream_Char)@{ .c : c, .ignore : false,
     466//                              fmt : { Ldelimiter, '%', 'c', (Rdelimiter == '\0' ? Ldelimiter : Rdelimiter), '%', 'n', '\0' } };
     467//      }
     468//      _Istream_Char ignore( char ) {
     469//              return (_Istream_Char)@{ .c : *0p, .ignore : true };
     470//      }
     471//      _Istream_Char & ignore( _Istream_Char & fmt ) { fmt.ignore = true; return fmt; }
     472// } // distribution
     473
     474// forall( istype & | basic_istream( istype ) ) {
     475//      istype & ?|?( istype & is, _Istream_Char f );
     476// }
    475477
    476478forall( T & | sized( T ) )
     
    483485#define INPUT_FMT_DECL( T ) \
    484486static inline { \
     487        _Istream_Manip(T) wdi( unsigned int wd, T & val ) { return (_Istream_Manip(T))@{ .val : val, .wd : wd, .ignore : false }; } \
    485488        _Istream_Manip(T) ignore( const T & val ) { return (_Istream_Manip(T))@{ .val : (T &)val, .wd : -1, .ignore : true }; } \
    486489        _Istream_Manip(T) & ignore( _Istream_Manip(T) & fmt ) { fmt.ignore = true; return fmt; } \
    487         _Istream_Manip(T) wdi( unsigned int wd, T & val ) { return (_Istream_Manip(T))@{ .val : val, .wd : wd, .ignore : false }; } \
    488         _Istream_Manip(T) & wdi( unsigned int wd, _Istream_Manip(T) & fmt ) { fmt.wd = wd; return fmt; } \
    489490} /* distribution */ \
    490491forall( istype & | basic_istream( istype ) ) { \
     
    492493} // ?|?
    493494
     495INPUT_FMT_DECL( char )
    494496INPUT_FMT_DECL( signed char )
    495497INPUT_FMT_DECL( unsigned char )
Note: See TracChangeset for help on using the changeset viewer.