Changeset baa1d5d for libcfa/src
- Timestamp:
- Jan 27, 2024, 11:29:57 PM (8 months ago)
- Branches:
- master
- Children:
- 63e129c
- Parents:
- 765ee42
- Location:
- libcfa/src
- Files:
-
- 2 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 )
Note: See TracChangeset
for help on using the changeset viewer.