45 #ifndef AGS_SHARED_UTIL_STRING_H 46 #define AGS_SHARED_UTIL_STRING_H 48 #include "common/str.h" 50 #include "common/std/vector.h" 51 #include "ags/shared/core/platform.h" 52 #include "ags/shared/core/types.h" 62 static const size_t NoIndex = (size_t)-1;
73 String(
const char *cstr,
size_t length);
75 String(
char c,
size_t count);
81 inline const char *GetCStr()
const {
85 inline size_t GetLength()
const {
89 inline bool IsEmpty()
const {
93 bool IsNullOrSpace()
const;
96 #if defined(AGS_PLATFORM_TEST) && AGS_PLATFORM_TEST 97 inline const char *GetBuffer()
const {
101 inline size_t GetCapacity()
const {
102 return _bufHead ? _bufHead->Capacity : 0;
105 inline size_t GetRefCount()
const {
106 return _bufHead ? _bufHead->RefCount : 0;
117 void Read(
Stream *in,
size_t max_chars = 5 * 1024 * 1024,
bool stop_at_limit =
false);
121 void ReadCount(
Stream *in,
size_t count);
123 void Write(
Stream *out)
const;
126 void WriteCount(
Stream *out,
size_t count)
const;
133 int Compare(
const String &str)
const {
134 return Compare(str._cstr);
136 int Compare(
const char *cstr)
const;
137 int CompareNoCase(
const String &str)
const {
138 return CompareNoCase(str._cstr);
140 int CompareNoCase(
const char *cstr)
const;
142 int CompareLeft(
const String &str,
size_t count = -1)
const {
143 return CompareLeft(str._cstr, count != NoIndex ? count : str._len);
145 int CompareLeft(
const char *cstr,
size_t count = -1)
const;
146 int CompareLeftNoCase(
const String &str,
size_t count = -1)
const {
147 return CompareLeftNoCase(str._cstr, count != NoIndex ? count : str._len);
149 int CompareLeftNoCase(
const char *cstr,
size_t count = -1)
const;
151 int CompareMid(
const String &str,
size_t from,
size_t count = -1)
const {
152 return CompareMid(str._cstr, from, count != NoIndex ? count : str._len);
154 int CompareMid(
const char *cstr,
size_t from,
size_t count = -1)
const;
155 int CompareMidNoCase(
const String &str,
size_t from,
size_t count = -1)
const {
156 return CompareMidNoCase(str._cstr, from, count != NoIndex ? count : str._len);
158 int CompareMidNoCase(
const char *cstr,
size_t from,
size_t count = -1)
const;
160 int CompareRight(
const String &str,
size_t count = -1)
const {
161 return CompareRight(str._cstr, count != NoIndex ? count : str._len);
163 int CompareRight(
const char *cstr,
size_t count = -1)
const;
164 int CompareRightNoCase(
const String &str,
size_t count = -1)
const {
165 return CompareRightNoCase(str._cstr, count != NoIndex ? count : str._len);
167 int CompareRightNoCase(
const char *cstr,
size_t count = -1)
const;
169 inline bool Equals(
const String &str)
const {
170 return Compare(str) == 0;
172 inline bool Equals(
const char *cstr)
const {
173 return Compare(cstr) == 0;
175 inline bool StartsWith(
const String &str)
const {
176 return CompareLeft(str) == 0;
178 inline bool StartsWith(
const char *cstr)
const {
179 return CompareLeft(cstr) == 0;
181 inline bool EndsWidth(
const String &str)
const {
182 return CompareRight(str) == 0;
184 inline bool EndsWidth(
const char *cstr)
const {
185 return CompareRight(cstr) == 0;
190 size_t FindChar(
char c,
size_t from = 0)
const;
191 size_t FindCharReverse(
char c,
size_t from = -1)
const;
192 size_t FindString(
const String &str,
size_t from = 0)
const {
193 return FindString(str._cstr, from);
195 size_t FindString(
const char *cstr,
size_t from = 0)
const;
208 bool FindSection(
char separator,
size_t first,
size_t last,
bool exclude_first_sep,
bool exclude_last_sep,
209 size_t &from,
size_t &to)
const;
212 inline char GetAt(
size_t index)
const {
213 return (index < _len) ? _cstr[index] : 0;
215 inline char GetLast()
const {
216 return (_len > 0) ? _cstr[_len - 1] : 0;
231 static String Wrapper(
const char *cstr);
235 static String FromFormat(
const char *fcstr, ...);
236 static String FromFormatV(
const char *fcstr, va_list argptr);
238 static String FromStream(
Stream *in,
size_t max_chars = 5 * 1024 * 1024,
bool stop_at_limit =
false);
240 static String FromStreamCount(
Stream *in,
size_t count);
248 String Left(
size_t count)
const;
250 String Mid(
size_t from,
size_t count = -1)
const;
252 String Right(
size_t count)
const;
256 String LeftSection(
char separator,
bool exclude_separator =
true)
const;
259 String RightSection(
char separator,
bool exclude_separator =
true)
const;
261 String Section(
char separator,
size_t first,
size_t last,
262 bool exclude_first_sep =
true,
bool exclude_last_sep =
true)
const;
274 void Reserve(
size_t max_length);
276 void ReserveMore(
size_t more_length);
282 void Append(
const String &str);
283 void Append(
const char *cstr) {
284 String str = String::Wrapper(cstr);
287 void Append(
const char *cstr,
size_t len);
289 void AppendChar(
char c);
291 void AppendFmt(MSVC_PRINTF
const char *fcstr, ...)
GCC_PRINTF(2, 3);
292 void AppendFmtv(
const char *fcstr, va_list argptr);
295 void ClipLeft(
size_t count);
297 void ClipMid(
size_t from,
size_t count = -1);
299 void ClipRight(
size_t count);
302 void ClipLeftSection(
char separator,
bool include_separator =
true);
305 void ClipRightSection(
char separator,
bool include_separator =
true);
307 void ClipSection(
char separator,
size_t first,
size_t last,
308 bool include_first_sep =
true,
bool include_last_sep =
true);
312 void FillString(
char c,
size_t count);
314 void Format(
const char *fcstr, ...);
315 void FormatV(
const char *fcstr, va_list argptr);
326 void MergeSequences(
char c = 0);
329 void Prepend(
const String &str);
330 void Prepend(
const char *cstr) {
331 String str = String::Wrapper(cstr); Prepend(str);
334 void PrependChar(
char c);
336 void Replace(
char what,
char with);
339 void Replace(
const char *what,
const char *with) {
340 String whats = String::Wrapper(what), withs = String::Wrapper(with); Replace(whats, withs);
344 void ReplaceMid(
size_t from,
size_t count,
const String &str);
345 void ReplaceMid(
size_t from,
size_t count,
const char *cstr) {
346 String str = String::Wrapper(cstr); ReplaceMid(from, count, str);
355 void SetAt(
size_t index,
char c);
357 void SetString(
const char *cstr,
size_t length = -1);
361 void Trim(
char c = 0);
363 void TrimLeft(
char c = 0);
365 void TrimRight(
char c = 0);
368 void TruncateToLeft(
size_t count);
370 void TruncateToMid(
size_t from,
size_t count = -1);
372 void TruncateToRight(
size_t count);
375 void TruncateToLeftSection(
char separator,
bool exclude_separator =
true);
378 void TruncateToRightSection(
char separator,
bool exclude_separator =
true);
381 void TruncateToSection(
char separator,
size_t first,
size_t last,
382 bool exclude_first_sep =
true,
bool exclude_last_sep =
true);
385 void Wrap(
const char *cstr);
396 String &operator=(
const char *cstr);
397 inline char operator[](
size_t index)
const {
398 assert(index < _len);
401 inline bool operator ==(
const String &str)
const {
402 return Compare(str) == 0;
404 inline bool operator ==(
const char *cstr)
const {
405 return Compare(cstr) == 0;
407 inline bool operator !=(
const String &str)
const {
408 return Compare(str) != 0;
410 inline bool operator !=(
const char *cstr)
const {
411 return Compare(cstr) != 0;
413 inline bool operator <(
const String &str)
const {
414 return Compare(str) < 0;
416 inline bool operator <(
const char *cstr)
const {
417 return Compare(cstr) < 0;
424 operator bool()
const {
427 operator const char *()
const {
433 void Create(
size_t buffer_length);
435 void Copy(
size_t buffer_length,
size_t offset = 0);
437 void Align(
size_t offset);
440 bool IsShared()
const;
445 void ReserveAndShift(
bool left,
size_t more_length);
Definition: achievements_tables.h:27
int FORCEINLINE GCC_PRINTF(2, 0) int vsprintf_s(T(&dst)[N]