Changeset e891349
- Timestamp:
- Jan 17, 2024, 2:16:04 PM (12 months ago)
- Branches:
- master
- Children:
- 5bf685f
- Parents:
- 06280ad
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/collections/string.cfa
r06280ad re891349 103 103 } 104 104 105 void assign(string & s, const string & c, size_t n) { 106 assign(*s.inner, *c.inner, n); 107 } 108 void assign(string & s, const char * c, size_t n) { 109 assign(*s.inner, c, n); 110 } 111 105 112 106 113 //////////////////////////////////////////////////////// … … 205 212 } 206 213 214 void append(string & s, const string & s2, size_t maxlen) { 215 append( (*s.inner), (*s2.inner), maxlen ); 216 } 217 207 218 void ?+=?(string & s, const char * c) { 208 219 (*s.inner) += c; 220 } 221 222 void append(string & s, const char * buffer, size_t bsize) { 223 append( (*s.inner), buffer, bsize ); 209 224 } 210 225 -
libcfa/src/collections/string.hfa
r06280ad re891349 36 36 void ?{}(string & s, string & s2); 37 37 38 void ?{}(string & s, c onst char);38 void ?{}(string & s, char); 39 39 void ?{}(string & s, const char * c); // copy from string literal (NULL-terminated) 40 40 void ?{}(string & s, const char * c, size_t size); // copy specific length from buffer 41 41 42 42 void ?=?(string & s, const char * c); // copy assignment from literal 43 static inline string & strcpy(string & s, const char * c) { s = c; return s; }44 static inline string & strncpy(string & s, const char * c, size_t n) { s = c; return s; }45 43 void ?=?(string & s, const string & c); 46 static inline string & strcpy(string & s, const string c) { s = c; return s; }47 44 void ?=?(string & s, char c); 48 45 string & ?=?(string & s, string & c); // surprising ret seems to help avoid calls to autogen 46 void assign(string & s, const string & c, size_t n); 47 void assign(string & s, const char * c, size_t n); 49 48 //string ?=?( string &, string ) = void; 49 50 static inline string & strcpy(string & s, const char * c) { s = c; return s; } 51 static inline string & strncpy(string & s, const char * c, size_t n) { assign( s, c, n); return s; } 52 static inline string & strcpy(string & s, const string & c) { s = c; return s; } 53 static inline string & strncpy(string & s, const string & c, size_t n) { assign(s, c, n); return s; } 54 50 55 void ^?{}(string & s); 51 56 … … 104 109 void ?+=?(string & s, char c); // append a character 105 110 void ?+=?(string & s, const string & s2); // append-concatenate to first string 106 static inline string & strcat(string & s, const string & s2) { s += s2; return s; } 107 void ?+=?(string & s, const char * s2); // append-concatenate to first string 108 static inline string & strcat(string & s, const char * c) { s += c; return s; } 111 void append(string & s, const string & s2, size_t maxlen); // append-concatenate to first string, up to maxlen 112 void ?+=?(string & s, const char * s2); // append-concatenate NULL-terminated string to first string 113 void append(string & s, const char * buffer, size_t bsize); // append-concatenate given range to first string 114 109 115 string ?+?(const string & s, char c); // add a character to a copy of the string 110 116 string ?+?(const string & s, const string & s2); // copy and concatenate both strings 111 string ?+?(const char * s1, const char * s2); // co ncatenate both strings117 string ?+?(const char * s1, const char * s2); // copy and concatenate both strings 112 118 string ?+?(const string & s, const char * c); // copy and concatenate with NULL-terminated string 119 120 static inline string & strcat(string & s, const string & s2) { s += s2; return s; } 121 static inline string & strcat(string & s, const char * c) { s += c; return s; } 122 static inline string & strncat(string & s, const string & s2, size_t maxlen) { append(s, s2, maxlen); return s; } 123 static inline string & strncat(string & s, const char * buffer, size_t bsize) { append(s, buffer, bsize); return s; } 113 124 114 125 // Repetition -
libcfa/src/collections/string_res.cfa
r06280ad re891349 563 563 } 564 564 565 string_res & assign(string_res & s, const string_res & src, size_t maxlen) { 566 return assign_(s, src.Handle.s, min(src.Handle.lnth, maxlen), *0p); 567 } 568 565 569 string_res & assign(string_res & s, const char * buffer, size_t bsize) { 566 570 return assign_(s, buffer, bsize, *0p); … … 637 641 } 638 642 643 void append(string_res & str1, const string_res & str2, size_t maxlen) { 644 append( str1, str2.Handle.s, min(str2.Handle.lnth, maxlen) ); 645 } 646 639 647 void ?+=?(string_res & s, char c) { 640 648 append( s, & c, 1 ); 641 649 } 642 650 void ?+=?(string_res & s, const char * c) { 651 append( s, c, strlen(c) ); 652 } 643 653 644 654 /////////////////////////////////////////////////////////////////// -
libcfa/src/collections/string_res.hfa
r06280ad re891349 88 88 } 89 89 90 string_res & assign(string_res & s, const string_res & src, size_t maxlen); // copy specific length from other string 90 91 string_res & assign(string_res & s, const char * buffer, size_t bsize); // copy specific length from buffer 91 92 static inline string_res & ?=?(string_res & s, const char * c) { // copy from string literal (NULL-terminated) … … 129 130 130 131 // Concatenation 132 void ?+=?(string_res & s, const string_res & s2); 133 void ?+=?(string_res & s, char c); 134 void append(string_res & s, const string_res & s2, size_t maxlen); 135 void ?+=?(string_res & s, const char * c); 131 136 void append(string_res & s, const char * buffer, size_t bsize); 132 void ?+=?(string_res & s, char c); // append a character 133 void ?+=?(string_res & s, const string_res & s2); // append-concatenate to first string 134 static inline void ?+=?(string_res & s, const char * c) {135 append( s, c, strlen(c) ); 136 }137 138 static inline string_res & strcat(string_res & s, const string_res & s2) { s += s2; return s; } 139 static inline string_res & strcat(string_res & s, const char * c) { s += c; return s; } 140 static inline string_res & strncat(string_res & s, const string_res & s2, size_t maxlen) { append(s, s2, maxlen); return s; } 141 static inline string_res & strncat(string_res & s, const char * buffer, size_t bsize) { append(s, buffer, bsize); return s; } 137 142 138 143 // Repetition -
tests/collections/.expect/string-api-coverage.txt
r06280ad re891349 20 20 hello 21 21 world 22 1234567 23 hello 24 Q 25 123 26 hell 27 1234567 28 hello 29 123 30 hell 22 31 5 23 32 helloworld … … 29 38 hello, friend 30 39 bye, friend 40 ohello 41 ohell 42 ohell 43 omydarling 44 omy 45 omy 31 46 hellohellohellohello 32 47 hellohellohello -
tests/collections/string-api-coverage.cfa
r06280ad re891349 90 90 } 91 91 assertWellFormedHandleList( 10 ); 92 // 93 // Assignments 94 // 95 { 96 string b = "xxx"; 97 98 b = "1234567"; 99 sout | b; // 1234567 100 101 b = "xxx"; 102 b = s; 103 sout | b; // hello 104 105 b = "xxx"; 106 b = 'Q'; 107 sout | b; // Q 108 109 b = "xxx"; 110 assign( b, "1234567", 3 ); 111 sout | b; // 123 112 113 b = "xxx"; 114 assign( b, s, 4 ); 115 sout | b; // hell 116 117 b = "xxx"; 118 strcpy(b, "1234567"); 119 sout | b; // 1234567 120 121 b = "xxx"; 122 strcpy(b, s); 123 sout | b; // hello 124 125 b = "xxx"; 126 strncpy( b, "1234567", 3 ); 127 sout | b; // 123 128 129 b = "xxx"; 130 strncpy( b, s, 4 ); 131 sout | b; // hell 132 } 133 assertWellFormedHandleList( 10 ); 134 135 92 136 93 137 sout | size(s); // 5 … … 125 169 sx = "bye, " + "friend"; 126 170 sout | sx; // bye, friend 171 172 sx = "o"; 173 strcat( sx, s ); 174 sout | sx; // ohello 175 176 sx = "o"; 177 append( sx, s, 4 ); 178 sout | sx; // ohell 179 180 sx = "o"; 181 strncat( sx, s, 4 ); 182 sout | sx; // ohell 183 184 sx = "o"; 185 strcat( sx, "mydarling" ); 186 sout | sx; // omydarling 187 188 sx = "o"; 189 append( sx, "mydarling", 2 ); 190 sout | sx; // omy 191 192 sx = "o"; 193 strncat( sx, "mydarling", 2 ); 194 sout | sx; // omy 127 195 128 196 //
Note: See TracChangeset
for help on using the changeset viewer.