- Timestamp:
- Apr 10, 2025, 7:44:17 PM (5 months ago)
- Branches:
- master
- Children:
- 570e7ad
- Parents:
- d175767
- Location:
- libcfa/src/collections
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/collections/string.cfa
rd175767 r3f631d6 214 214 // Input-Output 215 215 216 ofstream & ?|?( ofstream & out, const string & s ) { 217 return out | (*s.inner); // print internal string_res 218 } 219 220 void ?|?( ofstream & out, const string & s ) { 221 (ofstream &)(out | (*s.inner)); ends( out ); 222 } 223 224 ofstream & ?|?( ofstream & os, _Ostream_Manip(string) f ) { 225 size_t l = len( f.val ); 226 char cstr[l + 1]; // room for null terminator 227 for ( i; l ) cstr[i] = f.val[i]; // copy string 228 cstr[l] = '\0'; // terminate 229 _Ostream_Manip(const char *) cf @= { cstr, f.wd, f.pc, f.base, {f.all} }; 230 return os | cf | nonl; 231 } // ?|? 232 233 void ?|?( ofstream & os, _Ostream_Manip(string) f ) { 234 (ofstream &)(os | f); ends( os ); 235 } 236 237 ifstream & ?|?( ifstream & in, string & s ) { 238 return in | (*s.inner); // read to internal string_res 239 } 240 241 ifstream & ?|?( ifstream & is, _Istream_Squoted f ) { 242 _Istream_Rquoted f2 = { { f.sstr.s.inner, (_Istream_str_base)f.sstr } }; 243 return is | f2; 244 } // ?|? 245 246 ifstream & ?|?( ifstream & is, _Istream_Sstr f ) { 247 // _Istream_Rstr f2 = {f.sstr.s.inner, (_Istream_str_base)f.sstr}; 248 _Istream_Rstr f2 = {f.s.inner, (_Istream_str_base)f}; 249 return is | f2; 250 } // ?|? 216 forall( ostype & | basic_ostream( ostype ) ) { 217 218 ostype & ?|?( ostype & out, string s ) { 219 return out | (*s.inner); // print internal string_res 220 } 221 222 void ?|?( ostype & out, string s ) { 223 (ostype &)(out | (*s.inner)); ends( out ); 224 } 225 226 ostype & ?|?( ostype & os, _Ostream_Manip(string) f ) { 227 size_t l = len( f.val ); 228 char cstr[l + 1]; // room for null terminator 229 for ( i; l ) cstr[i] = f.val[i]; // copy string 230 cstr[l] = '\0'; // terminate 231 _Ostream_Manip(const char *) cf @= { cstr, f.wd, f.pc, f.base, {f.all} }; 232 return os | cf | nonl; 233 } // ?|? 234 235 void ?|?( ostype & os, _Ostream_Manip(string) f ) { 236 (ostype &)(os | f); ends( os ); 237 } 238 } 239 240 forall( istype & | basic_istream( istype ) ) { 241 242 istype & ?|?( istype & in, string & s ) { 243 return in | (*s.inner); // read to internal string_res 244 } 245 246 istype & ?|?( istype & is, _Istream_Squoted f ) { 247 _Istream_Rquoted f2 = { { f.sstr.s.inner, (_Istream_str_base)f.sstr } }; 248 return is | f2; 249 } // ?|? 250 251 istype & ?|?( istype & is, _Istream_Sstr f ) { 252 // _Istream_Rstr f2 = {f.sstr.s.inner, (_Istream_str_base)f.sstr}; 253 _Istream_Rstr f2 = {f.s.inner, (_Istream_str_base)f}; 254 return is | f2; 255 } // ?|? 256 } 251 257 252 258 //////////////////////////////////////////////////////// -
libcfa/src/collections/string.hfa
rd175767 r3f631d6 16 16 #pragma once 17 17 18 #include < fstream.hfa>18 #include <iostream.hfa> 19 19 #include <string_res.hfa> 20 20 … … 80 80 81 81 // IO Operator 82 ofstream & ?|?( ofstream & out, const string & s ); 83 void ?|?( ofstream & out, const string & s ); 84 ifstream & ?|?( ifstream & in, string & s ); 82 forall( ostype & | basic_ostream( ostype ) ) { 83 ostype & ?|?( ostype & out, string s ); 84 void ?|?( ostype & out, string s ); 85 } 86 forall( istype & | basic_istream( istype ) ) 87 istype & ?|?( istype & in, string & s ); 85 88 86 89 static inline { … … 95 98 _Ostream_Manip(string) & nobase( _Ostream_Manip(string) & fmt ) { fmt.flags.nobsdp = true; return fmt; } 96 99 } // distribution 97 ofstream & ?|?( ofstream & os, _Ostream_Manip(string) f ); 98 void ?|?( ofstream & os, _Ostream_Manip(string) ); 100 forall( ostype & | basic_ostream( ostype ) ) { 101 ostype & ?|?( ostype & os, _Ostream_Manip(string) f ); 102 void ?|?( ostype & os, _Ostream_Manip(string) ); 103 } 99 104 100 105 struct _Istream_Swidth { … … 143 148 _Istream_Sstr & ignore( _Istream_Sstr & f ) { f.flags.ignore = true; return (_Istream_Sstr &)f; } 144 149 } // distribution 145 ifstream & ?|?( ifstream & is, _Istream_Squoted f ); 146 ifstream & ?|?( ifstream & is, _Istream_Sstr f ); 147 static inline ifstream & ?|?( ifstream & is, _Istream_Swidth f ) { return is | *(_Istream_Sstr *)&f; } 150 forall( istype & | basic_istream( istype ) ) { 151 istype & ?|?( istype & is, _Istream_Squoted f ); 152 istype & ?|?( istype & is, _Istream_Sstr f ); 153 static inline istype & ?|?( istype & is, _Istream_Swidth f ) { return is | *(_Istream_Sstr *)&f; } 154 } 148 155 149 156 // Concatenation -
libcfa/src/collections/string_res.cfa
rd175767 r3f631d6 193 193 194 194 // Output operator 195 ofstream & ?|?(ofstream & out, const string_res & s) { 195 forall( ostype & | basic_ostream( ostype ) ) 196 ostype & ?|?( ostype & out, const string_res & s ) { 196 197 // CFA string is NOT null terminated, so print exactly lnth characters in a minimum width of 0. 197 198 return out | wd( 0, s.Handle.lnth, s.Handle.s ) | nonl; 198 199 } 199 200 200 void ?|?(ofstream & out, const string_res & s) { 201 (ofstream &)(out | s); ends( out ); 201 forall( ostype & | basic_ostream( ostype ) ) 202 void ?|?( ostype & out, const string_res & s ) { 203 (ostype &)(out | s); ends( out ); 202 204 } 203 205 204 206 // Input operator 205 ifstream & ?|?(ifstream & in, string_res & s) { 207 forall( istype & | basic_istream( istype ) ) 208 istype & ?|?( istype & in, string_res & s ) { 206 209 // Reading into a temp before assigning to s is near zero overhead in typical cases because of sharing. 207 210 // If s is a substring of something larger, simple assignment takes care of that case correctly. … … 245 248 } 246 249 247 ifstream & ?|?( ifstream & is, _Istream_Rquoted f ) with( f.rstr ) { 250 forall( istype & | basic_istream( istype ) ) 251 istype & ?|?( istype & is, _Istream_Rquoted f ) with( f.rstr ) { 248 252 if ( eof( is ) ) throwResume ExceptionInst( end_of_file ); 249 253 int args; … … 270 274 } 271 275 272 ifstream & ?|?( ifstream & is, _Istream_Rstr f ) { 276 forall( istype & | basic_istream( istype ) ) 277 istype & ?|?( istype & is, _Istream_Rstr f ) { 273 278 // .---------------, 274 279 // | | | | |...|0|0| null terminator and guard if missing -
libcfa/src/collections/string_res.hfa
rd175767 r3f631d6 16 16 #pragma once 17 17 18 #include < fstream.hfa>18 #include <iostream.hfa> 19 19 #include <string.h> // e.g. strlen 20 20 … … 120 120 121 121 // IO Operator 122 ofstream & ?|?(ofstream & out, const string_res & s); 123 void ?|?(ofstream & out, const string_res & s); 124 ifstream & ?|?(ifstream & in, string_res & s); 122 forall( ostype & | basic_ostream( ostype ) ) { 123 ostype & ?|?(ostype & out, const string_res & s); 124 void ?|?(ostype & out, const string_res & s); 125 } 126 forall( istype & | basic_istream( istype ) ) 127 istype & ?|?(istype & in, string_res & s); 125 128 126 129 struct _Istream_Rwidth { … … 167 170 _Istream_Rstr & ignore( _Istream_Rstr & f ) { f.flags.ignore = true; return (_Istream_Rstr &)f; } 168 171 } // distribution 169 ifstream & ?|?( ifstream & is, _Istream_Rquoted f ); 170 ifstream & ?|?( ifstream & is, _Istream_Rstr f ); 171 static inline ifstream & ?|?( ifstream & is, _Istream_Rwidth f ) { return is | *(_Istream_Rstr *)&f; } 172 forall( istype & | basic_istream( istype ) ) { 173 istype & ?|?( istype & is, _Istream_Rquoted f ); 174 istype & ?|?( istype & is, _Istream_Rstr f ); 175 static inline istype & ?|?( istype & is, _Istream_Rwidth f ) { return is | *(_Istream_Rstr *)&f; } 176 } 172 177 173 178 // Concatenation
Note:
See TracChangeset
for help on using the changeset viewer.