Changeset 570e7ad
- Timestamp:
- Apr 11, 2025, 12:29:56 AM (5 months ago)
- Branches:
- master
- Children:
- d03a386
- Parents:
- 3f631d6
- Files:
-
- 12 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/collections/string.cfa
r3f631d6 r570e7ad 40 40 } 41 41 42 void ?{}( string & s, const string & c ) {42 void ?{}( string & s, string c ) { // c is a memcpy of the real src string 43 43 (s.inner) { malloc() }; 44 44 ?{}( *s.inner, *c.inner, COPY_VALUE ); 45 45 } 46 46 47 void ?{}( string & s, const string &s2, size_t maxlen ) {47 void ?{}( string & s, string s2, size_t maxlen ) { 48 48 (s.inner) { malloc() }; 49 49 ?{}( *s.inner, *s2.inner, COPY_VALUE, maxlen ); 50 50 } 51 51 52 53 void ?{}( string & s, string & c ) { 54 ?{}( s, (const string &) c ); 55 } 56 57 void ?{}( string & s, const char c ) { 52 void ?{}( string & s, char c ) { 58 53 (s.inner) { malloc() }; 59 54 ?{}( *s.inner, c ); … … 70 65 } 71 66 72 void ?{}( string & s, s size_t rhs ) {67 void ?{}( string & s, signed long int rhs ) { 73 68 (s.inner) { malloc() }; 74 69 ?{}( *s.inner, rhs ); … … 151 146 // Assignment 152 147 153 string & ?=?( string & s, const string & c ) { 154 (*s.inner) = (*c.inner); 155 return s; 156 } 157 158 string & ?=?( string & s, string & c ) { 148 string & ?=?( string & s, string c ) { 159 149 (*s.inner) = (*c.inner); 160 150 return s; … … 181 171 } 182 172 183 string & ?=?( string & s, s size_t rhs ) {173 string & ?=?( string & s, signed long int rhs ) { 184 174 (*s.inner) = rhs; 185 175 return s; … … 324 314 } 325 315 326 string ?+?( const string &s, char c ) {316 string ?+?( string s, char c ) { 327 317 string ret = s; 328 318 ret += c; … … 330 320 } 331 321 332 string ?+?( char c, const string &s ) {322 string ?+?( char c, string s ) { 333 323 string ret = c; 334 324 ret += s; … … 336 326 } 337 327 338 string ?+?( const string & s, const string &s2 ) {328 string ?+?( string s, string s2 ) { 339 329 string ret = s; 340 330 ret += s2; … … 360 350 } 361 351 362 string ?+?( const char * s1, const string &s2 ) {352 string ?+?( const char * s1, string s2 ) { 363 353 string ret = s1; 364 354 ret += s2; … … 366 356 } 367 357 368 string ?+?( const string &s, const char * c ) {358 string ?+?( string s, const char * c ) { 369 359 string ret = s; 370 360 ret += c; … … 381 371 // Repetition 382 372 383 void ?*=?( string & s, s ize_t factor ) {373 void ?*=?( string & s, strmul_factor_t factor ) { 384 374 (*s.inner) *= factor; 385 375 } 386 376 387 string ?*?( const string & s, size_t factor ) {377 string ?*?( string s, strmul_factor_t factor ) { 388 378 string ret = s; 389 379 ret *= factor; … … 391 381 } 392 382 393 string ?*?( char c, s ize_t factor ) {383 string ?*?( char c, strmul_factor_t factor ) { 394 384 string ret = c; 395 385 ret *= factor; … … 397 387 } 398 388 399 string ?*?( const char * s, s ize_t factor ) {389 string ?*?( const char * s, strmul_factor_t factor ) { 400 390 string ret = s; 401 391 ret *= factor; -
libcfa/src/collections/string.hfa
r3f631d6 r570e7ad 27 27 28 28 void ?{}( string & s ); // empty string 29 void ?{}( string & s, const string & s2 ); 30 void ?{}( string & s, const string & s2, size_t maxlen ); 31 void ?{}( string & s, string & s2 ); 32 29 void ?{}( string & s, string s2, size_t maxlen ); 30 void ?{}( string & s, string s2 ); 33 31 void ?{}( string & s, char ); 34 32 void ?{}( string & s, const char * c ); // copy from string literal (NULL-terminated) 35 33 void ?{}( string & s, const char * c, size_t size ); // copy specific length from buffer 36 34 37 void ?{}( string & s, s size_t rhs );35 void ?{}( string & s, signed long int rhs ); 38 36 void ?{}( string & s, size_t rhs ); 39 37 void ?{}( string & s, double rhs ); … … 41 39 void ?{}( string & s, double _Complex rhs ); 42 40 void ?{}( string & s, long double _Complex rhs ); 41 static inline void ?{}( string & s, int rhs ) { (s){(signed long int) rhs}; } 43 42 44 43 // string str( ssize_t rhs ); … … 49 48 // string str( long double _Complex rhs ); 50 49 51 string & ?=?( string & s, const string & c ); 52 string & ?=?( string & s, string & c ); 50 string & ?=?( string & s, string c ); 53 51 string & ?=?( string & s, const char * c ); // copy from "literal" 54 52 string & ?=?( string & s, char c ); // copy from 'l' 55 53 string & assign( string & s, const string & c, size_t n ); 56 54 string & assign( string & s, const char * c, size_t n ); 57 string & ?=?( string & s, s size_t rhs );55 string & ?=?( string & s, signed long int rhs ); 58 56 string & ?=?( string & s, size_t rhs ); 59 57 string & ?=?( string & s, double rhs ); … … 61 59 string & ?=?( string & s, double _Complex rhs ); 62 60 string & ?=?( string & s, long double _Complex rhs ); 61 static inline string & ?=?( string & s, int rhs ) { return s = ((signed long int) rhs); } // to match cost of (char * int): int 63 62 64 63 static inline string & strcpy( string & s, const char * c ) { s = c; return s; } … … 161 160 void append( string & s, const char * buffer, size_t bsize ); 162 161 163 string ?+?( const string &s, char c );164 string ?+?( char c, const string &s );165 string ?+?( const string & s, const string &s2 );162 string ?+?( string s, char c ); 163 string ?+?( char c, string s ); 164 string ?+?( string s, string s2 ); 166 165 string ?+?( const char * s, char c ); // not backwards compatible 167 166 string ?+?( char c, const char * s ); 168 167 string ?+?( const char * c, const char * s ); 169 string ?+?( const char * c, const string &s );170 string ?+?( const string &s, const char * c );168 string ?+?( const char * c, string s ); 169 string ?+?( string s, const char * c ); 171 170 string ?+?( char, char ); // not being called 8-( 172 171 … … 177 176 178 177 // Repetition 179 void ?*=?( string & s, size_t factor ); 180 string ?*?( char c, size_t factor ); // not backwards compatible 181 string ?*?( const string & s, size_t factor ); 182 static inline string ?*?( size_t factor, const string & s ) { return s * factor; } 183 string ?*?( const char * s, size_t factor ); 184 static inline string ?*?( size_t factor, const char * s ) { return s * factor; } 178 179 // Type `signed long long int` chosen for `factor` argument to achieve cost detente. 180 // This way, the call `'a' * 3` gets the same safe conversion cost calling here as for 181 // the built-in definition `int * int`. 182 typedef signed long long int strmul_factor_t; 183 184 void ?*=?( string & s, strmul_factor_t factor ); 185 string ?*?( char c, strmul_factor_t factor ); // not backwards compatible 186 string ?*?( string s, strmul_factor_t factor ); 187 string ?*?( const char * s, strmul_factor_t factor ); 188 static inline string ?*?( strmul_factor_t factor, char s ) { return s * factor; } 189 static inline string ?*?( strmul_factor_t factor, string s ) { return s * factor; } 190 static inline string ?*?( strmul_factor_t factor, const char * s ) { return s * factor; } 185 191 186 192 // Character access -
tests/Makefile.am
r3f631d6 r570e7ad 288 288 -cp ${test} ${abspath ${@}} 289 289 290 collections/string-operator-ERR01 : collections/string-operator.cfa 291 ${CFACOMPILE_SYNTAX} -DTRY_MR01 292 -cp ${test} ${abspath ${@}} 293 294 collections/string-operator-ERR02 : collections/string-operator.cfa 295 ${CFACOMPILE_SYNTAX} -DTRY_MR02 296 -cp ${test} ${abspath ${@}} 297 298 collections/string-operator-ERR03 : collections/string-operator.cfa 299 ${CFACOMPILE_SYNTAX} -DTRY_MR03 300 -cp ${test} ${abspath ${@}} 301 302 collections/string-operator-ERR04 : collections/string-operator.cfa 303 ${CFACOMPILE_SYNTAX} -DTRY_MR04 304 -cp ${test} ${abspath ${@}} 305 306 collections/string-operator-ERR05 : collections/string-operator.cfa 307 ${CFACOMPILE_SYNTAX} -DTRY_MR05 308 -cp ${test} ${abspath ${@}} 309 310 collections/string-operator-ERR06 : collections/string-operator.cfa 311 ${CFACOMPILE_SYNTAX} -DTRY_MR06 312 -cp ${test} ${abspath ${@}} 313 314 collections/string-operator-ERR07 : collections/string-operator.cfa 315 ${CFACOMPILE_SYNTAX} -DTRY_MR07 316 -cp ${test} ${abspath ${@}} 317 318 collections/string-operator-ERR08 : collections/string-operator.cfa 319 ${CFACOMPILE_SYNTAX} -DTRY_MR08 320 -cp ${test} ${abspath ${@}} 321 290 322 collections/string-operator-ERR09 : collections/string-operator.cfa 291 323 ${CFACOMPILE_SYNTAX} -DTRY_MR09 292 324 -cp ${test} ${abspath ${@}} 293 325 326 collections/string-operator-ERR10 : collections/string-operator.cfa 327 ${CFACOMPILE_SYNTAX} -DTRY_MR10 328 -cp ${test} ${abspath ${@}} 329 330 collections/string-operator-ERR11 : collections/string-operator.cfa 331 ${CFACOMPILE_SYNTAX} -DTRY_MR11 332 -cp ${test} ${abspath ${@}} 333 334 collections/string-operator-ERR13 : collections/string-operator.cfa 335 ${CFACOMPILE_SYNTAX} -DTRY_MR13 336 -cp ${test} ${abspath ${@}} 337 294 338 collections/string-operator-ERR15 : collections/string-operator.cfa 295 339 ${CFACOMPILE_SYNTAX} -DTRY_MR15 340 -cp ${test} ${abspath ${@}} 341 342 collections/string-operator-ERR16 : collections/string-operator.cfa 343 ${CFACOMPILE_SYNTAX} -DTRY_MR16 296 344 -cp ${test} ${abspath ${@}} 297 345 -
tests/collections/.expect/string-operator.txt
r3f631d6 r570e7ad 3 3 4 4 ------------- Initialization 5 Ã 5 (skip) 6 6 ab 7 7 ab 8 8 ab 9 9 10 Ãx 10 (skip) 11 11 abx 12 12 abx … … 23 23 axb 24 24 25 aaa 25 (skip) 26 26 bbb 27 ÃÃÃ 27 585 28 28 cdcdcd 29 29 30 291 30 (skip) 31 31 bbb 32 ababab 32 585 33 33 cdcdcd 34 34 35 35 ------------- Assignment 36 Ã 36 (skip) 37 37 ab 38 38 ab 39 39 ab 40 40 41 Ã 42 ab Ã43 abab Ã44 ababab Ã41 (skip) 42 ab 43 abab 44 ababab 45 45 46 46 ab … … 54 54 aaaabbbb 55 55 56 aaa 56 (skip) 57 57 bbb 58 ÃÃÃ 58 585 59 59 cdcdcd 60 60 61 291 61 (skip) 62 62 bbb 63 ababab 63 585 64 64 cdcdcd 65 65 … … 70 70 ab 71 71 72 Ãx 72 (skip) 73 73 abx 74 74 abx … … 85 85 axb 86 86 87 291 87 (skip) 88 88 bbb 89 89 585 90 90 cdcdcd 91 91 92 291 92 (skip) 93 93 bbb 94 94 585 … … 97 97 ------------- Miscellany 98 98 (skip) 99 291 99 (skip) 100 100 0x2a 0x2d -
tests/collections/string-operator.cfa
r3f631d6 r570e7ad 9 9 10 10 // These MR points do reject in the current revision, so they have satellite "-ERR" cases: 11 // MR01 12 // MR02 13 // MR03 14 // MR04 15 // MR05 16 // MR06 17 // MR07 18 // MR08 11 19 // MR09 20 // MR10 21 // MR11 22 // MR13 12 23 // MR15 24 // MR16 13 25 14 26 // These MR points do not reject in the current revision, so they join the "happy run": 15 #define TRY_MR0116 #define TRY_MR0217 #define TRY_MR0318 #define TRY_MR0419 #define TRY_MR0520 #define TRY_MR0621 #define TRY_MR0722 #define TRY_MR0823 #define TRY_MR1024 #define TRY_MR1125 27 #define TRY_MR12 26 #define TRY_MR1327 28 #define TRY_MR14 28 #define TRY_MR1629 29 30 30 … … 137 137 138 138 sout | "------------- Initialization"; 139 MR01( {string s = 'a' + 'b'; // Ãb139 MR01( {string s = 'a' + 'b'; // (ambiguous) 140 140 sout | s;} ) 141 141 {string s = 'a' + "b"; // ab … … 149 149 string s0 = "x"; 150 150 151 MR02( {string s = 'a' + 'b' + s0; // Ãx151 MR02( {string s = 'a' + 'b' + s0; // (ambiguous) 152 152 sout | s;} ) 153 153 {string s = 'a' + "b" + s0; // abx … … 179 179 sout | nl; // 180 180 181 MR03( {string s = 'a' * 3; // aaa181 MR03( {string s = 'a' * 3; // (ambiguous) 182 182 sout | s;} ) 183 183 {string s = "b" * 3; // bbb 184 184 sout | s;} 185 {string s = ('a' + 'b') * 3; // ÃÃÃ 185 {string s = ('a' + 'b') * 3; // ÃÃÃ (expecting ambiguous, likely from #309) 186 186 sout | s;} 187 187 {string s = ('c' + "d") * 3; // cdcdcd … … 189 189 sout | nl; // 190 190 191 MR04( {string s = 3 * 'a'; // 291191 MR04( {string s = 3 * 'a'; // (ambiguous) 192 192 sout | s;} ) 193 193 {string s = 3 * "b"; // bbb … … 205 205 206 206 s = ""; 207 MR05( s = 'a' + 'b'; // Ã207 MR05( s = 'a' + 'b'; // (ambiguous) 208 208 sout | s; ) 209 209 s = 'a' + "b"; // ab … … 216 216 217 217 s = ""; 218 MR06( s = 'a' + 'b' + s; // Ã218 MR06( s = 'a' + 'b' + s; // (ambiguous) 219 219 sout | s; ) 220 s = 'a' + "b" + s; // ab Ã221 sout | s; 222 s = "a" + 'b' + s; // abab Ã223 sout | s; 224 s = "a" + "b" + s; // ababab Ã220 s = 'a' + "b" + s; // ab 221 sout | s; 222 s = "a" + 'b' + s; // abab 223 sout | s; 224 s = "a" + "b" + s; // ababab 225 225 sout | s; 226 226 sout | nl; // … … 249 249 250 250 s = ""; 251 MR07( s = 'a' * 3; // aaa251 MR07( s = 'a' * 3; // (ambiguous) 252 252 sout | s; ) 253 253 s = "b" * 3; // bbb 254 254 sout | s; 255 s = ('a' + 'b') * 3; // ÃÃÃ 255 s = ('a' + 'b') * 3; // ÃÃÃ (expecting ambiguous, likely from #309) 256 256 sout | s; 257 257 s = ('c' + "d") * 3; // cdcdcd … … 260 260 261 261 s = ""; 262 MR08( s = 3 * 'a'; // 291262 MR08( s = 3 * 'a'; // (ambiguous) 263 263 sout | s; ) 264 264 s = 3 * "b"; // bbb … … 281 281 sout | nl; // 282 282 283 MR10( sout | 'a' + 'b' + s; ) // Ãx283 MR10( sout | 'a' + 'b' + s; ) // (ambiguous) 284 284 sout | 'a' + "b" + s; // abx 285 285 sout | "a" + 'b' + s; // abx … … 299 299 sout | nl; // 300 300 301 MR11( sout | 'a' * 3; ) // 291301 MR11( sout | 'a' * 3; ) // (ambiguous) 302 302 sout | "b" * 3; // bbb 303 MR12( sout | ('a' + 'b') * 3; ) // 585 303 MR12( sout | ('a' + 'b') * 3; ) // 585 (expecting ambiguous, likely from #309) 304 304 sout | ('c' + "d") * 3; // cdcdcd 305 305 sout | nl; // 306 306 307 MR13( sout | 3 * 'a'; ) // 291307 MR13( sout | 3 * 'a'; ) // (ambiguous) 308 308 sout | 3 * "b"; // bbb 309 MR14( sout | 3 * ('a' + 'b'); ) // 585 309 MR14( sout | 3 * ('a' + 'b'); ) // 585 (expecting ambiguous, likely from #309) 310 310 sout | 3 * ('c' + "d"); // cdcdcd 311 311 sout | nl; // … … 316 316 317 317 MR15( printf( "%c\n", 'a' + 'b'); ) // (ambiguous) 318 MR16( printf( "%d\n", 'a' * 3 ); ) // 291318 MR16( printf( "%d\n", 'a' * 3 ); ) // (ambiguous) 319 319 320 320 { // (picks arithmetic; there is no interpretation of `_ + 3` that's string)
Note:
See TracChangeset
for help on using the changeset viewer.