Changeset baa1d5d


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

update testing for manipulators

Files:
4 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 )
  • tests/io/.in/manipulatorsInput.txt

    r765ee42 rbaa1d5d  
    2020X               ZC44%Y
    2121X               ZC55%Y
     22'x'
     23"x"
     24{x}
     25XxY
     26XyY
    2227abc
    2328cccccb
     
    3742X               ZC44%Y
    3843X               ZC55%Y
     44'x'
     45"x"
     46{x}
     47XxY
     48XyY
    3949ab
     50xxxyyy
    40510xff 017 15-15
    41520xff 017 15-15
  • tests/io/manipulatorsInput.cfa

    r765ee42 rbaa1d5d  
    77// Created On       : Sat Jun  8 17:58:54 2019
    88// Last Modified By : Peter A. Buhr
    9 // Last Modified On : Wed Jan 24 18:36:32 2024
    10 // Update Count     : 104
     9// Last Modified On : Sat Jan 27 18:47:42 2024
     10// Update Count     : 122
    1111//
    1212
     
    5555        }
    5656        {
    57                 char s[] = "yyyyyyyyyyyyyyyyyyyy";                                                     // Input characters consumed:
     57                char s[] = "yyyyyyyyyyyyyyyyyyyy";                                                                                                      // Input characters consumed:
    5858                const char sk_fmt[] = "%*[abc]";
    59                 scanf( "abc " ); scanf( sk_fmt ); for ( 5 ) scanf( "%*c" ); printf( "1 %s\n", s );     // |abc |\ncccccb| \nxx\n|
    60                 scanf( "%s", s );                                                               printf( "2 %s\n", s );                 // |abcxxx|
    61                 scanf( "%*s" );                                                                 printf( "3 %s\n", s );                 // |\nabcyyy|
    62                 scanf( "%8s", s );                                                              printf( "4 %s\n", s );                 // |\naaaaaaaa|
    63                 scanf( "%*8s" );                                                                printf( "5 %s\n", s );                 // |xxxxxxxx|
    64 
    65                 scanf( "%[abc]", s );                                                   printf( "6 %s\n", s );                 // |aabbccbb|
    66                 scanf( "%[^abc]", s );                                                  printf( "7 %s\n", s );                 // |dddwww|
    67                 scanf( "%*[abc]" );                                                             printf( "8 %s\n", s );                 // |bbbbbbbb|
    68                 scanf( "%*[^abc]" );                                                    printf( "9 %s\n", s );                 // |wwwwwwww|
    69                 scanf( "%8[abc]", s );                                                  printf( "10 %s\n", s );                // |aaaaaaaa|
    70                 scanf( "%8[^abc]", s );                                                 printf( "11 %s\n", s );                // |wwwwwwww|
    71                 scanf( "%*8[abc]" );                                                    printf( "12 %s\n", s );                // |aaaaaaaa|
    72                 scanf( "%*8[^abc]" );                                                   printf( "13 %s\n", s );                // |wwwwwwww|
    73                 scanf( "\n" );                                                                  // must start next line                // |\n|
     59                scanf( "abc " ); scanf( sk_fmt ); for ( 5 ) scanf( "%*c" ); printf( "1 %s\n", s );      // |abc |\ncccccb| \nxx\n|
     60                scanf( "%s", s );                                                               printf( "2 %s\n", s );                          // |abcxxx|
     61                scanf( "%*s" );                                                                 printf( "3 %s\n", s );                          // |\nabcyyy|
     62                scanf( "%8s", s );                                                              printf( "4 %s\n", s );                          // |\naaaaaaaa|
     63                scanf( "%*8s" );                                                                printf( "5 %s\n", s );                          // |xxxxxxxx|
     64
     65                scanf( "%[abc]", s );                                                   printf( "6 %s\n", s );                          // |aabbccbb|
     66                scanf( "%[^abc]", s );                                                  printf( "7 %s\n", s );                          // |dddwww|
     67                scanf( "%*[abc]" );                                                             printf( "8 %s\n", s );                          // |bbbbbbbb|
     68                scanf( "%*[^abc]" );                                                    printf( "9 %s\n", s );                          // |wwwwwwww|
     69                scanf( "%8[abc]", s );                                                  printf( "10 %s\n", s );                         // |aaaaaaaa|
     70                scanf( "%8[^abc]", s );                                                 printf( "11 %s\n", s );                         // |wwwwwwww|
     71                scanf( "%*8[abc]" );                                                    printf( "12 %s\n", s );                         // |aaaaaaaa|
     72                scanf( "%*8[^abc]" );                                                   printf( "13 %s\n", s );                         // |wwwwwwww|
     73                scanf( "\n" );                                                                  // must start next line                         // |\n|
    7474
    7575                int rc;
    7676                s[0] = 'q'; s[1] = '\0'; rc = 99;
    77                 rc = scanf( "%[abc]", s );                                              printf( "14 rc=%d, %s\n", rc, s );     // ||
     77                rc = scanf( "%[abc]", s );                                              printf( "14 rc=%d, %s\n", rc, s );      // ||
    7878                s[0] = 'q'; s[1] = '\0'; rc = 99;
    79                 rc = scanf( "%[^u]", s );                                               printf( "15 rc=%d, %s\n", rc, s );     // ||
    80                 scanf( "%*[u]\n" );                                                                    // |uuuuu\n|
    81                 scanf( "%[^\n]\n", s );                                                 printf( "16 %s\n", s );                // |get this line\n|
    82                 scanf( "%[^%%]%%\n", s );                                               printf( "17 %s\n", s );                // |@# this line 1)-{}%\n|
    83                 scanf( "%*[^%%]%%\n", s );                                              printf( "18 %s\n", s );                // |@# this line 1)-{}%\n|
    84 
    85                 scanf( "%*[ \f\n\r\t\v]" );                                             // ignore whitespace                   // ||
    86                 scanf( "\"%[^\"]\"", s );                                               printf( "19 %s\n", s );                // |"abc"|
    87                 scanf( "%*[ \f\n\r\t\v]" );                                             // ignore whitespace                   // |\n|
    88                 scanf( "'%[^']'", s );                                                  printf( "20 %s\n", s );                // |'abc  '|
    89                 scanf( "%*[ \f\n\r\t\v]" );                                             // ignore whitespace                   // |\n|
    90                 scanf( "{%[^}]}", s );                                                  printf( "21 %s\n", s );                // |{ d d\n\nd }|
    91                 scanf( "%*[ \f\n\r\t\v]" );                                             // ignore whitespace                   // |\n|
    92                 scanf( "X%[^Y]Y", s );                                                  printf( "22 %s\n", s );                // |X            ZC44%Y|
    93                 scanf( "%*[ \f\n\r\t\v]" );                                             // ignore whitespace                   // |\n|
    94                 scanf( "X%*[^Y]Y", s );                                                 printf( "23 %s\n", s );                // |X            ZC44%Y|
    95                 scanf( "\n" );                                                                  // must start next line                // |\n|
     79                rc = scanf( "%[^u]", s );                                               printf( "15 rc=%d, %s\n", rc, s );      // ||
     80                scanf( "%*[u]\n" );                                                                                                                                     // |uuuuu\n|
     81                scanf( "%[^\n]\n", s );                                                 printf( "16 %s\n", s );                         // |get this line\n|
     82                scanf( "%[^%%]%%\n", s );                                               printf( "17 %s\n", s );                         // |@# this line 1)-{}%\n|
     83                scanf( "%*[^%%]%%\n", s );                                              printf( "18 %s\n", s );                         // |@# this line 1)-{}%\n|
     84
     85                scanf( "%*[ \f\n\r\t\v]" );                                             // ignore whitespace                            // ||
     86                scanf( "\"%[^\"]\"", s );                                               printf( "19 %s\n", s );                         // |"abc"|
     87                scanf( "%*[ \f\n\r\t\v]" );                                             // ignore whitespace                            // |\n|
     88                scanf( "'%[^']'", s );                                                  printf( "20 %s\n", s );                         // |'abc  '|
     89                scanf( "%*[ \f\n\r\t\v]" );                                             // ignore whitespace                            // |\n|
     90                scanf( "{%[^}]}", s );                                                  printf( "21 %s\n", s );                         // |{ d d\n\nd }|
     91                scanf( "%*[ \f\n\r\t\v]" );                                             // ignore whitespace                            // |\n|
     92                scanf( "X%[^Y]Y", s );                                                  printf( "22 %s\n", s );                         // |X           ZC44%Y|
     93                scanf( "%*[ \f\n\r\t\v]" );                                             // ignore whitespace                            // |\n|
     94                scanf( "X%*[^Y]Y", s );                                                 printf( "23 %s\n", s );                         // |X           ZC44%Y|
     95                scanf( "\n" );                                                                  // must start next line                         // |\n|
     96
     97                char ch;
     98                scanf( "%*[ \f\n\r\t\v]" );                                             // ignore whitespace                            // |\n|
     99                scanf( "'%c'", &ch );                                                   printf( "24 %c\n", ch );                        // |x|
     100                scanf( "%*[ \f\n\r\t\v]" );                                             // ignore whitespace                            // |\n|
     101                scanf( "\"%c\"", &ch );                                                 printf( "25 %c\n", ch );                        // |x|
     102                scanf( "%*[ \f\n\r\t\v]" );                                             // ignore whitespace                            // |\n|
     103                scanf( "{%c}", &ch );                                                   printf( "26 %c\n", ch );                        // |x|
     104                scanf( "%*[ \f\n\r\t\v]" );                                             // ignore whitespace                            // |\n|
     105                scanf( "X%cY", &ch );                                                   printf( "27 %c\n", ch );                        // |x|
     106                scanf( "%*[ \f\n\r\t\v]" );                                             // ignore whitespace                            // |\n|
     107                scanf( "X%*cY", &ch );                                                  printf( "28 %c\n", ch );                        // |x|
     108                scanf( "\n" );                                                                  // must start next line                         // |\n|
    96109        }
    97110        {
     
    128141                sin | quoted( wdi( sizeof(s), s ), 'X', 'Y' );  sout | "22" | s;
    129142                sin | ignore( quoted( wdi( sizeof(s), s ), 'X', 'Y' ) ); sout | "23" | s;
    130         }
    131     // Keep harmonized with collections/string-istream-manip
     143
     144                char ch;
     145                sin | quoted( ch );                                                             sout | "24 " | ch;
     146                sin | quoted( ch, '\"' );                                               sout | "25 " | ch;
     147                sin | quoted( ch, '{', '}' );                                   sout | "26 " | ch;
     148                sin | quoted( ch, 'X', 'Y' );                                   sout | "27 " | ch;
     149                sin | ignore( quoted( ch, 'X', 'Y' ) );                 sout | "28 " | ch;
     150                sin | "\n";
     151        }
     152        // Keep harmonized with collections/string-istream-manip
    132153        {
    133154                char c;
    134155                sin | c;                                                                                sout | c;
    135156                sin | ignore( c );                                                              sout | c;
     157
     158                char ca[3] = { 'a', 'b', 'c' };
     159                sin | wdi( 4, (char &)*&ca[0] );                                        sout | ca[0] | ca[1] | ca[2];
     160                sin | ignore( wdi( 4, (char &)*&ca[0] ) );              sout | ca[0] | ca[1] | ca[2];
    136161
    137162                signed char sc;
Note: See TracChangeset for help on using the changeset viewer.