- Timestamp:
- Sep 5, 2023, 4:08:32 PM (16 months ago)
- Branches:
- master
- Children:
- 737988b
- Parents:
- 3c7e3c4
- Location:
- libcfa/src/collections
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/collections/string_res.cfa
r3c7e3c4 rff56dd2e 245 245 s = temp; 246 246 return in; 247 } 248 249 void ?|?( ifstream & in, string_res & this ) { 250 (ifstream &)(in | this); ends( in ); 251 } 252 253 ifstream & ?|?( ifstream & is, _Istream_Rstr f ) { 254 // .---------------, 255 // | | | | |...|0|0| null terminator and guard if missing 256 // `---------------' 257 enum { gwd = 128 + 1, wd = gwd - 1 }; // guard and unguard width 258 char cstr[gwd]; // read in chunks 259 bool cont = false; 260 261 _Istream_Cstr cf = { cstr, (_Istream_str_base)f }; 262 if ( ! cf.flags.rwd ) cf.wd = wd; 263 264 cstr[wd] = '\0'; // guard null terminate string 265 try { 266 is | cf; 267 } catch( cstring_length * ) { 268 cont = true; 269 } finally { 270 if ( ! cf.flags.ignore ) *(f.s) = cstr; // ok to initialize string 271 } // try 272 for ( ; cont; ) { // overflow read ? 273 cont = false; 274 try { 275 is | cf; 276 } catch( cstring_length * ) { 277 cont = true; // continue not allowed 278 } finally { 279 if ( ! cf.flags.ignore ) *(f.s) += cstr; // build string chunk at a time 280 } // try 281 } // for 282 return is; 283 } // ?|? 284 285 void ?|?( ifstream & in, _Istream_Rstr f ) { 286 (ifstream &)(in | f); ends( in ); 247 287 } 248 288 -
libcfa/src/collections/string_res.hfa
r3c7e3c4 rff56dd2e 102 102 void ?|?(ofstream &out, const string_res &s); 103 103 ifstream & ?|?(ifstream &in, string_res &s); 104 void ?|?( ifstream & in, string_res & this ); 105 106 struct _Istream_Rstr { 107 string_res * s; 108 inline _Istream_str_base; 109 }; // _Istream_Rstr 110 111 static inline { 112 // read width does not include null terminator 113 _Istream_Rstr wdi( unsigned int rwd, string_res & s ) { return (_Istream_Rstr)@{ &s, {{0p}, rwd, {.flags.rwd : true}} }; } 114 _Istream_Rstr getline( string_res & s, const char delimiter = '\n' ) { 115 return (_Istream_Rstr)@{ &s, {{.delimiter : { delimiter, '\0' } }, -1, {.flags.delimiter : true, .flags.inex : true}} }; 116 } 117 _Istream_Rstr & getline( _Istream_Rstr & fmt, const char delimiter = '\n' ) { 118 fmt.delimiter[0] = delimiter; fmt.delimiter[1] = '\0'; fmt.flags.delimiter = true; fmt.flags.inex = true; return fmt; 119 } 120 _Istream_Rstr incl( const char scanset[], string_res & s ) { return (_Istream_Rstr)@{ &s, {{scanset}, -1, {.flags.inex : false}} }; } 121 _Istream_Rstr & incl( const char scanset[], _Istream_Rstr & fmt ) { fmt.scanset = scanset; fmt.flags.inex = false; return fmt; } 122 _Istream_Rstr excl( const char scanset[], string_res & s ) { return (_Istream_Rstr)@{ &s, {{scanset}, -1, {.flags.inex : true}} }; } 123 _Istream_Rstr & excl( const char scanset[], _Istream_Rstr & fmt ) { fmt.scanset = scanset; fmt.flags.inex = true; return fmt; } 124 _Istream_Rstr ignore( string_res & s ) { return (_Istream_Rstr)@{ &s, {{0p}, -1, {.flags.ignore : true}} }; } 125 _Istream_Rstr & ignore( _Istream_Rstr & fmt ) { fmt.flags.ignore = true; return fmt; } 126 } // distribution 127 ifstream & ?|?( ifstream & is, _Istream_Rstr f ); 128 void ?|?( ifstream & is, _Istream_Rstr t ); 104 129 105 130 // Concatenation
Note: See TracChangeset
for help on using the changeset viewer.