Changeset 686912c for libcfa/src/collections/string.cfa
- Timestamp:
- Aug 31, 2023, 1:25:38 PM (10 months ago)
- Branches:
- master
- Children:
- 0f107e4, 2a301ff
- Parents:
- 0b8c951d
- File:
-
- 1 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
Note: See TracChangeset
for help on using the changeset viewer.