Changeset 5ad2c6c7 for libcfa/src
- Timestamp:
- Aug 24, 2023, 11:37:16 AM (2 years ago)
- Branches:
- master
- Children:
- 88001dd
- Parents:
- d0cfcbe1
- Location:
- libcfa/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/iostream.cfa
rd0cfcbe1 r5ad2c6c7 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Aug 14 23:07:20 202313 // Update Count : 1 46612 // Last Modified On : Thu Aug 24 10:25:20 2023 13 // Update Count : 1516 14 14 // 15 15 … … 970 970 } // if 971 971 972 int check = f.wd - 1; 973 972 974 // getline 973 975 if ( f.flags.delimit ) { 974 enum { size = 16};976 enum { size = 32 }; 975 977 char fmtstr[size]; 976 978 snprintf( fmtstr, size, "%%%d[^%c]s", f.wd, f.delimit ); 977 f.s[f.wd - 1] = '\0';// insert sentinel979 if ( ! f.flags.rwd ) f.s[check] = '\0'; // insert sentinel 978 980 int len = fmt( is, fmtstr, f.s ); // read upto delimiter 981 if ( ! f.flags.rwd && f.s[check] != '\0' ) // sentinel overwritten ? 982 throw (cstring_length){ &cstring_length_vt }; 979 983 if ( len == 0 ) f.s[0] = '\0'; // empty read => argument unchanged => set empty 980 if ( f.s[f.wd - 1] != '\0' ) // sentinel overwritten ? 981 throw (cstring_length){ &cstring_length_vt }; 984 // fprintf( stderr, "getline %s %s %d %d %d '%c'\n", fmtstr, f.s, len, f.wd, check, f.s[check] ); 982 985 if ( ! eof( is ) ) fmt( is, "%*c" ); // ignore delimiter 983 986 return is; … … 1007 1010 } // if 1008 1011 1009 int check = f.wd - 1; 1010 if ( f.flags.rwd ) check += 1; // provide place for sentinel 1011 f.s[check] = '\0'; // insert sentinel 1012 if ( ! f.flags.rwd ) f.s[check] = '\0'; // insert sentinel 1012 1013 fmt( is, fmtstr, f.s ); 1013 if ( f.s[check] != '\0' ) // sentinel overwritten ? 1014 // fprintf( stderr, "KK %s %d %c\n", fmtstr, check, f.s[check] ); 1015 if ( ! f.flags.rwd && f.s[check] != '\0' ) // sentinel overwritten ? 1014 1016 throw (cstring_length){ &cstring_length_vt }; 1015 1017 return is; -
libcfa/src/iostream.hfa
rd0cfcbe1 r5ad2c6c7 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Aug 18 10:44:50202313 // Update Count : 5 1212 // Last Modified On : Thu Aug 24 11:35:02 2023 13 // Update Count : 530 14 14 // 15 15 … … 18 18 #include "iterator.hfa" 19 19 #include "Exception.hfa" 20 21 20 22 21 // *********************************** ostream *********************************** … … 432 431 433 432 static inline { 434 _Istream_Cstr skip( const char scanset[] ) { return (_Istream_Cstr){ 0p, {scanset}, -1, {.all : 0} }; } 435 _Istream_Cstr skip( unsigned int wd ) { return (_Istream_Cstr){ 0p, {0p}, wd, {.all : 0} }; } 436 _Istream_Cstr & getline( _Istream_Cstr & fmt ) { fmt.delimit = '\n'; fmt.flags.delimit = true; return fmt; } 437 _Istream_Cstr & getline( const char delimit, _Istream_Cstr & fmt ) { fmt.delimit = delimit; fmt.flags.delimit = true; return fmt; } 438 // _Istream_Cstr incl( const char scanset[], char s[] ) { return (_Istream_Cstr){ s, {scanset}, -1, { .flags.inex : false } }; } 439 // _Istream_Cstr incl( const char scanset[], unsigned int wd, char s[] ) { return (_Istream_Cstr){ s, {scanset}, wd, {.flags.inex : false} }; } 440 _Istream_Cstr & incl( const char scanset[], _Istream_Cstr & fmt ) { fmt.scanset = scanset; fmt.flags.inex = false; return fmt; } 441 // _Istream_Cstr excl( const char scanset[], char s[] ) { return (_Istream_Cstr){ s, {scanset}, -1, { .flags.inex : true } }; } 442 // _Istream_Cstr excl( const char scanset[], unsigned int wd, char s[] ) { return (_Istream_Cstr){ s, {scanset}, wd, {.flags.inex : true} }; } 443 _Istream_Cstr & excl( const char scanset[], _Istream_Cstr & fmt ) { fmt.scanset = scanset; fmt.flags.inex = true; return fmt; } 444 _Istream_Cstr ignore( char s[] ) { return (_Istream_Cstr)@{ s, {0p}, -1, {.flags.ignore : true} }; } 445 _Istream_Cstr & ignore( _Istream_Cstr & fmt ) { fmt.flags.ignore = true; return fmt; } 433 // width must include room for null terminator 446 434 _Istream_Cstr wdi( unsigned int wd, char s[] ) { return (_Istream_Cstr)@{ s, {0p}, wd, {.all : 0} }; } 435 // read width does not include null terminator 447 436 _Istream_Cstr wdi( unsigned int wd, unsigned int rwd, char s[] ) { 448 437 if ( wd <= rwd ) throw (cstring_length){ &cstring_length_vt }; 449 438 return (_Istream_Cstr)@{ s, {0p}, rwd, {.flags.rwd : true} }; 450 439 } 451 // _Istream_Cstr & wdi( unsigned int wd, _Istream_Cstr & fmt ) { fmt.wd = wd; return fmt; } 440 _Istream_Cstr skip( const char scanset[] ) { return (_Istream_Cstr){ 0p, {scanset}, -1, {.all : 0} }; } 441 _Istream_Cstr skip( unsigned int wd ) { return (_Istream_Cstr){ 0p, {0p}, wd, {.all : 0} }; } 442 _Istream_Cstr & getline( _Istream_Cstr & fmt, const char delimit = '\n' ) { fmt.delimit = delimit; fmt.flags.delimit = true; return fmt; } 443 _Istream_Cstr & incl( const char scanset[], _Istream_Cstr & fmt ) { fmt.scanset = scanset; fmt.flags.inex = false; return fmt; } 444 _Istream_Cstr & excl( const char scanset[], _Istream_Cstr & fmt ) { fmt.scanset = scanset; fmt.flags.inex = true; return fmt; } 445 _Istream_Cstr ignore( char s[] ) { return (_Istream_Cstr)@{ s, {0p}, -1, {.flags.ignore : true} }; } 446 _Istream_Cstr & ignore( _Istream_Cstr & fmt ) { fmt.flags.ignore = true; return fmt; } 452 447 } // distribution 453 448 forall( istype & | basic_istream( istype ) ) {
Note:
See TracChangeset
for help on using the changeset viewer.