Changeset 34c6e1e6 for libcfa/src/collections/string.cfa
- Timestamp:
- Sep 2, 2023, 3:01:05 PM (9 months ago)
- Branches:
- master
- Children:
- 389fbf5
- Parents:
- 0f107e4
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/collections/string.cfa
r0f107e4 r34c6e1e6 10 10 // Created On : Fri Sep 03 11:00:00 2021 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 31 13:20:41202313 // Update Count : 16112 // Last Modified On : Sat Sep 2 12:05:57 2023 13 // Update Count : 206 14 14 // 15 15 … … 110 110 } 111 111 112 ofstream & ?|?( ofstream & os, _Ostream_Manip(string) f ) { 113 size_t len = size( f.val ); 114 char cstr[len + 1]; // room for null terminator 115 for ( i; len ) cstr[i] = f.val[i]; // copy string 116 cstr[len] = '\0'; // terminate 117 _Ostream_Manip(const char *) cf @= { cstr, f.wd, f.pc, f.base, {f.all} }; 118 os | cf | nonl; 119 return os; 120 } // ?|? 121 122 void ?|?( ofstream & os, _Ostream_Manip(string) f ) { 123 (ofstream &)(os | f); ends( os ); 124 } 125 112 126 ifstream & ?|?(ifstream & in, string & this) { 113 127 return in | (*this.inner); // read to internal string_res … … 118 132 } 119 133 120 ifstream & ?|?( ifstream & is, _Istream_str f ) { 121 // skip, same as for char * 122 if ( ! &f.s ) { 123 // fprintf( stderr, "skip %s %d\n", f.scanset, f.wd ); 124 if ( f.wd == -1 ) fmt( is, f.scanset, "" ); // no input arguments 125 else for ( f.wd ) fmt( is, "%*c" ); 126 return is; 127 } // if 128 134 ifstream & ?|?( ifstream & is, _Istream_Sstr f ) { 129 135 // .---------------, 130 // | | | | |...|0|0| check and guard136 // | | | | |...|0|0| null terminator and guard if missing 131 137 // `---------------' 132 enum { gwd = 128 + 2, wd = gwd - 1 }; // guarded and unguarded width138 enum { gwd = 128 + 1, wd = gwd - 1 }; // guard and unguard width 133 139 char cstr[gwd]; // read in chunks 134 140 bool cont = false; 135 141 136 if ( f.wd == -1 ) f.wd = wd;137 _Istream_Cstr cfmt = { cstr, (_Istream_str_base)f };142 _Istream_Cstr cf = { cstr, (_Istream_str_base)f }; 143 if ( ! cf.flags.rwd ) cf.wd = wd; 138 144 139 145 cstr[wd] = '\0'; // guard null terminate string 140 146 try { 141 is | cf mt;147 is | cf; 142 148 } catch( cstring_length * ) { 143 149 cont = true; … … 148 154 cont = false; 149 155 try { 150 is | cf mt;156 is | cf; 151 157 } catch( cstring_length * ) { 152 158 cont = true; // continue not allowed … … 158 164 } // ?|? 159 165 160 void ?|?( ifstream & in, _Istream_ str f ) {166 void ?|?( ifstream & in, _Istream_Sstr f ) { 161 167 (ifstream &)(in | f); ends( in ); 162 168 }
Note: See TracChangeset
for help on using the changeset viewer.