Changeset 38de914 for libcfa/src/containers
- Timestamp:
- Aug 30, 2023, 11:20:14 AM (16 months ago)
- Branches:
- master
- Children:
- 55b060d
- Parents:
- 7e1dbd7
- Location:
- libcfa/src/containers
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
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 ) { -
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
Note: See TracChangeset
for help on using the changeset viewer.