- Timestamp:
- Aug 31, 2023, 1:25:38 PM (19 months ago)
- Branches:
- master
- Children:
- 0f107e4, 2a301ff
- Parents:
- 0b8c951d
- Location:
- libcfa/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/collections/string.cfa
r0b8c951d r686912c 10 10 // Created On : Fri Sep 03 11:00:00 2021 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T ue Aug 29 18:32:34202313 // Update Count : 1 5312 // Last Modified On : Thu Aug 31 13:20:41 2023 13 // Update Count : 161 14 14 // 15 15 … … 127 127 } // if 128 128 129 // .---------------, 130 // | | | | |...|0|0| check and guard 131 // `---------------' 129 132 enum { gwd = 128 + 2, wd = gwd - 1 }; // guarded and unguarded width 130 133 char cstr[gwd]; // read in chunks 131 bool cont = false; ;134 bool cont = false; 132 135 133 136 if ( f.wd == -1 ) f.wd = wd; 134 const char * scanset = f.scanset;; 135 if ( f.flags.delimit ) scanset = f.delimit; // getline ? 136 137 size_t len = 0; 138 if ( scanset ) len = strlen( scanset ); 139 char fmtstr[len + 16]; 140 int start = 1; 141 fmtstr[0] = '%'; 142 if ( f.flags.ignore ) { fmtstr[1] = '*'; start += 1; } 143 if ( f.wd != -1 ) { start += sprintf( &fmtstr[start], "%d", f.wd ); } 144 145 if ( ! scanset ) { 146 // %s, %*s, %ws, %*ws 147 fmtstr[start] = 's'; fmtstr[start + 1] = '\0'; 148 // printf( "cstr %s\n", fmtstr ); 149 } else { 150 // incl %[xxx], %*[xxx], %w[xxx], %*w[xxx] 151 // excl %[^xxx], %*[^xxx], %w[^xxx], %*w[^xxx] 152 fmtstr[start] = '['; start += 1; 153 if ( f.flags.inex ) { fmtstr[start] = '^'; start += 1; } 154 strcpy( &fmtstr[start], scanset ); // copy includes '\0' 155 len += start; 156 fmtstr[len] = ']'; fmtstr[len + 1] = '\0'; 157 // printf( "incl/excl %s\n", fmtstr ); 158 } // if 137 _Istream_Cstr cfmt = { cstr, (_Istream_str_base)f }; 159 138 160 139 cstr[wd] = '\0'; // guard null terminate string 161 140 try { 162 readstr( is, f, fmtstr, cstr );141 is | cfmt; 163 142 } catch( cstring_length * ) { 164 143 cont = true; … … 169 148 cont = false; 170 149 try { 171 readstr( is, f, fmtstr, cstr );150 is | cfmt; 172 151 } catch( cstring_length * ) { 173 152 cont = true; // continue not allowed … … 183 162 } 184 163 185 // void getline( ifstream & in, string & str, const char delimit = '\n' ) {186 // // .---------------,187 // // | | | | |...|0|0| check and guard188 // // `---------------'189 // enum { gwd = 128 + 2, wd = gwd - 1 }; // guarded and unguarded width190 // char cstr[gwd]; // read in chunks191 // bool cont = false;;192 193 // cstr[wd] = '\0'; // guard null terminate string194 // try {195 // in | getline( wdi( wd, cstr ), delimit ); // must have room for string terminator196 // if ( eof( in ) ) return; // do not change argument197 // } catch( cstring_length * ) {198 // cont = true;199 // } finally {200 // str = cstr; // ok to initialize string201 // } // try202 // for ( ; cont; ) { // overflow read ?203 // cont = false;204 // try {205 // in | getline( wdi( wd, cstr ), delimit ); // must have room for string terminator206 // if ( eof( in ) ) return;207 // } catch( cstring_length * ) {208 // cont = true; // continue not allowed209 // } finally {210 // str += cstr; // build string chunk at a time211 // } // try212 // } // for213 // }214 215 164 //////////////////////////////////////////////////////// 216 165 // Slicing -
libcfa/src/collections/string.hfa
r0b8c951d r686912c 10 10 // Created On : Fri Sep 03 11:00:00 2021 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T ue Aug 29 18:28:04202313 // Update Count : 4 712 // Last Modified On : Thu Aug 31 11:47:27 2023 13 // Update Count : 49 14 14 // 15 15 … … 83 83 ifstream & ?|?( ifstream & is, _Istream_str f ); 84 84 void ?|?( ifstream & is, _Istream_str t ); 85 void getline( ifstream & in, string & this, const char delimit = '\n' );86 85 87 86 // Concatenation -
libcfa/src/iostream.cfa
r0b8c951d r686912c 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Aug 30 10:56:08202313 // Update Count : 154 112 // Last Modified On : Thu Aug 31 11:27:56 2023 13 // Update Count : 1545 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 sentinel968 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 empty976 if ( ! eof( is ) ) fmt( is, "%*c" ); // ignore delimiter977 } //if978 } // readstr979 980 964 istype & ?|?( istype & is, _Istream_Cstr f ) { 981 965 // skip … … 1013 997 } // if 1014 998 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 999 int check = f.wd - 1; 1000 if ( ! f.flags.rwd ) f.s[check] = '\0'; // insert sentinel 1001 len = fmt( is, fmtstr, f.s ); 1002 //fprintf( stderr, "KK %s %zd %d %c %s\n", fmtstr, len, check, f.s[check], f.s ); 1003 1004 if ( ! f.flags.rwd && f.s[check] != '\0' ) // sentinel overwritten ? 1005 throw (cstring_length){ &cstring_length_vt }; 1006 1007 if ( f.flags.delimit ) { // getline ? 1008 if ( len == 0 ) f.s[0] = '\0'; // empty read => argument unchanged => set empty 1009 if ( ! eof( is ) ) fmt( is, "%*c" ); // ignore delimiter 1010 } //if 1028 1011 return is; 1029 1012 } // ?|? -
libcfa/src/iostream.hfa
r0b8c951d r686912c 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T ue Aug 29 19:15:06202313 // Update Count : 54 212 // Last Modified On : Thu Aug 31 10:55:35 2023 13 // Update Count : 544 14 14 // 15 15 … … 446 446 } // distribution 447 447 forall( istype & | basic_istream( istype ) ) { 448 void readstr( istype & is, _Istream_str_base f, char fmtstr[], char cstr[] );449 448 istype & ?|?( istype & is, _Istream_Cstr f ); 450 449 ISTYPE_VOID( _Istream_Cstr );
Note: See TracChangeset
for help on using the changeset viewer.