Changeset baa1d5d
- Timestamp:
- Jan 27, 2024, 11:29:57 PM (7 months ago)
- Branches:
- master
- Children:
- 63e129c
- Parents:
- 765ee42
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/iostream.cfa
r765ee42 rbaa1d5d 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jan 25 08:39:31202413 // Update Count : 190 112 // Last Modified On : Sat Jan 27 18:02:40 2024 13 // Update Count : 1909 14 14 // 15 15 … … 1002 1002 return is | *(_Istream_Cstr *)&f; 1003 1003 } // 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'; 1005 1006 if ( args == 1 && eof( is ) ) { // data but scan ended at EOF 1006 1007 clear( is ); // => reset EOF => detect again on next read … … 1055 1056 if ( flags.delimiter ) { // getline 1056 1057 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 1058 1063 if ( flags.ignore ) args = fmt( is, fmtstr, &len ); // no string argument for '*' 1059 1064 else args = fmt( is, fmtstr, s, &len ); … … 1097 1102 } // ?|? 1098 1103 1099 istype & ?|?( istype & is, _Istream_Char f ) with(f) {1100 if ( ignore ) {1101 fmt( is, "%*c" ); // argument variable unused1102 } else {1103 int len = -1, args = fmt( is, fmt, &c, &len );1104 if ( args != -1 && len == -1 ) throwResume ExceptionInst( missing_data );1105 } // if1106 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 // } // ?|? 1108 1113 } // distribution 1109 1114 … … 1124 1129 } // distribution 1125 1130 1131 INPUT_FMT_IMPL( char, "c" ) 1126 1132 INPUT_FMT_IMPL( signed char, "hhi" ) 1127 1133 INPUT_FMT_IMPL( unsigned char, "hhi" ) -
libcfa/src/iostream.hfa
r765ee42 rbaa1d5d 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jan 25 08:39:04202413 // Update Count : 69612 // Last Modified On : Sat Jan 27 17:55:22 2024 13 // Update Count : 732 14 14 // 15 15 … … 366 366 istype & nlOn( istype & ); 367 367 istype & nlOff( istype & ); 368 istype & quoted( istype &, char & c );369 368 } // distribution 370 369 … … 398 397 unsigned char ignore:1; // do not change input argument 399 398 unsigned char inex:1; // include/exclude characters in scanset 400 unsigned char delimiter:1; // delimit character 399 unsigned char delimiter:1; // delimit character(s) 401 400 unsigned char rwd:1; // read width 402 401 } flags; … … 429 428 return (_Istream_Cwidth)@{ .s : s, { {.scanset : 0p}, .wd : rwd, {.flags.rwd : true} } }; 430 429 } 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 } 431 433 _Istream_Cquoted & quoted( _Istream_Cwidth & f, const char Ldelimiter = '"', const char Rdelimiter = '\0' ) { 432 434 f.delimiters[0] = Ldelimiter; f.delimiters[1] = Rdelimiter; f.delimiters[2] = '\0'; … … 438 440 _Istream_Cstr & incl( const char scanset[], _Istream_Cwidth & f ) { f.scanset = scanset; f.flags.inex = false; return (_Istream_Cstr &)f; } 439 441 _Istream_Cstr & excl( const char scanset[], _Istream_Cwidth & f ) { f.scanset = scanset; f.flags.inex = true; return (_Istream_Cstr &)f; } 440 _Istream_Cstr ignore( c har 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} } }; } 441 443 _Istream_Cstr & ignore( _Istream_Cwidth & f ) { f.flags.ignore = true; return (_Istream_Cstr &)f; } 442 444 _Istream_Cquoted & ignore( _Istream_Cquoted & f ) { f.cstr.flags.ignore = true; return (_Istream_Cquoted &)f; } … … 453 455 } // distribution 454 456 455 struct _Istream_Char {456 char & c;457 bool ignore; // do not change input argument458 char fmt[7]; // \L%c\R%n\0459 }; // _Istream_Char460 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 } // distribution471 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 // } 475 477 476 478 forall( T & | sized( T ) ) … … 483 485 #define INPUT_FMT_DECL( T ) \ 484 486 static inline { \ 487 _Istream_Manip(T) wdi( unsigned int wd, T & val ) { return (_Istream_Manip(T))@{ .val : val, .wd : wd, .ignore : false }; } \ 485 488 _Istream_Manip(T) ignore( const T & val ) { return (_Istream_Manip(T))@{ .val : (T &)val, .wd : -1, .ignore : true }; } \ 486 489 _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; } \489 490 } /* distribution */ \ 490 491 forall( istype & | basic_istream( istype ) ) { \ … … 492 493 } // ?|? 493 494 495 INPUT_FMT_DECL( char ) 494 496 INPUT_FMT_DECL( signed char ) 495 497 INPUT_FMT_DECL( unsigned char ) -
tests/io/.in/manipulatorsInput.txt
r765ee42 rbaa1d5d 20 20 X ZC44%Y 21 21 X ZC55%Y 22 'x' 23 "x" 24 {x} 25 XxY 26 XyY 22 27 abc 23 28 cccccb … … 37 42 X ZC44%Y 38 43 X ZC55%Y 44 'x' 45 "x" 46 {x} 47 XxY 48 XyY 39 49 ab 50 xxxyyy 40 51 0xff 017 15-15 41 52 0xff 017 15-15 -
tests/io/manipulatorsInput.cfa
r765ee42 rbaa1d5d 7 7 // Created On : Sat Jun 8 17:58:54 2019 8 8 // Last Modified By : Peter A. Buhr 9 // Last Modified On : Wed Jan 24 18:36:32 202410 // Update Count : 1 049 // Last Modified On : Sat Jan 27 18:47:42 2024 10 // Update Count : 122 11 11 // 12 12 … … 55 55 } 56 56 { 57 char s[] = "yyyyyyyyyyyyyyyyyyyy"; 57 char s[] = "yyyyyyyyyyyyyyyyyyyy"; // Input characters consumed: 58 58 const char sk_fmt[] = "%*[abc]"; 59 scanf( "abc " ); scanf( sk_fmt ); for ( 5 ) scanf( "%*c" ); printf( "1 %s\n", s ); 60 scanf( "%s", s ); printf( "2 %s\n", s ); 61 scanf( "%*s" ); printf( "3 %s\n", s ); 62 scanf( "%8s", s ); printf( "4 %s\n", s ); 63 scanf( "%*8s" ); printf( "5 %s\n", s ); 64 65 scanf( "%[abc]", s ); printf( "6 %s\n", s ); 66 scanf( "%[^abc]", s ); printf( "7 %s\n", s ); 67 scanf( "%*[abc]" ); printf( "8 %s\n", s ); 68 scanf( "%*[^abc]" ); printf( "9 %s\n", s ); 69 scanf( "%8[abc]", s ); printf( "10 %s\n", s ); 70 scanf( "%8[^abc]", s ); printf( "11 %s\n", s ); 71 scanf( "%*8[abc]" ); printf( "12 %s\n", s ); 72 scanf( "%*8[^abc]" ); printf( "13 %s\n", s ); 73 scanf( "\n" ); // must start next line 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| 74 74 75 75 int rc; 76 76 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 ); // || 78 78 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| 96 109 } 97 110 { … … 128 141 sin | quoted( wdi( sizeof(s), s ), 'X', 'Y' ); sout | "22" | s; 129 142 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 132 153 { 133 154 char c; 134 155 sin | c; sout | c; 135 156 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]; 136 161 137 162 signed char sc;
Note: See TracChangeset
for help on using the changeset viewer.