- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/collections/string_res.hfa
re8b3717 r416b443 10 10 // Created On : Fri Sep 03 11:00:00 2021 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jan 4 11:28:06 202413 // Update Count : 2 712 // Last Modified On : Sat Aug 12 15:45:47 2023 13 // Update Count : 2 14 14 // 15 15 … … 70 70 71 71 // Getters 72 size_t size(const string_res & 72 size_t size(const string_res &s); 73 73 74 74 // Constructors, Assignment Operators, Destructor 75 void ?{}(string_res & 76 void ?{}(string_res & s, const char* buffer, size_t bsize); // copy specific length from buffer77 static inline void ?{}(string_res & s, const char* rhs) { // copy from string literal (NULL-terminated)75 void ?{}(string_res &s); // empty string 76 void ?{}(string_res &s, const char* buffer, size_t bsize); // copy specific length from buffer 77 static inline void ?{}(string_res &s, const char* rhs) { // copy from string literal (NULL-terminated) 78 78 (s){ rhs, strlen(rhs) }; 79 79 } 80 static inline void ?{}(string_res & s, char c ) { 81 ?{}( s, &c, 1); 82 } 83 84 // Deleting the copy constructors makes the compiler reject an attempt to call/return by value 85 void ?{}(string_res & s, const string_res & s2) = void; 86 void ?{}(string_res & s, string_res & s2) = void; 80 81 void ?{}(string_res &s, const string_res & s2) = void; 82 void ?{}(string_res &s, string_res & s2) = void; 87 83 88 84 enum StrResInitMode { COPY_VALUE, SHARE_EDITS }; 89 void ?{}(string_res & s, const string_res & src, StrResInitMode, size_t start, size_t len);90 static inline void ?{}(string_res & 85 void ?{}(string_res &s, const string_res & src, StrResInitMode, size_t start, size_t end ); 86 static inline void ?{}(string_res &s, const string_res & src, StrResInitMode mode ) { 91 87 ?{}( s, src, mode, 0, size(src)); 92 88 } 93 static inline void ?{}(string_res & s, const string_res & src, StrResInitMode mode, size_t maxlen ) { 94 ?{}( s, src, mode, 0, (size(src) > maxlen)?maxlen:size(src) ); 95 } 96 97 string_res & assign(string_res & s, const string_res & src, size_t maxlen); // copy specific length from other string 98 string_res & assign(string_res & s, const char * buffer, size_t bsize); // copy specific length from buffer 99 static inline string_res & ?=?(string_res & s, const char * c) { // copy from string literal (NULL-terminated) 100 return assign(s, c, strlen(c)); 101 } 102 string_res & ?=?(string_res & s, const string_res & c); 103 string_res & ?=?(string_res & s, string_res & c); 104 string_res & ?=?(string_res & s, char c); 105 106 void ^?{}(string_res & s); 89 90 string_res & assign(string_res &s, const char* buffer, size_t bsize); // copy specific length from buffer 91 static inline string_res & ?=?(string_res &s, const char* other) { // copy from string literal (NULL-terminated) 92 return assign(s, other, strlen(other)); 93 } 94 string_res & ?=?(string_res &s, const string_res &other); 95 string_res & ?=?(string_res &s, string_res &other); 96 string_res & ?=?(string_res &s, char other); 97 98 void ^?{}(string_res &s); 107 99 108 100 // IO Operator 109 ofstream & ?|?(ofstream & out, const string_res &s);110 void ?|?(ofstream & out, const string_res &s);111 ifstream & ?|?(ifstream & in, string_res &s);112 void ?|?( ifstream & in, string_res & s );101 ofstream & ?|?(ofstream &out, const string_res &s); 102 void ?|?(ofstream &out, const string_res &s); 103 ifstream & ?|?(ifstream &in, string_res &s); 104 void ?|?( ifstream & in, string_res & this ); 113 105 114 106 struct _Istream_Rstr { … … 121 113 _Istream_Rstr wdi( unsigned int rwd, string_res & s ) { return (_Istream_Rstr)@{ &s, {{0p}, rwd, {.flags.rwd : true}} }; } 122 114 _Istream_Rstr getline( string_res & s, const char delimiter = '\n' ) { 123 return (_Istream_Rstr)@{ &s, {{.delimiter s: { delimiter, '\0' } }, -1, {.flags.delimiter : true, .flags.inex : true}} };115 return (_Istream_Rstr)@{ &s, {{.delimiter : { delimiter, '\0' } }, -1, {.flags.delimiter : true, .flags.inex : true}} }; 124 116 } 125 117 _Istream_Rstr & getline( _Istream_Rstr & fmt, const char delimiter = '\n' ) { 126 fmt.delimiter s[0] = delimiter; fmt.delimiters[1] = '\0'; fmt.flags.delimiter = true; fmt.flags.inex = true; return fmt;118 fmt.delimiter[0] = delimiter; fmt.delimiter[1] = '\0'; fmt.flags.delimiter = true; fmt.flags.inex = true; return fmt; 127 119 } 128 120 _Istream_Rstr incl( const char scanset[], string_res & s ) { return (_Istream_Rstr)@{ &s, {{scanset}, -1, {.flags.inex : false}} }; } … … 137 129 138 130 // Concatenation 139 void ?+=?(string_res & s, const string_res & s2); 140 void ?+=?(string_res & s, char c); 141 void append(string_res & s, const string_res & s2, size_t maxlen); 142 void ?+=?(string_res & s, const char * c); 143 void append(string_res & s, const char * buffer, size_t bsize); 144 145 static inline string_res & strcat(string_res & s, const string_res & s2) { s += s2; return s; } 146 static inline string_res & strcat(string_res & s, const char * c) { s += c; return s; } 147 static inline string_res & strncat(string_res & s, const string_res & s2, size_t maxlen) { append(s, s2, maxlen); return s; } 148 static inline string_res & strncat(string_res & s, const char * buffer, size_t bsize) { append(s, buffer, bsize); return s; } 149 150 // Repetition 151 void ?*=?(string_res & s, size_t factor); 131 void append(string_res &s, const char* buffer, size_t bsize); 132 void ?+=?(string_res &s, char other); // 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* other) { 135 append( s, other, strlen(other) ); 136 } 152 137 153 138 // Character access 154 void assignAt(const string_res & 155 char ?[?](const string_res & 156 //char codePointAt(const string_res & 139 void assignAt(const string_res &s, size_t index, char val); 140 char ?[?](const string_res &s, size_t index); // Mike changed to ret by val from Sunjay's ref, to match Peter's 141 //char codePointAt(const string_res &s, size_t index); // revisit under Unicode 157 142 158 143 // Comparisons 159 int strcmp (const string_res &, const string_res &);144 int cmp (const string_res &, const string_res &); 160 145 bool ?==?(const string_res &, const string_res &); 161 146 bool ?!=?(const string_res &, const string_res &); … … 165 150 bool ?<? (const string_res &, const string_res &); 166 151 167 int strcmp(const string_res &, const char*);168 bool ?==?(const string_res &, const char 169 bool ?!=?(const string_res &, const char 170 bool ?>? (const string_res &, const char 171 bool ?>=?(const string_res &, const char 172 bool ?<=?(const string_res &, const char 173 bool ?<? (const string_res &, const char 174 175 int strcmp(const char*, const string_res &);176 bool ?==?(const char 177 bool ?!=?(const char 178 bool ?>? (const char 179 bool ?>=?(const char 180 bool ?<=?(const char 181 bool ?<? (const char 152 int cmp (const string_res &, const char*); 153 bool ?==?(const string_res &, const char*); 154 bool ?!=?(const string_res &, const char*); 155 bool ?>? (const string_res &, const char*); 156 bool ?>=?(const string_res &, const char*); 157 bool ?<=?(const string_res &, const char*); 158 bool ?<? (const string_res &, const char*); 159 160 int cmp (const char*, const string_res &); 161 bool ?==?(const char*, const string_res &); 162 bool ?!=?(const char*, const string_res &); 163 bool ?>? (const char*, const string_res &); 164 bool ?>=?(const char*, const string_res &); 165 bool ?<=?(const char*, const string_res &); 166 bool ?<? (const char*, const string_res &); 182 167 183 168 // String search 184 bool contains(const string_res & 185 186 int find(const string_res & 187 int find(const string_res & s, const string_res &search);188 int find(const string_res & s, const char* search);189 int find(const string_res & s, const char* search, size_t searchsize);190 191 int findFrom(const string_res & 192 int findFrom(const string_res & s, size_t fromPos, const string_res &search);193 int findFrom(const string_res & s, size_t fromPos, const char* search);194 int findFrom(const string_res & s, size_t fromPos, const char* search, size_t searchsize);195 196 bool includes(const string_res & s, const string_res &search);197 bool includes(const string_res & s, const char* search);198 bool includes(const string_res & s, const char* search, size_t searchsize);199 200 bool startsWith(const string_res & s, const string_res &prefix);201 bool startsWith(const string_res & s, const char* prefix);202 bool startsWith(const string_res & s, const char* prefix, size_t prefixsize);203 204 bool endsWith(const string_res & s, const string_res &suffix);205 bool endsWith(const string_res & s, const char* suffix);206 bool endsWith(const string_res & s, const char* suffix, size_t suffixsize);207 208 int include(const string_res & s, const charclass_res &mask);209 int exclude(const string_res & s, const charclass_res &mask);169 bool contains(const string_res &s, char ch); // single character 170 171 int find(const string_res &s, char search); 172 int find(const string_res &s, const string_res &search); 173 int find(const string_res &s, const char* search); 174 int find(const string_res &s, const char* search, size_t searchsize); 175 176 int findFrom(const string_res &s, size_t fromPos, char search); 177 int findFrom(const string_res &s, size_t fromPos, const string_res &search); 178 int findFrom(const string_res &s, size_t fromPos, const char* search); 179 int findFrom(const string_res &s, size_t fromPos, const char* search, size_t searchsize); 180 181 bool includes(const string_res &s, const string_res &search); 182 bool includes(const string_res &s, const char* search); 183 bool includes(const string_res &s, const char* search, size_t searchsize); 184 185 bool startsWith(const string_res &s, const string_res &prefix); 186 bool startsWith(const string_res &s, const char* prefix); 187 bool startsWith(const string_res &s, const char* prefix, size_t prefixsize); 188 189 bool endsWith(const string_res &s, const string_res &suffix); 190 bool endsWith(const string_res &s, const char* suffix); 191 bool endsWith(const string_res &s, const char* suffix, size_t suffixsize); 192 193 int include(const string_res &s, const charclass_res &mask); 194 int exclude(const string_res &s, const charclass_res &mask); 210 195 211 196 // Modifiers 212 void padStart(string_res & 213 void padStart(string_res & 214 void padEnd(string_res & 197 void padStart(string_res &s, size_t n); 198 void padStart(string_res &s, size_t n, char padding); 199 void padEnd(string_res &s, size_t n); 215 200 void padEnd(string_res &s, size_t n, char padding); 216 201
Note:
See TracChangeset
for help on using the changeset viewer.