45 #ifndef AGS_SHARED_UTIL_STRING_H 46 #define AGS_SHARED_UTIL_STRING_H 50 #include "common/str.h" 52 #include "common/std/vector.h" 53 #include "ags/shared/core/platform.h" 54 #include "ags/shared/core/types.h" 64 static const size_t NoIndex = (size_t)-1;
75 String(
const char *cstr,
size_t length);
77 String(
char c,
size_t count);
83 inline const char *GetCStr()
const {
87 inline size_t GetLength()
const {
91 inline bool IsEmpty()
const {
95 bool IsNullOrSpace()
const;
98 #if defined(AGS_PLATFORM_TEST) && AGS_PLATFORM_TEST 99 inline const char *GetBuffer()
const {
103 inline size_t GetCapacity()
const {
104 return _bufHead ? _bufHead->Capacity : 0;
107 inline size_t GetRefCount()
const {
108 return _bufHead ? _bufHead->RefCount : 0;
119 void Read(
Stream *in,
size_t max_chars = 5 * 1024 * 1024,
bool stop_at_limit =
false);
123 void ReadCount(
Stream *in,
size_t count);
125 void Write(
Stream *out)
const;
128 void WriteCount(
Stream *out,
size_t count)
const;
135 int Compare(
const String &str)
const {
136 return Compare(str._cstr);
138 int Compare(
const char *cstr)
const;
139 int CompareNoCase(
const String &str)
const {
140 return CompareNoCase(str._cstr);
142 int CompareNoCase(
const char *cstr)
const;
144 int CompareLeft(
const String &str,
size_t count = -1)
const {
145 return CompareLeft(str._cstr, count != NoIndex ? count : str._len);
147 int CompareLeft(
const char *cstr,
size_t count = -1)
const;
148 int CompareLeftNoCase(
const String &str,
size_t count = -1)
const {
149 return CompareLeftNoCase(str._cstr, count != NoIndex ? count : str._len);
151 int CompareLeftNoCase(
const char *cstr,
size_t count = -1)
const;
153 int CompareMid(
const String &str,
size_t from,
size_t count = -1)
const {
154 return CompareMid(str._cstr, from, count != NoIndex ? count : str._len);
156 int CompareMid(
const char *cstr,
size_t from,
size_t count = -1)
const;
157 int CompareMidNoCase(
const String &str,
size_t from,
size_t count = -1)
const {
158 return CompareMidNoCase(str._cstr, from, count != NoIndex ? count : str._len);
160 int CompareMidNoCase(
const char *cstr,
size_t from,
size_t count = -1)
const;
162 int CompareRight(
const String &str,
size_t count = -1)
const {
163 return CompareRight(str._cstr, count != NoIndex ? count : str._len);
165 int CompareRight(
const char *cstr,
size_t count = -1)
const;
166 int CompareRightNoCase(
const String &str,
size_t count = -1)
const {
167 return CompareRightNoCase(str._cstr, count != NoIndex ? count : str._len);
169 int CompareRightNoCase(
const char *cstr,
size_t count = -1)
const;
171 inline bool Equals(
const String &str)
const {
172 return Compare(str) == 0;
174 inline bool Equals(
const char *cstr)
const {
175 return Compare(cstr) == 0;
177 inline bool StartsWith(
const String &str)
const {
178 return CompareLeft(str) == 0;
180 inline bool StartsWith(
const char *cstr)
const {
181 return CompareLeft(cstr) == 0;
183 inline bool EndsWidth(
const String &str)
const {
184 return CompareRight(str) == 0;
186 inline bool EndsWidth(
const char *cstr)
const {
187 return CompareRight(cstr) == 0;
192 size_t FindChar(
char c,
size_t from = 0)
const;
193 size_t FindCharReverse(
char c,
size_t from = -1)
const;
194 size_t FindString(
const String &str,
size_t from = 0)
const {
195 return FindString(str._cstr, from);
197 size_t FindString(
const char *cstr,
size_t from = 0)
const;
210 bool FindSection(
char separator,
size_t first,
size_t last,
bool exclude_first_sep,
bool exclude_last_sep,
211 size_t &from,
size_t &to)
const;
214 inline char GetAt(
size_t index)
const {
215 return (index < _len) ? _cstr[index] : 0;
217 inline char GetLast()
const {
218 return (_len > 0) ? _cstr[_len - 1] : 0;
233 static String Wrapper(
const char *cstr);
237 static String FromFormat(
const char *fcstr, ...);
238 static String FromFormatV(
const char *fcstr, va_list argptr);
240 static String FromStream(
Stream *in,
size_t max_chars = 5 * 1024 * 1024,
bool stop_at_limit =
false);
242 static String FromStreamCount(
Stream *in,
size_t count);
250 String Left(
size_t count)
const;
252 String Mid(
size_t from,
size_t count = -1)
const;
254 String Right(
size_t count)
const;
258 String LeftSection(
char separator,
bool exclude_separator =
true)
const;
261 String RightSection(
char separator,
bool exclude_separator =
true)
const;
263 String Section(
char separator,
size_t first,
size_t last,
264 bool exclude_first_sep =
true,
bool exclude_last_sep =
true)
const;
276 void Reserve(
size_t max_length);
278 void ReserveMore(
size_t more_length);
284 void Append(
const String &str);
285 void Append(
const char *cstr) {
286 String str = String::Wrapper(cstr);
289 void Append(
const char *cstr,
size_t len);
291 void AppendChar(
char c);
293 void AppendFmt(MSVC_PRINTF
const char *fcstr, ...)
GCC_PRINTF(2, 3);
294 void AppendFmtv(
const char *fcstr, va_list argptr);
297 void ClipLeft(
size_t count);
299 void ClipMid(
size_t from,
size_t count = -1);
301 void ClipRight(
size_t count);
304 void ClipLeftSection(
char separator,
bool include_separator =
true);
307 void ClipRightSection(
char separator,
bool include_separator =
true);
309 void ClipSection(
char separator,
size_t first,
size_t last,
310 bool include_first_sep =
true,
bool include_last_sep =
true);
314 void FillString(
char c,
size_t count);
316 void Format(
const char *fcstr, ...);
317 void FormatV(
const char *fcstr, va_list argptr);
328 void MergeSequences(
char c = 0);
331 void Prepend(
const String &str);
332 void Prepend(
const char *cstr) {
333 String str = String::Wrapper(cstr); Prepend(str);
336 void PrependChar(
char c);
338 void Replace(
char what,
char with);
341 void Replace(
const char *what,
const char *with) {
342 String whats = String::Wrapper(what), withs = String::Wrapper(with); Replace(whats, withs);
346 void ReplaceMid(
size_t from,
size_t count,
const String &str);
347 void ReplaceMid(
size_t from,
size_t count,
const char *cstr) {
348 String str = String::Wrapper(cstr); ReplaceMid(from, count, str);
357 void SetAt(
size_t index,
char c);
359 void SetString(
const char *cstr,
size_t length = -1);
363 void Trim(
char c = 0);
365 void TrimLeft(
char c = 0);
367 void TrimRight(
char c = 0);
370 void TruncateToLeft(
size_t count);
372 void TruncateToMid(
size_t from,
size_t count = -1);
374 void TruncateToRight(
size_t count);
377 void TruncateToLeftSection(
char separator,
bool exclude_separator =
true);
380 void TruncateToRightSection(
char separator,
bool exclude_separator =
true);
383 void TruncateToSection(
char separator,
size_t first,
size_t last,
384 bool exclude_first_sep =
true,
bool exclude_last_sep =
true);
387 void Wrap(
const char *cstr);
398 String &operator=(
const char *cstr);
399 inline char operator[](
size_t index)
const {
400 assert(index < _len);
403 inline bool operator ==(
const String &str)
const {
404 return Compare(str) == 0;
406 inline bool operator ==(
const char *cstr)
const {
407 return Compare(cstr) == 0;
409 inline bool operator !=(
const String &str)
const {
410 return Compare(str) != 0;
412 inline bool operator !=(
const char *cstr)
const {
413 return Compare(cstr) != 0;
415 inline bool operator <(
const String &str)
const {
416 return Compare(str) < 0;
418 inline bool operator <(
const char *cstr)
const {
419 return Compare(cstr) < 0;
426 operator bool()
const {
429 operator const char *()
const {
435 void Create(
size_t buffer_length);
437 void Copy(
size_t buffer_length,
size_t offset = 0);
439 void Align(
size_t offset);
442 bool IsShared()
const;
447 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]