Changeset 38de914
- Timestamp:
- Aug 30, 2023, 11:20:14 AM (20 months ago)
- Branches:
- master
- Children:
- 55b060d
- Parents:
- 7e1dbd7
- Location:
- libcfa/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified libcfa/src/containers/string.cfa ¶
r7e1dbd7 r38de914 10 10 // Created On : Fri Sep 03 11:00:00 2021 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Aug 28 19:00:45202313 // Update Count : 1 4612 // Last Modified On : Tue Aug 29 18:32:34 2023 13 // Update Count : 153 14 14 // 15 15 … … 118 118 } 119 119 120 static void readstr( ifstream & is, _Istream_str f, char fmtstr[], char cstr[] ) {121 int check = f.rwd - 1;122 123 if ( ! f.flags.rwd ) cstr[check] = '\0'; // insert sentinel124 int len = fmt( is, fmtstr, cstr );125 // fprintf( stderr, "KK %s %zd %d %c %s\n", fmtstr, len, check, cstr[check], cstr );126 127 if ( ! f.flags.rwd && cstr[check] != '\0' ) // sentinel overwritten ?128 throw (cstring_length){ &cstring_length_vt };129 130 if ( f.flags.delimit ) { // getline ?131 if ( len == 0 ) cstr[0] = '\0'; // empty read => argument unchanged => set empty132 if ( ! eof( is ) ) fmt( is, "%*c" ); // ignore delimiter133 } //if134 } // readstr135 136 120 ifstream & ?|?( ifstream & is, _Istream_str f ) { 137 121 // skip, same as for char * 138 122 if ( ! &f.s ) { 139 123 // fprintf( stderr, "skip %s %d\n", f.scanset, f.wd ); 140 if ( f. rwd == -1 ) fmt( is, f.scanset, "" ); // no input arguments141 else for ( f. rwd ) fmt( is, "%*c" );124 if ( f.wd == -1 ) fmt( is, f.scanset, "" ); // no input arguments 125 else for ( f.wd ) fmt( is, "%*c" ); 142 126 return is; 143 127 } // if 144 128 145 enum { gwd = 1 6+ 2, wd = gwd - 1 }; // guarded and unguarded width129 enum { gwd = 128 + 2, wd = gwd - 1 }; // guarded and unguarded width 146 130 char cstr[gwd]; // read in chunks 147 131 bool cont = false;; 148 132 149 if ( f. rwd == -1 ) f.rwd = wd;133 if ( f.wd == -1 ) f.wd = wd; 150 134 const char * scanset = f.scanset;; 151 135 if ( f.flags.delimit ) scanset = f.delimit; // getline ? … … 157 141 fmtstr[0] = '%'; 158 142 if ( f.flags.ignore ) { fmtstr[1] = '*'; start += 1; } 159 if ( f. rwd != -1 ) { start += sprintf( &fmtstr[start], "%d", f.rwd ); }143 if ( f.wd != -1 ) { start += sprintf( &fmtstr[start], "%d", f.wd ); } 160 144 161 145 if ( ! scanset ) { -
TabularUnified libcfa/src/containers/string.hfa ¶
r7e1dbd7 r38de914 10 10 // Created On : Fri Sep 03 11:00:00 2021 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Aug 28 18:32:59202313 // Update Count : 4 012 // Last Modified On : Tue Aug 29 18:28:04 2023 13 // Update Count : 47 14 14 // 15 15 … … 58 58 void ?|?( ifstream & in, string & this ); 59 59 60 61 60 struct _Istream_str { 62 61 string & s; 63 union { 64 const char * scanset; 65 char delimit[2]; 66 }; 67 int rwd; // read width 68 union { 69 unsigned char all; 70 struct { 71 unsigned char ignore:1; // do not change input argument 72 unsigned char inex:1; // include/exclude characters in scanset 73 unsigned char delimit:1; // delimit character 74 unsigned char rwd:1; // read width 75 } flags; 76 }; 62 inline _Istream_str_base; 77 63 }; // _Istream_str 78 64 79 65 static inline { 80 66 // read width does not include null terminator 81 _Istream_str wdi( unsigned int rwd, string & s ) { return (_Istream_str)@{ s, { 0p}, rwd, {.flags.rwd : true} }; }82 _Istream_str skip( const char scanset[] ) { return (_Istream_str)@{ *0p, { scanset}, -1, {.all : 0} }; }83 _Istream_str skip( unsigned int wd ) { return (_Istream_str)@{ *0p, { 0p}, wd, {.all : 0} }; }67 _Istream_str wdi( unsigned int rwd, string & s ) { return (_Istream_str)@{ s, {{0p}, rwd, {.flags.rwd : true}} }; } 68 _Istream_str skip( const char scanset[] ) { return (_Istream_str)@{ *0p, {{scanset}, -1, {.all : 0}} }; } 69 _Istream_str skip( unsigned int wd ) { return (_Istream_str)@{ *0p, {{0p}, wd, {.all : 0}} }; } 84 70 _Istream_str getline( string & s, const char delimit = '\n' ) { 85 return (_Istream_str)@{ s, { .delimit : { delimit, '\0' } }, -1, {.flags.delimit : true, .flags.inex : true} };71 return (_Istream_str)@{ s, {{.delimit : { delimit, '\0' } }, -1, {.flags.delimit : true, .flags.inex : true}} }; 86 72 } 87 73 _Istream_str & getline( _Istream_str & fmt, const char delimit = '\n' ) { 88 74 fmt.delimit[0] = delimit; fmt.delimit[1] = '\0'; fmt.flags.delimit = true; fmt.flags.inex = true; return fmt; 89 75 } 90 _Istream_str incl( const char scanset[], string & s ) { return (_Istream_str)@{ s, { scanset}, -1, {.flags.inex : false} }; }76 _Istream_str incl( const char scanset[], string & s ) { return (_Istream_str)@{ s, {{scanset}, -1, {.flags.inex : false}} }; } 91 77 _Istream_str & incl( const char scanset[], _Istream_str & fmt ) { fmt.scanset = scanset; fmt.flags.inex = false; return fmt; } 92 _Istream_str excl( const char scanset[], string & s ) { return (_Istream_str)@{ s, { scanset}, -1, {.flags.inex : true} }; }78 _Istream_str excl( const char scanset[], string & s ) { return (_Istream_str)@{ s, {{scanset}, -1, {.flags.inex : true}} }; } 93 79 _Istream_str & excl( const char scanset[], _Istream_str & fmt ) { fmt.scanset = scanset; fmt.flags.inex = true; return fmt; } 94 _Istream_str ignore( string & s ) { return (_Istream_str)@{ s, { 0p}, -1, {.flags.ignore : true} }; }80 _Istream_str ignore( string & s ) { return (_Istream_str)@{ s, {{0p}, -1, {.flags.ignore : true}} }; } 95 81 _Istream_str & ignore( _Istream_str & fmt ) { fmt.flags.ignore = true; return fmt; } 96 82 } // distribution -
TabularUnified libcfa/src/iostream.cfa ¶
r7e1dbd7 r38de914 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 28 13:36:16202313 // Update Count : 15 2712 // Last Modified On : Wed Aug 30 10:56:08 2023 13 // Update Count : 1541 14 14 // 15 15 … … 962 962 963 963 forall( istype & | basic_istream( istype ) ) { 964 void readstr( istype & is, _Istream_str_base f, char fmtstr[], char cstr[] ) { 965 int check = f.wd - 1; 966 967 if ( ! f.flags.rwd ) cstr[check] = '\0'; // insert sentinel 968 int len = fmt( is, fmtstr, cstr ); 969 // fprintf( stderr, "KK %s %zd %d %c %s\n", fmtstr, len, check, cstr[check], cstr ); 970 971 if ( ! f.flags.rwd && cstr[check] != '\0' ) // sentinel overwritten ? 972 throw (cstring_length){ &cstring_length_vt }; 973 974 if ( f.flags.delimit ) { // getline ? 975 if ( len == 0 ) cstr[0] = '\0'; // empty read => argument unchanged => set empty 976 if ( ! eof( is ) ) fmt( is, "%*c" ); // ignore delimiter 977 } //if 978 } // readstr 979 964 980 istype & ?|?( istype & is, _Istream_Cstr f ) { 965 981 // skip … … 971 987 } // if 972 988 973 int check = f.wd - 1; 974 const char * scanset = f.scanset;; 989 const char * scanset = f.scanset; 975 990 if ( f.flags.delimit ) scanset = f.delimit; // getline ? 976 977 // getline978 // if ( f.flags.delimit ) {979 // enum { size = 32 };980 // char fmtstr[size];981 // snprintf( fmtstr, size, "%%%d[^%c]s", f.wd, f.delimit );982 // if ( ! f.flags.rwd ) f.s[check] = '\0'; // insert sentinel983 // int len = fmt( is, fmtstr, f.s ); // read upto delimiter984 // if ( ! f.flags.rwd && f.s[check] != '\0' ) // sentinel overwritten ?985 // throw (cstring_length){ &cstring_length_vt };986 // if ( len == 0 ) f.s[0] = '\0'; // empty read => argument unchanged => set empty987 // // fprintf( stderr, "getline %s %s %d %d %d '%c'\n", fmtstr, f.s, len, f.wd, check, f.s[check] );988 // if ( ! eof( is ) ) fmt( is, "%*c" ); // ignore delimiter989 // return is;990 // } // if991 991 992 992 size_t len = 0; … … 1013 1013 } // if 1014 1014 1015 if ( ! f.flags.rwd ) f.s[check] = '\0'; // insert sentinel 1016 len = fmt( is, fmtstr, f.s ); 1017 //fprintf( stderr, "KK %s %zd %d %c %s\n", fmtstr, len, check, f.s[check], f.s ); 1018 if ( ! f.flags.rwd && f.s[check] != '\0' ) // sentinel overwritten ? 1019 throw (cstring_length){ &cstring_length_vt }; 1020 1021 if ( f.flags.delimit ) { // getline ? 1022 if ( len == 0 ) f.s[0] = '\0'; // empty read => argument unchanged => set empty 1023 if ( ! eof( is ) ) fmt( is, "%*c" ); // ignore delimiter 1024 } //if 1015 readstr( is, f, fmtstr, f.s ); 1016 // int check = f.wd - 1; 1017 1018 // if ( ! f.flags.rwd ) f.s[check] = '\0'; // insert sentinel 1019 // len = fmt( is, fmtstr, f.s ); 1020 // //fprintf( stderr, "KK %s %zd %d %c %s\n", fmtstr, len, check, f.s[check], f.s ); 1021 // if ( ! f.flags.rwd && f.s[check] != '\0' ) // sentinel overwritten ? 1022 // throw (cstring_length){ &cstring_length_vt }; 1023 1024 // if ( f.flags.delimit ) { // getline ? 1025 // if ( len == 0 ) f.s[0] = '\0'; // empty read => argument unchanged => set empty 1026 // if ( ! eof( is ) ) fmt( is, "%*c" ); // ignore delimiter 1027 // } //if 1025 1028 return is; 1026 1029 } // ?|? -
TabularUnified libcfa/src/iostream.hfa ¶
r7e1dbd7 r38de914 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 25 14:55:06 202313 // Update Count : 5 3512 // Last Modified On : Tue Aug 29 19:15:06 2023 13 // Update Count : 542 14 14 // 15 15 … … 406 406 // *********************************** manipulators *********************************** 407 407 408 struct _Istream_Cstr { 409 char * s; 408 struct _Istream_str_base { 410 409 union { 411 410 const char * scanset; … … 422 421 } flags; 423 422 }; 423 }; // _Istream_str_base 424 425 struct _Istream_Cstr { 426 char * s; 427 inline _Istream_str_base; 424 428 }; // _Istream_Cstr 425 429 426 430 static inline { 427 431 // width must include room for null terminator 428 _Istream_Cstr wdi( unsigned int wd, char s[] ) { return (_Istream_Cstr)@{ s, { 0p}, wd, {.all : 0} }; }432 _Istream_Cstr wdi( unsigned int wd, char s[] ) { return (_Istream_Cstr)@{ s, { {0p}, wd, {.all : 0} } }; } 429 433 // read width does not include null terminator 430 434 _Istream_Cstr wdi( unsigned int wd, unsigned int rwd, char s[] ) { 431 435 if ( wd <= rwd ) throw (cstring_length){ &cstring_length_vt }; 432 return (_Istream_Cstr)@{ s, { 0p}, rwd, {.flags.rwd : true} };436 return (_Istream_Cstr)@{ s, { {0p}, rwd, {.flags.rwd : true} } }; 433 437 } 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} }; }438 _Istream_Cstr skip( const char scanset[] ) { return (_Istream_Cstr)@{ 0p, { {scanset}, -1, {.all : 0} } }; } 439 _Istream_Cstr skip( unsigned int wd ) { return (_Istream_Cstr)@{ 0p, { {0p}, wd, {.all : 0} } }; } 436 440 _Istream_Cstr & getline( _Istream_Cstr & fmt, const char delimit = '\n' ) { 437 441 fmt.delimit[0] = delimit; fmt.delimit[1] = '\0'; fmt.flags.delimit = true; fmt.flags.inex = true; return fmt; } 438 442 _Istream_Cstr & incl( const char scanset[], _Istream_Cstr & fmt ) { fmt.scanset = scanset; fmt.flags.inex = false; return fmt; } 439 443 _Istream_Cstr & excl( const char scanset[], _Istream_Cstr & fmt ) { fmt.scanset = scanset; fmt.flags.inex = true; return fmt; } 440 _Istream_Cstr ignore( char s[] ) { return (_Istream_Cstr)@{ s, { 0p}, -1, {.flags.ignore : true} }; }444 _Istream_Cstr ignore( char s[] ) { return (_Istream_Cstr)@{ s, { {0p}, -1, {.flags.ignore : true} } }; } 441 445 _Istream_Cstr & ignore( _Istream_Cstr & fmt ) { fmt.flags.ignore = true; return fmt; } 442 446 } // distribution 443 447 forall( istype & | basic_istream( istype ) ) { 448 void readstr( istype & is, _Istream_str_base f, char fmtstr[], char cstr[] ); 444 449 istype & ?|?( istype & is, _Istream_Cstr f ); 445 450 ISTYPE_VOID( _Istream_Cstr );
Note: See TracChangeset
for help on using the changeset viewer.