Changeset 3f631d6
- Timestamp:
- Apr 10, 2025, 7:44:17 PM (5 months ago)
- Branches:
- master
- Children:
- 570e7ad
- Parents:
- d175767
- Files:
-
- 1 added
- 13 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 -
tests/Makefile.am
rd175767 r3f631d6 288 288 -cp ${test} ${abspath ${@}} 289 289 290 collections/string-operator-ERR09 : collections/string-operator.cfa 291 ${CFACOMPILE_SYNTAX} -DTRY_MR09 292 -cp ${test} ${abspath ${@}} 293 290 294 collections/string-operator-ERR15 : collections/string-operator.cfa 291 295 ${CFACOMPILE_SYNTAX} -DTRY_MR15 -
tests/collections/.expect/string-operator.txt
rd175767 r3f631d6 65 65 66 66 ------------- Bare (sout-direct) 67 ab 67 (skip) 68 68 ab 69 69 ab … … 85 85 axb 86 86 87 aaa 87 291 88 88 bbb 89 ÃÃÃ 89 585 90 90 cdcdcd 91 91 92 92 291 93 93 bbb 94 ababab 94 585 95 95 cdcdcd 96 96 -
tests/collections/string-api-coverage.cfa
rd175767 r3f631d6 1 #include < collections/string.hfa>1 #include <string.hfa> 2 2 #include <string_sharectx.hfa> 3 #include <fstream.hfa> 3 4 4 5 -
tests/collections/string-ctx-manage.cfa
rd175767 r3f631d6 2 2 #include <string_sharectx.hfa> 3 3 #include <string_res.hfa> 4 #include <fstream.hfa> 4 5 5 6 // In these tests, shared heaps are never remotely full and string sizes are tiny. -
tests/collections/string-gc.cfa
rd175767 r3f631d6 1 1 #include <string_res.hfa> 2 #include <fstream.hfa> 2 3 3 4 size_t bytesRemaining() { -
tests/collections/string-istream-manip.cfa
rd175767 r3f631d6 1 1 2 2 #include <fstream.hfa> 3 #include < collections/string.hfa>4 #include < collections/string_res.hfa>3 #include <string.hfa> 4 #include <string_res.hfa> 5 5 #include <stdio.h> 6 6 -
tests/collections/string-istream.cfa
rd175767 r3f631d6 1 #include < iostream.hfa>2 #include < collections/string.hfa>3 #include < collections/string_res.hfa>1 #include <fstream.hfa> 2 #include <string.hfa> 3 #include <string_res.hfa> 4 4 5 5 -
tests/collections/string-operator.cfa
rd175767 r3f631d6 9 9 10 10 // These MR points do reject in the current revision, so they have satellite "-ERR" cases: 11 // MR09 11 12 // MR15 12 13 … … 20 21 #define TRY_MR07 21 22 #define TRY_MR08 22 #define TRY_MR0923 23 #define TRY_MR10 24 24 #define TRY_MR11 … … 275 275 s = "x"; 276 276 277 MR09( sout | 'a' + 'b'; ) // ab277 MR09( sout | 'a' + 'b'; ) // (ambiguous) 278 278 sout | 'a' + "b"; // ab 279 279 sout | "a" + 'b'; // ab … … 299 299 sout | nl; // 300 300 301 MR11( sout | 'a' * 3; ) // aaa301 MR11( sout | 'a' * 3; ) // 291 302 302 sout | "b" * 3; // bbb 303 MR12( sout | ('a' + 'b') * 3; ) // ÃÃÃ303 MR12( sout | ('a' + 'b') * 3; ) // 585 304 304 sout | ('c' + "d") * 3; // cdcdcd 305 305 sout | nl; // … … 307 307 MR13( sout | 3 * 'a'; ) // 291 308 308 sout | 3 * "b"; // bbb 309 MR14( sout | 3 * ('a' + 'b'); ) // ababab309 MR14( sout | 3 * ('a' + 'b'); ) // 585 310 310 sout | 3 * ('c' + "d"); // cdcdcd 311 311 sout | nl; // -
tests/collections/string-overwrite.cfa
rd175767 r3f631d6 1 #include < collections/string.hfa>1 #include <string.hfa> 2 2 #include <string_sharectx.hfa> 3 #include <fstream.hfa> 3 4 4 5 /*
Note:
See TracChangeset
for help on using the changeset viewer.