Changeset f2898df
- Timestamp:
- Jan 19, 2024, 5:25:28 PM (11 months ago)
- Branches:
- master
- Children:
- 8abe4090, a4ed165
- Parents:
- dd10bf4
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/collections/string.cfa
rdd10bf4 rf2898df 70 70 } 71 71 72 void ?{}( string & s, ssize_t rhs ) { 73 (s.inner) { malloc() }; 74 ?{}( *s.inner, rhs ); 75 } 76 77 void ?{}( string & s, size_t rhs ) { 78 (s.inner) { malloc() }; 79 ?{}( *s.inner, rhs ); 80 } 81 82 void ?{}( string & s, double rhs ) { 83 (s.inner) { malloc() }; 84 ?{}( *s.inner, rhs ); 85 } 86 87 void ?{}( string & s, long double rhs ) { 88 (s.inner) { malloc() }; 89 ?{}( *s.inner, rhs ); 90 } 91 92 void ?{}( string & s, double _Complex rhs ) { 93 (s.inner) { malloc() }; 94 ?{}( *s.inner, rhs ); 95 } 96 97 void ?{}( string & s, long double _Complex rhs ) { 98 (s.inner) { malloc() }; 99 ?{}( *s.inner, rhs ); 100 } 101 72 102 void ^?{}( string & s ) { 73 103 ^(*s.inner){}; … … 121 151 } 122 152 153 string & ?=?( string & s, ssize_t rhs ) { 154 (*s.inner) = rhs; 155 return s; 156 } 157 158 string & ?=?( string & s, size_t rhs ) { 159 (*s.inner) = rhs; 160 return s; 161 } 162 163 string & ?=?( string & s, double rhs ) { 164 (*s.inner) = rhs; 165 return s; 166 } 167 168 string & ?=?( string & s, long double rhs ) { 169 (*s.inner) = rhs; 170 return s; 171 } 172 173 string & ?=?( string & s, double _Complex rhs ) { 174 (*s.inner) = rhs; 175 return s; 176 } 177 178 string & ?=?( string & s, long double _Complex rhs ) { 179 (*s.inner) = rhs; 180 return s; 181 } 123 182 124 183 //////////////////////////////////////////////////////// -
libcfa/src/collections/string.hfa
rdd10bf4 rf2898df 40 40 void ?{}(string & s, const char * c); // copy from string literal (NULL-terminated) 41 41 void ?{}(string & s, const char * c, size_t size); // copy specific length from buffer 42 43 void ?{}( string & s, ssize_t rhs ); 44 void ?{}( string & s, size_t rhs ); 45 void ?{}( string & s, double rhs ); 46 void ?{}( string & s, long double rhs ); 47 void ?{}( string & s, double _Complex rhs ); 48 void ?{}( string & s, long double _Complex rhs ); 42 49 43 50 string & ?=?(string & s, const string & c); … … 52 59 static inline string & strcpy(string & s, const string & c) { s = c; return s; } 53 60 static inline string & strncpy(string & s, const string & c, size_t n) { assign(s, c, n); return s; } 61 62 string & ?=?( string & s, ssize_t rhs ); 63 string & ?=?( string & s, size_t rhs ); 64 string & ?=?( string & s, double rhs ); 65 string & ?=?( string & s, long double rhs ); 66 string & ?=?( string & s, double _Complex rhs ); 67 string & ?=?( string & s, long double _Complex rhs ); 54 68 55 69 void ^?{}(string & s); -
libcfa/src/collections/string_res.cfa
rdd10bf4 rf2898df 25 25 26 26 #include <assert.h> 27 #include <complex.h> // creal, cimag 27 28 28 29 //######################### VbyteHeap "header" ######################### … … 333 334 void ?{}(string_res & s, const char * rhs, size_t rhslnth) with(s) { 334 335 eagerCopyCtorHelper(s, rhs, rhslnth); 336 } 337 338 void ?{}( string_res & s, ssize_t rhs ) { 339 char buf[64]; 340 int len; 341 snprintf( buf, sizeof(buf)-1, "%zd%n", rhs, &len ); 342 ( s ){ buf, len }; 343 } 344 void ?{}( string_res & s, size_t rhs ) { 345 char buf[64]; 346 int len; 347 snprintf( buf, sizeof(buf)-1, "%zu%n", rhs, &len ); 348 ( s ){ buf, len }; 349 } 350 void ?{}( string_res & s, double rhs ) { 351 char buf[64]; 352 int len; 353 snprintf( buf, sizeof(buf)-1, "%g%n", rhs, &len ); 354 ( s ){ buf, len }; 355 } 356 void ?{}( string_res & s, long double rhs ) { 357 char buf[64]; 358 int len; 359 snprintf( buf, sizeof(buf)-1, "%Lg%n", rhs, &len ); 360 ( s ){ buf, len }; 361 } 362 void ?{}( string_res & s, double _Complex rhs ) { 363 char buf[64]; 364 int len; 365 snprintf( buf, sizeof(buf)-1, "%g+%gi%n", creal( rhs ), cimag( rhs ), &len ); 366 ( s ){ buf, len }; 367 } 368 void ?{}( string_res & s, long double _Complex rhs ) { 369 char buf[64]; 370 int len; 371 snprintf( buf, sizeof(buf)-1, "%Lg+%Lgi%n", creall( rhs ), cimagl( rhs ), &len ); 372 ( s ){ buf, len }; 335 373 } 336 374 … … 577 615 } 578 616 617 string_res & ?=?( string_res & s, ssize_t rhs ) { 618 string_res rhs2 = rhs; 619 s = rhs2; 620 return s; 621 } 622 string_res & ?=?( string_res & s, size_t rhs ) { 623 string_res rhs2 = rhs; 624 s = rhs2; 625 return s; 626 } 627 string_res & ?=?( string_res & s, double rhs ) { 628 string_res rhs2 = rhs; 629 s = rhs2; 630 return s; 631 } 632 string_res & ?=?( string_res & s, long double rhs ) { 633 string_res rhs2 = rhs; 634 s = rhs2; 635 return s; 636 } 637 string_res & ?=?( string_res & s, double _Complex rhs ) { 638 string_res rhs2 = rhs; 639 s = rhs2; 640 return s; 641 } 642 string_res & ?=?( string_res & s, long double _Complex rhs ) { 643 string_res rhs2 = rhs; 644 s = rhs2; 645 return s; 646 } 647 579 648 // Copy assignment operator 580 649 string_res & ?=?(string_res & s, const string_res & rhs) with( s ) { -
libcfa/src/collections/string_res.hfa
rdd10bf4 rf2898df 94 94 ?{}( s, src, mode, 0, (size(src) > maxlen)?maxlen:size(src) ); 95 95 } 96 void ?{}( string_res & s, ssize_t rhs ); 97 void ?{}( string_res & s, size_t rhs ); 98 void ?{}( string_res & s, double rhs ); 99 void ?{}( string_res & s, long double rhs ); 100 void ?{}( string_res & s, double _Complex rhs ); 101 void ?{}( string_res & s, long double _Complex rhs ); 96 102 97 103 string_res & assign(string_res & s, const string_res & src, size_t maxlen); // copy specific length from other string … … 103 109 string_res & ?=?(string_res & s, string_res & c); 104 110 string_res & ?=?(string_res & s, char c); 111 112 string_res & ?=?( string_res & s, ssize_t rhs ); 113 string_res & ?=?( string_res & s, size_t rhs ); 114 string_res & ?=?( string_res & s, double rhs ); 115 string_res & ?=?( string_res & s, long double rhs ); 116 string_res & ?=?( string_res & s, double _Complex rhs ); 117 string_res & ?=?( string_res & s, long double _Complex rhs ); 105 118 106 119 void ^?{}(string_res & s); -
tests/collections/.expect/string-api-coverage.txt
rdd10bf4 rf2898df 23 23 world 24 24 Q 25 42 26 -42 27 5.5 28 5.5 29 5.5+3.4i 30 5.5+3.4i 25 31 1234567 26 32 hello … … 32 38 123 33 39 hell 40 42 41 -42 42 5.5 43 5.5 44 5.5+3.4i 45 5.5+3.4i 34 46 5 35 47 helloworld -
tests/collections/string-api-coverage.cfa
rdd10bf4 rf2898df 98 98 sout | b5; // Q 99 99 100 100 string b6 = 42; 101 sout | b6; // 42 102 103 string b7 = -42; 104 sout | b7; // -42 105 106 string b8 = 5.5; 107 sout | b8; // 5.5 108 109 string b9 = 5.5L; 110 sout | b9; // 5.5 111 112 string b10 = 5.5+3.4i; 113 sout | b10; // 5.5+3.4i 114 115 string b11 = 5.5L+3.4Li; 116 sout | b11; // 5.5+3.4i 101 117 } 102 118 assertWellFormedHandleList( 10 ); … … 141 157 strncpy( b, s, 4 ); 142 158 sout | b; // hell 159 160 b = 42; 161 sout | b; // 42 162 163 b = -42; 164 sout | b; // -42 165 166 b = 5.5; 167 sout | b; // 5.5 168 169 b = 5.5L; 170 sout | b; // 5.5 171 172 b = 5.5+3.4i; 173 sout | b; // 5.5+3.4i 174 175 b = 5.5L+3.4Li; 176 sout | b; // 5.5+3.4i 143 177 } 144 178 assertWellFormedHandleList( 10 );
Note: See TracChangeset
for help on using the changeset viewer.