3DCoat Core API
The 3DCoat API documentation.
Loading...
Searching...
No Matches
cStr.h
1#pragma once
2
3//*****************************************************************************
4// cStr
5//*****************************************************************************
6class APICALL cStr {
7public:
8 //-------------------------------------------------------------------------
9 // .ctor
10 //-------------------------------------------------------------------------
11 cStr();
12 cStr(const cStr& Src);
13 cStr(const cStr& Src, const int StartIndex, const int Count);
14 cStr(const char* Src);
15 cStr(const char* Src, const int StartIndex, const int Count);
16 cStr(const wchar_t* Src);
17 cStr(const int Length, const char Fill = ' '); // ... + cStr(20, '-') + ...
18
19 // .dtor
20 ~cStr();
21
22 //-------------------------------------------------------------------------
23 // Copy
24 //-------------------------------------------------------------------------
25 void Copy(const cStr&);
26 void Copy(const cStr&, const int StartIndex, const int Count);
27 void Copy(const char*);
28 void Copy(const char*, const int StartIndex, const int Count);
29 void Copy(const wchar_t*);
30 void operator = (const cStr&);
31 void operator = (const char*);
32 void operator = (int);
33
34
35 //-------------------------------------------------------------------------
36 // ToCharPtr
37 //-------------------------------------------------------------------------
38 const char* ToCharPtr() const;
39 char* ToNonConstCharPtr();
40 operator const char* () const;
41 //operator char * ();
42
43 //---------------------------------------------------------------
44 // operator []
45 //---------------------------------------------------------------
46 char operator [] (const int CharIndex) const;
47 char& operator [] (const int CharIndex);
48
49 //-------------------------------------------------------------------------
50 // Length
51 //-------------------------------------------------------------------------
52 int Length() const;
53 static int Length(const char* Str);
54
55 //-------------------------------------------------------------------------
56 // SetLength / CalcLength, Fill
57 //-------------------------------------------------------------------------
58 // Ensures needed capacity and sets a specified length. Fill char can be specified.
59 void SetLength(const int Length, const char Fill = ' ');
60 void CalcLength(); // Updates length based on actual '\0' character position.
61
62 // cStr Path;
63 // ...
64 // Path.SetLength(MAX_PATH);
65 // GetModuleFileName(nullptr, Path.ToCharPtr(), Path.Length());
66 // Path.CalcLength();
67
68 void Fill(const char c); // Fills the whole string with the specified character.
69
70 //-------------------------------------------------------------------------
71 // IsEmpty, Clear
72 //-------------------------------------------------------------------------
73 bool IsEmpty() const;
74 bool empty() const;
75 void Clear();
76 static const cStr Empty;
77
78 //-------------------------------------------------------------------------
79 // Equals(NoCase) (==, !=)
80 //-------------------------------------------------------------------------
81 static bool Equals(const char*, const char*);
82 static bool Equals(const char*, const cStr&);
83 static bool Equals(const cStr&, const char*);
84 static bool Equals(const cStr&, const cStr&);
85 static bool Equals(const cStr*, const cStr*);
86 bool Equals(const char*) const;
87
88 friend bool operator == (const char*, const cStr&);
89 friend bool operator == (const cStr&, const char*);
90 friend bool operator == (const cStr&, const cStr&);
91
92 friend bool operator != (const char*, const cStr&);
93 friend bool operator != (const cStr&, const char*);
94 friend bool operator != (const cStr&, const cStr&);
95
96 static bool Equals(const char*, const char*, const int MaxLength);
97 static bool Equals(const char*, const cStr&, const int MaxLength);
98 static bool Equals(const cStr&, const char*, const int MaxLength);
99 static bool Equals(const cStr&, const cStr&, const int MaxLength);
100
101 static bool EqualsNoCase(const char*, const char*);
102 static bool EqualsNoCase(const char*, const cStr&);
103 static bool EqualsNoCase(const cStr&, const char*);
104 static bool EqualsNoCase(const cStr&, const cStr&);
105 static bool EqualsNoCase(const cStr*, const cStr*);
106
107 static bool EqualsNoCase(const char*, const char*, const int MaxLength);
108 static bool EqualsNoCase(const char*, const cStr&, const int MaxLength);
109 static bool EqualsNoCase(const cStr&, const char*, const int MaxLength);
110 static bool EqualsNoCase(const cStr&, const cStr&, const int MaxLength);
111
112 //-------------------------------------------------------------------------
113 // Compare(NoCase) (>, >=, <, <=)
114 //-------------------------------------------------------------------------
115 static int Compare(const char*, const char*);
116 static int Compare(const char*, const cStr&);
117 static int Compare(const cStr&, const char*);
118 static int Compare(const cStr&, const cStr&);
119 static int Compare(const cStr*, const cStr*);
120
121 friend bool operator > (const char*, const cStr&);
122 friend bool operator > (const cStr&, const char*);
123 friend bool operator > (const cStr&, const cStr&);
124
125 friend bool operator >= (const char*, const cStr&);
126 friend bool operator >= (const cStr&, const char*);
127 friend bool operator >= (const cStr&, const cStr&);
128
129 friend bool operator < (const char*, const cStr&);
130 friend bool operator < (const cStr&, const char*);
131 friend bool operator < (const cStr&, const cStr&);
132
133 friend bool operator <= (const char*, const cStr&);
134 friend bool operator <= (const cStr&, const char*);
135 friend bool operator <= (const cStr&, const cStr&);
136
137 static int Compare(const char*, const char*, const int MaxLength);
138 static int Compare(const char*, const cStr&, const int MaxLength);
139 static int Compare(const cStr&, const char*, const int MaxLength);
140 static int Compare(const cStr&, const cStr&, const int MaxLength);
141
142 static int CompareNoCase(const char*, const char*);
143 static int CompareNoCase(const char*, const cStr&);
144 static int CompareNoCase(const cStr&, const char*);
145 static int CompareNoCase(const cStr&, const cStr&);
146 static int CompareNoCase(const cStr*, const cStr*);
147
148 static int CompareNoCase(const char*, const char*, const int MaxLength);
149 static int CompareNoCase(const char*, const cStr&, const int MaxLength);
150 static int CompareNoCase(const cStr&, const char*, const int MaxLength);
151 static int CompareNoCase(const cStr&, const cStr&, const int MaxLength);
152
153 //-------------------------------------------------------------------------
154 // EqualsPath
155 //-------------------------------------------------------------------------
156 static bool EqualsPath(const char*, const char*);
157 static bool EqualsPath(const char*, const cStr&);
158 static bool EqualsPath(const cStr&, const char*);
159 static bool EqualsPath(const cStr&, const cStr&);
160 static bool EqualsPath(const cStr*, const cStr*);
161
162 static bool EqualsPath(const char*, const char*, const int MaxLength);
163 static bool EqualsPath(const char*, const cStr&, const int MaxLength);
164 static bool EqualsPath(const cStr&, const char*, const int MaxLength);
165 static bool EqualsPath(const cStr&, const cStr&, const int MaxLength);
166
167 //-------------------------------------------------------------------------
168 // ComparePath
169 //-------------------------------------------------------------------------
170 static int ComparePath(const char*, const char*);
171 static int ComparePath(const char*, const cStr&);
172 static int ComparePath(const cStr&, const char*);
173 static int ComparePath(const cStr&, const cStr&);
174 static int ComparePath(const cStr*, const cStr*);
175
176 static int ComparePath(const char*, const char*, const int MaxLength);
177 static int ComparePath(const char*, const cStr&, const int MaxLength);
178 static int ComparePath(const cStr&, const char*, const int MaxLength);
179 static int ComparePath(const cStr&, const cStr&, const int MaxLength);
180
181 // Path comparers consider '\\' and '/' as equivalents. They use no case compare.
182 // Also they compare according to folder depth.
183
184 //-------------------------------------------------------------------------
185 // StartsWith / EndsWith
186 //-------------------------------------------------------------------------
187 // Determines whether the beginning of this instance matches the specified string.
188 // If the specified string is empty (not nullptr is asserted), the return value is "true".
189 // Case insesitive compare can be specified.
190 bool StartsWith(const char* Str, const bool NoCase = false) const;
191 // Determines whether the end of this instance matches the specified string.
192 // If the specified string is empty (not nullptr is asserted), the return value is "true";
193 // Case insesitive compare can be specified.
194 bool EndsWith(const char* Str, const bool NoCase = false) const;
195
196 //-------------------------------------------------------------------------
197 // ToString
198 //-------------------------------------------------------------------------
199 // Returns a string that represents a specified value.
200 // These functions are heavily used in "Append" and "Insert" functions,
201 // as well as in "+=", "+" and "<<" operators.
202 static const cStr ToString(const bool);
203 static const cStr ToString(const int);
204 static const cStr ToString(const int, const int Prec);
205 static const cStr ToString(const int* IntArray, const int Count, const char* Separator = " ");
206 static const cStr ToString(const float, const int Prec = 2);
207 static const cStr ToString(const float* FloatArray, const int Count, const int Prec = 2, const char* Separator = " ");
208 static const cStr ToString(const double, const int Prec = 6);
209 static const cStr ToString(const double* DoubleArray, const int Count, const int Prec = 6, const char* Separator = " ");
210 static const cStr ToHex(const dword dw);
211 static const cStr ToHex(const qword qw);
212 static const cStr ToHex(const void* Ptr);
213
228 static const cStr ToSize(const qword, const bool Pow2 = false);
229
230 //-------------------------------------------------------------------------
231 // Append (+=, <<, +)
232 //-------------------------------------------------------------------------
233 void Append(const cStr&);
234 void Append(const cStr&, const int StartIndex, const int Count);
235 void Append(const char*);
236 void Append(const wchar_t*);
237 void Append(const char*, const int StartIndex, const int Count);
238 void Append(const char);
239 void Append(const char, const int Count);
240 void Append(const bool);
241 void Append(const int);
242 void Append(const float, const int Prec = 2);
243 void Append(const double, const int Prec = 6);
244
245 void AppendWithEndLn(const cStr&);
246 static const cStr EndLn;
247
248 void operator += (const cStr&);
249 void operator += (const char*);
250 void operator += (const wchar_t*);
251 void operator += (const char);
252 void operator += (const bool);
253 void operator += (const int);
254 void operator += (const float);
255 void operator += (const double);
256
257 cStr& operator << (const cStr&);
258 cStr& operator << (const char*);
259 cStr& operator << (const wchar_t*);
260 cStr& operator << (const char);
261 cStr& operator << (const bool);
262 cStr& operator << (const int);
263 cStr& operator << (const float);
264 cStr& operator << (const double);
265
266 friend const cStr operator + (const cStr&, const cStr&);
267 friend const cStr operator + (const cStr&, const char*);
268 friend const cStr operator + (const char*, const cStr&);
269 friend const cStr operator + (const cStr&, const char);
270 friend const cStr operator + (const char, const cStr&);
271 friend const cStr operator + (const cStr&, const bool);
272 friend const cStr operator + (const bool, const cStr&);
273 friend const cStr operator + (const cStr&, const int);
274 friend const cStr operator + (const int, const cStr&);
275 friend const cStr operator + (const cStr&, const float);
276 friend const cStr operator + (const float, const cStr&);
277 friend const cStr operator + (const cStr&, const double);
278 friend const cStr operator + (const double, const cStr&);
279
280 friend const cStr operator + (const cStr&, const wchar_t*);
281 friend const cStr operator + (const wchar_t*, const cStr&);
282
283 //-------------------------------------------------------------------------
284 // Append... (Path, Format)
285 //-------------------------------------------------------------------------
286 void AppendPath(const char* Path); // Appends '\\' under Windows, '/' under Linux and macOS
287 void AppendFormat(const char* Format, ...);
288
289 //-------------------------------------------------------------------------
290 // Insert
291 //-------------------------------------------------------------------------
292 void Insert(const int Index, const cStr&);
293 void Insert(const int Index, const cStr&, const int StartIndex, const int Count);
294 void Insert(const int Index, const char*);
295 void Insert(const int Index, const char*, const int StartIndex, const int Count);
296 void Insert(const int Index, const char);
297 void Insert(const int Index, const char, const int Count);
298 void Insert(const int Index, const bool);
299 void Insert(const int Index, const int);
300 void Insert(const int Index, const float, const int Prec = 2);
301 void Insert(const int Index, const double, const int Prec = 6);
302
303 //-------------------------------------------------------------------------
304 // Remove
305 //-------------------------------------------------------------------------
306 // Deletes all the characters from this string beginning at a specified position
307 // and continuing through the last position.
308 void Remove(const int StartIndex);
309 // Deletes a specified number of characters from this instance
310 // beginning at a specified position.
311 void Remove(const int StartIndex, const int Count);
312
313 //-------------------------------------------------------------------------
314 // Replace : (const char, const char, ...)
315 //-------------------------------------------------------------------------
316 // Replaces all occurrences of a specified character in this instance// with another specified character.
317 void Replace(const char Char, const char WithChar);
318 void ReplaceCommaWithDot() {
319 Replace(',', '.');
320 }
321 // Replaces only within a substring of this instance.
322 void Replace(const char Char, const char WithChar, const int StartIndex, const int Count);
323
324 //-------------------------------------------------------------------------
325 // Replace : (const char *, const char *, ...)
326 //-------------------------------------------------------------------------
327 // Replaces all occurrences of a specified string in this instance
328 // with another specified string.
329 // Returns number of replaces.
330 // Case insensitive compare can be specified.
331 int Replace(const char* String, const char* WithString, const bool NoCase = false);
332 // Replaces in a substring beginning from a specified position to the end.
333 int Replace(const char* String, const char* WithString, const int StartIndex, const bool NoCase = false);
334 // Replaces only within a substring of this instance.
335 int Replace(const char* String, const char* WithString, const int StartIndex, const int Count, const bool NoCase = false);
336 // Replaces first occurrence of a specified string in this instance with another specified string.
337 int ReplaceFirst(const char* String, const char* WithString, const bool NoCase = false);
338 // Replaces only within a substring of this instance.
339 int ReplaceFirst(const char* String, const char* WithString, const int StartIndex, const int Count, const bool NoCase = false);
340
341 //-------------------------------------------------------------------------
342 // ReplaceAny : (const char *, const char, ...)
343 //-------------------------------------------------------------------------
344 // Replaces all occurrences in this instance of every character in the
345 // specified list of characters with another specified character.
346 void ReplaceAny(const char* Chars, const char WithChar); // S.ReplaceAny(",;\t", ' ');
347 // Replaces only within a substring of this instance.
348 void ReplaceAny(const char* Chars, const char WithChar, const int StartIndex, const int Count);
349
350 //-------------------------------------------------------------------------
351 // Substring
352 //-------------------------------------------------------------------------
353 // Retrieves a substring from this instance.
354 // The substring starts at a specified character position.
355 const cStr Substring(const int StartIndex) const;
356 // The substring starts at a specified character position and has a specified length.
357 const cStr Substring(const int StartIndex, const int Count) const;
358
359 //-------------------------------------------------------------------------
360 // Trim...
361 //-------------------------------------------------------------------------
362 // Removes all occurrences of a set of characters specified in a string
363 // from the beginning of this instance.
364 void TrimStart(const char* TrimChars);
365 // Removes all occurrences of a set of characters specified in a string
366 // from the end of this instance.
367 void TrimEnd(const char* TrimChars);
368 // Removes all occurrences of a set of characters specified in a string
369 // from the beginning and end of this instance.
370 void Trim(const char* TrimChars);
371
372 //-------------------------------------------------------------------------
373 // PadLeft / PadRight
374 //-------------------------------------------------------------------------
375 // Right - aligns the characters of this instance, padding on the left with
376 // spaces or a specified character for a specified total length.
377 void PadLeft(const int TotalWidth, const char PaddingChar = ' ');
378 // Left - align the characters of this instance, padding on the right with
379 // spaces or a specified character for a specified total length.
380 void PadRight(const int TotalWidth, const char PaddingChar = ' ');
381
382 //-------------------------------------------------------------------------
383 // Contains
384 //-------------------------------------------------------------------------
385 // Returns a value indicating whether the specified character occurs within this string.
386 bool Contains(const char c) const;
387 // Returns "true" if the specified string occurs within this string, or if the
388 // specified string is empty string or nullptr; otherwise, "false".
389 // Case insesitive compare can be specified.
390 bool Contains(const char* Str, const bool NoCase = false) const;
391
392 //-------------------------------------------------------------------------
393 // IndexOf : (const char, ...)
394 //-------------------------------------------------------------------------
395 // Returns the index position of the first occurrence within this instance
396 // where the specified character is found, or -1 if it is not.
397 int IndexOf(const char c) const;
398 static int IndexOf(const char* Src, const char c);
399 // The search starts at a specified character position.
400 int IndexOf(const char c, const int StartIndex) const;
401 // The search starts at a specified character position and examines a specified number of character positions.
402 int IndexOf(const char c, const int StartIndex, const int Count) const;
403
404 //-------------------------------------------------------------------------
405 // IndexOf : (const char *, ...)
406 //-------------------------------------------------------------------------
407 // Returns the index position of the first occurrence in this instance
408 // where the specified string is found, or -1 if it is not.
409 // If the specified string is empty or nullptr, the return value is "StartIndex".
410 // Case insesitive compare can be specified.
411 int IndexOf(const char* Str, const bool NoCase = false) const;
412 // The search starts at a specified character position.
413 int IndexOf(const char* Str, const int StartIndex, const bool NoCase = false) const;
414 // The search starts at a specified character position and examines a specified number of character positions.
415 int IndexOf(const char* Str, const int StartIndex, const int Count, const bool NoCase = false) const;
416
417 //-------------------------------------------------------------------------
418 // IndexOfAny
419 //-------------------------------------------------------------------------
420 // Returns the index position of the first occurrence in this instance
421 // where any character from the specified list of characters is found, or -1 if it is not.
422 int IndexOfAny(const char* Chars) const;
423 // The search starts at a specified character position.
424 int IndexOfAny(const char* Chars, const int StartIndex) const;
425 // The search starts at a specified character position and examines a specified number of character positions.
426 int IndexOfAny(const char* Chars, const int StartIndex, const int Count) const;
427
428 //-------------------------------------------------------------------------
429 // LastIndexOf : (const char, ...)
430 //-------------------------------------------------------------------------
431 // Returns the index position of the last occurrence within this instance
432 // where the specified character is found, or -1 if it is not.
433 int LastIndexOf(const char c) const;
434 // The search starts at a specified character position and
435 // proceeds backwards towards the beginning.
436 int LastIndexOf(const char c, const int StartIndex) const;
437 // The search starts at a specified character position and
438 // proceeds backwards towards the beginning until either character is found
439 // or a specified number of character positions have been examined.
440 int LastIndexOf(const char c, const int StartIndex, const int Count) const;
441
442 //-------------------------------------------------------------------------
443 // LastIndexOf : (const char *, ...)
444 //-------------------------------------------------------------------------
445 // Returns the index position of the last occurrence within this instance
446 // where the specified string is found, or -1 if it is not.
447 // If the specified string is empty or nullptr, the return value is "StartIndex".
448 // Case insesitive compare can be specified.
449 int LastIndexOf(const char* Str, const bool NoCase = false) const;
450 // The search starts at a specified character position and proceeds backwards towards the beginning.
451 int LastIndexOf(const char* Str, const int StartIndex, const bool NoCase = false) const;
452 // The search starts at a specified character position and proceeds backwards towards the beginning
453 // until either the string is found or a specified character positions have been examined.
454 int LastIndexOf(const char* Str, const int StartIndex, const int Count, const bool NoCase = false) const;
455
456 //-------------------------------------------------------------------------
457 // LastIndexOfAny
458 //-------------------------------------------------------------------------
459 // Returns the index position of the last occurrence in this instance
460 // where any character from the specified list of characters is found, or -1 if it is not.
461 int LastIndexOfAny(const char* Chars) const;
462 // The search starts at a specified character position and
463 // proceeds backwards towards the beginning.
464 int LastIndexOfAny(const char* Chars, const int StartIndex) const;
465 // The search starts at a specified character position and proceeds
466 // backwards towards the beginning until either character in a specified string
467 // is found or a specified number of character positions have been examined.
468 int LastIndexOfAny(const char* Chars, const int StartIndex, const int Count) const;
469
470 //-------------------------------------------------------------------------
471 // ToLower / ToUpper, MakeLower / MakeUpper
472 //-------------------------------------------------------------------------
473 static char ToLower(const char c);
474 static char ToUpper(const char c);
475 void MakeLower(int start = 0); // Converts this string instance to lowercase.
476 void MakeUpper(int start = 0); // Converts this string instance to uppercase.
477 const cStr ToLower() const; // Returns a copy of this string converted to lowercase.
478 const cStr ToUpper() const; // Returns a copy of this string converted to uppercase.
479
480 //-------------------------------------------------------------------------
481 // Join
482 //-------------------------------------------------------------------------
483 // Concatenates a specified separator between each element of a specified
484 // string list, yielding a single concatenated string.
485 static const cStr Join(const char* Separator, const cList<cStr>& Strings);
486 // Parameters specify the first array element and number of elements to use.
487 static const cStr Join(const char* Separator, const cList<cStr>& Strings, const int StartIndex, const int Count);
488
489 //-------------------------------------------------------------------------
490 // Split
491 //-------------------------------------------------------------------------
492 // Fills a list with the substrings from a specified string or this instance
493 // that are delimited by a specified characters.
494 static void Split(const char* Src, cList<cStr>* List, const char* Delimiters = " ,;\t");
495 void Split(cList<cStr>* List, const char* Delimiters = " ,;\t") const;
496
497 //-------------------------------------------------------------------------
498 // Format
499 //-------------------------------------------------------------------------
500 // Returns a copy of the specified format string in which each format item is replaced
501 // with the text equivalent of a corresponding value from arguments.
502 static const cStr Format(const char* Format, ...);
503 static const cStr Formatv(const char* Format, va_list Args); // Uses list of arguments.
504
505 //-------------------------------------------------------------------------
506 // CharIs...
507 //-------------------------------------------------------------------------
508 static bool CharIsLower(const int c);
509 static bool CharIsUpper(const int c);
510 static bool CharIsAlpha(const int c);
511 static bool CharIsNumeric(const int c);
512 static bool CharIsHexadecimal(const int c);
513 static bool CharIsNewLine(const int c);
514 static bool CharIsTab(const int c);
515 static bool CharIsWhitespace(const int c);
516 static bool CharIsDecimalPoint(const int c);
517 static bool CharIsSign(const int c);
518 static bool CharIsExponent(const int c);
519
520 //-------------------------------------------------------------------------
521 // ToInt(Array) / ToFloat(Array)
522 //-------------------------------------------------------------------------
523 static bool ToInt(const char* Str, int* Value);
524 // [Whitespace] Consists of space or tab characters, which are ignored.
525 // [Sign] Is either plus (+) or minus (-).
526 // Digits Are one or more decimal digits.
527
528 static bool ToFloat(const char* Str, float* Value);
529 // [Whitespace] Consists of space or tab characters, which are ignored.
530 // [Sign] Is either plus (+) or minus (-).
531 // [Digits] Are one or more decimal digits.
532 // [.Digits] If no digits appear before the decimal point,
533 // at least one must appear after the decimal point.
534 // [ {d | D | e | E }[Sign]Digits] The decimal point may be followed by an exponent,
535 // which consists of an introductory letter (d, D, e, or E) and
536 // an optionally signed decimal integer.
537
538 static bool ToIntArray(const char* Str, cList<int>* IntArray);
539 static bool ToFloatArray(const char* Str, cList<float>* FloatArray);
540
541 //-------------------------------------------------------------------------
542 // GetHashCode
543 //-------------------------------------------------------------------------
544 int GetHashCode(const bool NoCase = false) const {
545 return GetHashCode(m_Str, NoCase);
546 }
547 static int GetHashCode(const char* Str, const bool NoCase = false);
548
549 //-------------------------------------------------------------------------
550 // GetFile... Extension / Name / Base / Path
551 //-------------------------------------------------------------------------
552 const cStr GetFileExtension() const;
553 const cStr GetFileName() const;
554 const cStr GetFileBase() const;
555 const cStr GetFilePath() const;
556
557 //-------------------------------------------------------------------------
558 // RemoveFile... Extension / Name / Path
559 //-------------------------------------------------------------------------
560 void RemoveFileExtension();
561 void RemoveFileName();
562 void RemoveFilePath();
563 // If string contains absolute path to file below specified "AbsPath", it will be removed
564 void RemoveFileAbsPath(const char* AbsPath);
565 void AppendFileRelPath(const char* RelPath);
566
567 //-------------------------------------------------------------------------
568 // SetFile... (Default)Extension / (Default)Path
569 //-------------------------------------------------------------------------
570 void SetFileExtension(const char* Extension);
571 void SetFileDefaultExtension(const char* DefaultExtension); // If there's no extension set the default.
572 void SetFilePath(const char* Path);
573 void SetFileDefaultPath(const char* DefaultPath); // If there's no path set the default.
574
575 void EnsureTrailingBackslash();
576 void EnsureTrailingSlash();
577 void EnsureTrailingPlatformSlash() {
578#if defined COMMS_WINDOWS
579 EnsureTrailingBackslash();
580#endif // Windows
581#if defined COMMS_MACOS || defined COMMS_LINUX
582 EnsureTrailingSlash();
583#endif // macOS, Linux
584 }
585 static const cStr EnsureTrailingPlatformSlash(const cStr &S) {
586 cStr T(S);
587 T.EnsureTrailingPlatformSlash();
588 return T;
589 }
590
591 void SlashesToBackSlashes(); // Replaces '/' with '\\'
592 void BackSlashesToSlashes(); // Replaces '\\' with '/'
593 void MakePlatformSlashes() {
594#if defined COMMS_WINDOWS
595 SlashesToBackSlashes(); // '/' -> '\\'
596#endif // Windows
597#if defined COMMS_MACOS || defined COMMS_LINUX
598 BackSlashesToSlashes(); // '\\' -> '/'
599#endif // macOS, Linux
600 }
601
602 //-------------------------------------------------------------------------
603 // Unicode
604 //-------------------------------------------------------------------------
605 struct CodePage {
606 enum Enum {
607 _1251 = 0,
608 Count = 1
609 };
610 };
611 void Decode(const CodePage::Enum _CodePage, cList<word>* UniChars) const;
612 bool DecodeUTF8(cList<word>* UniChars) const;
613 int CalcUTF8Length(const int StartIndex) const;
614 void Init();
615 void Free();
616#ifndef DLL_API
617 // if the DLL interface used the std containers may not be used because sizeof(std::...) is different
618 cStr(const ::std::wstring& Src);
619 cStr(const std::string& Src);
620 void Copy(const ::std::wstring&);
621 void Copy(const ::std::string&);
622 void operator = (const ::std::wstring&);
623 void operator = (const ::std::string&);
624 void toWstring(::std::wstring& ws);
625 std::wstring toWstring();
626 void Append(const std::string&);
627 void Append(const std::wstring&);
628 void operator += (const std::string&);
629 void operator += (const std::wstring&);
630 cStr& operator << (const std::string&);
631 cStr& operator << (const std::wstring&);
632 friend const cStr operator + (const cStr&, const std::wstring&);
633 friend const cStr operator + (const std::wstring&, const cStr&);
634 friend const cStr operator + (const cStr&, const std::string&);
635 friend const cStr operator + (const std::string&, const cStr&);
636#endif
637private:
638 char* m_Str;
639 int m_Length, m_Capacity;
640 static char def_str;
641
642 struct Param {
643 enum Values {
644 BaseBufferLength = 32,
645 GrowBy = 32
646 };
647 };
648
649 //char m_BaseBuffer[Param::BaseBufferLength];
650 bool IsValid() const;
651 friend class cXml;
652 void EnsureCapacity(const int MinCapacity, const bool KeepOld = true);
653 void Resize(const int MinCapacity, const bool KeepOld);
654 static char* getstr();
655 static void freestr(char* s);
656};
657
658// cStr::IsValid
659inline bool cStr::IsValid() const {
660 //cAssert(m_Str != nullptr);
661 // Seriously slows down Debug build of 3D-Coat
662 //cAssert(m_Length == Length(m_Str)); // Cached length should be the same as actual
663 //cAssert(m_Capacity >= m_Length); // Capacity should be at least length + 1 (terminating zero)
664 return true;
665}
666
667// cStr::Init
668inline void cStr::Init() {
669 m_Length = 0;
670 m_Capacity = 0;// Param::BaseBufferLength;
671 m_Str = nullptr;// m_BaseBuffer;
672 //m_Str[0] = '\0';
673 // No need in "cAssert(IsValid())", since after "Init" this string is valid for sure
674}
675
676// cStr::Free
677inline void cStr::Free() {
678 // In "Free" we don't care was string valid or not, cause usage of
679 // string buffer may be not only for storing one string with terminating zero.
680 //cAssert(m_Str != nullptr);
681 if (m_Capacity > Param::BaseBufferLength) {
682 cPool::Free((byte*)m_Str, m_Capacity);
683 }
684 else if (m_Str)freestr(m_Str);
685 Init();
686}
687
688// cStr::EnsureCapacity
689inline void cStr::EnsureCapacity(const int MinCapacity, const bool KeepOld) {
690 if (MinCapacity > m_Capacity) {
691 Resize(MinCapacity, KeepOld);
692 }
693}
694
695//-----------------------------------------------------------------------------
696// cStr.ctor
697//-----------------------------------------------------------------------------
698
699// cStr.ctor : ()
700inline cStr::cStr() {
701 Init();
702}
703
704// cStr.ctor : (const cStr &)
705inline cStr::cStr(const cStr& Src) {
706 Init();
707 Copy(Src);
708}
709
710// cStr.ctor : (const cStr &, const int, const int)
711inline cStr::cStr(const cStr& Src, const int StartIndex, const int Count) {
712 Init();
713 Copy(Src, StartIndex, Count);
714}
715
716// cStr.ctor : (const char *)
717inline cStr::cStr(const char* Src) {
718 Init();
719 Copy(Src);
720}
721
722inline cStr::cStr(const wchar_t* Src) {
723 Init();
724 Copy(Src);
725}
726
727// cStr.ctor : (const char *, const int, const int)
728inline cStr::cStr(const char* Src, const int StartIndex, const int Count) {
729 Init();
730 Copy(Src, StartIndex, Count);
731}
732
733// cStr.ctor : (const int, const char)
734inline cStr::cStr(const int Length, const char Fill) {
735 Init();
736 SetLength(Length, Fill);
737}
738
739//-----------------------------------------------------------------------------
740// cStr.dtor
741//-----------------------------------------------------------------------------
742
743// cStr.dtor
744inline cStr::~cStr() {
745 Free();
746}
747
748//-----------------------------------------------------------------------------
749// cStr::Copy
750//-----------------------------------------------------------------------------
751
752// cStr::Copy : (const cStr &)
753inline void cStr::Copy(const cStr& Src) {
754 cAssert(Src.IsValid());
755 Copy(Src.m_Str, 0, Src.m_Length);
756}
757
758// cStr::Copy : (const cStr &, const int, const int)
759inline void cStr::Copy(const cStr& Src, const int StartIndex, const int Count) {
760 cAssert(Src.IsValid());
761 Copy(Src.m_Str, StartIndex, Count);
762}
763
764// cStr::Copy : (const char *)
765inline void cStr::Copy(const char* Src) {
766 Copy(Src, 0, Length(Src));
767}
768
769// cStr::operator = : (const cStr &)
770inline void cStr::operator = (const cStr& Src) {
771 Copy(Src);
772}
773
774// cStr::operator = : (const char *)
775inline void cStr::operator = (const char* Src) {
776 Copy(Src);
777}
778
779inline void cStr::operator=(int x) {
780 *this = ToString(x);
781}
782
783//-----------------------------------------------------------------------------
784// cStr::ToCharPtr
785//-----------------------------------------------------------------------------
786
787// None of these casters has cAssert on validity, cause during work with
788// string buffer as with temp storage, its state most probably is not valid.
789
790// cStr::ToCharPtr : const char * () const
791inline const char* cStr::ToCharPtr() const {
792 //cAssert(m_Str != nullptr);
793 return m_Str ? m_Str : &def_str;
794}
795
796// cStr::ToNonConstCharPtr() : char * ()
797inline char* cStr::ToNonConstCharPtr() {
798 return (this && m_Str) ? m_Str : &def_str;
799}
800
801// cStr::operator const char * () const
802inline cStr::operator const char* () const {
803 return (this && m_Str) ? m_Str : &def_str;
804}
805
806// cStr::operator char * ()
807//inline cStr::operator char * () {
808// return (this && m_Str) ? m_Str : &def_str;
809//}
810
811//-----------------------------------------------------------------------------
812// cStr::operator []
813//-----------------------------------------------------------------------------
814
815// cStr::operator [] const
816inline char cStr::operator [] (const int CharIndex) const {
817 cAssert(IsValid());
818 cAssert(CharIndex >= 0);
819 cAssert(CharIndex <= m_Length);
820 return m_Str ? m_Str[CharIndex] : 0;
821}
822
823// cStr::operator []
824inline char& cStr::operator [] (const int CharIndex) {
825 cAssert(IsValid());
826 cAssert(CharIndex >= 0);
827 cAssert(CharIndex <= m_Length);
828 return m_Str ? m_Str[CharIndex] : def_str;
829}
830
831//-----------------------------------------------------------------------------
832// cStr::Length
833//-----------------------------------------------------------------------------
834
835// cStr::Length : ()
836inline int cStr::Length() const {
837 cAssert(IsValid());
838 return m_Length;
839}
840
841// cStr::Length : (const char *)
842inline int cStr::Length(const char* Str) {
843 if (Str == nullptr) {
844 return 0;
845 }
846
847 int l;
848
849 for (l = 0; Str[l] != '\0'; l++) {
850 }
851 return l;
852}
853
854//-----------------------------------------------------------------------------
855// cStr::SetLength / cStr::CalcLength
856//-----------------------------------------------------------------------------
857
858// cStr::SetLength : (const int, const char)
859inline void cStr::SetLength(const int Length, const char Fill) {
860 cAssert(IsValid());
861 cAssert(Length >= 0);
862
863 int i;
864
865 if (Length <= 0) {
866 Free();
867 }
868 else {
869 EnsureCapacity(Length + 1);
870 for (i = 0; i < Length; i++) {
871 m_Str[i] = Fill;
872 }
873 m_Length = Length;
874 m_Str[Length] = '\0';
875
876 }
877}
878
879// cStr::CalcLength
880inline void cStr::CalcLength() {
881 m_Length = Length(m_Str);
882 cAssert(IsValid());
883}
884
885// cStr::Fill : (const char)
886inline void cStr::Fill(const char c) {
887 cAssert(IsValid());
888
889 int i;
890
891 for (i = 0; i < m_Length; i++) {
892 m_Str[i] = c;
893 }
894}
895
896//-----------------------------------------------------------------------------
897// cStr::IsEmpty, cStr::Clear
898//-----------------------------------------------------------------------------
899
900// cStr::IsEmpty
901inline bool cStr::IsEmpty() const {
902 return Equals(m_Str, "");
903}
904
905inline bool cStr::empty() const {
906 return Length() == 0;
907}
908
909// cStr::Clear
910inline void cStr::Clear() {
911 if (m_Str) {
912 EnsureCapacity(1, false);
913 m_Str[0] = '\0';
914 m_Length = 0;
915 }
916 else m_Length = 0;
917}
918
919//-----------------------------------------------------------------------------
920// cStr::Equals(NoCase) (==, !=)
921//-----------------------------------------------------------------------------
922
923// cStr::Equals : bool (const char *, const char *)
924inline bool cStr::Equals(const char* l, const char* r) {
925 return Compare(l, r) == 0;
926}
927
928// cStr::Equals : bool (const char *, const cStr &)
929inline bool cStr::Equals(const char* l, const cStr& r) {
930 cAssert(r.IsValid());
931 return Compare(l, r.ToCharPtr()) == 0;
932}
933
934// cStr::Equals : bool (const cStr &, const char *)
935inline bool cStr::Equals(const cStr& l, const char* r) {
936 cAssert(l.IsValid());
937 return Compare(l.ToCharPtr(), r) == 0;
938}
939
940// cStr::Equals : bool (const cStr &, const cStr &)
941inline bool cStr::Equals(const cStr& l, const cStr& r) {
942 cAssert(l.IsValid());
943 cAssert(r.IsValid());
944 return Compare(l.ToCharPtr(), r.ToCharPtr()) == 0;
945}
946
947// cStr::Equals : bool (const cStr *, const cStr *)
948inline bool cStr::Equals(const cStr* l, const cStr* r) {
949 cAssert(l != nullptr);
950 cAssert(r != nullptr);
951 cAssert(l->IsValid());
952 cAssert(r->IsValid());
953 return Compare(l->ToCharPtr(), r->ToCharPtr()) == 0;
954}
955
956inline bool cStr::Equals(const char* r) const {
957 return cStr::Compare(ToCharPtr(), r) == 0;
958}
959
960// cStr.friend operator == : bool (const char *, const cStr &)
961inline bool operator == (const char* l, const cStr& r) {
962 cAssert(r.IsValid());
963 return cStr::Compare(l, r.ToCharPtr()) == 0;
964}
965
966// cStr.friend operator == : bool (const cStr &, const char *)
967inline bool operator == (const cStr& l, const char* r) {
968 cAssert(l.IsValid());
969 return cStr::Compare(l.ToCharPtr(), r) == 0;
970}
971
972// cStr.friend operator == : bool (const cStr &, const cStr &)
973inline bool operator == (const cStr& l, const cStr& r) {
974 cAssert(l.IsValid());
975 cAssert(r.IsValid());
976 return cStr::Compare(l.ToCharPtr(), r.ToCharPtr()) == 0;
977}
978
979// cStr.friend operator != : bool (const char *, const cStr &)
980inline bool operator != (const char* l, const cStr& r) {
981 cAssert(r.IsValid());
982 return cStr::Compare(l, r.ToCharPtr()) != 0;
983}
984
985// cStr.friend operator != : bool (const cStr &, const char *)
986inline bool operator != (const cStr& l, const char* r) {
987 cAssert(l.IsValid());
988 return cStr::Compare(l.ToCharPtr(), r) != 0;
989}
990
991// cStr.friend operator != : bool (const cStr &, const cStr &)
992inline bool operator != (const cStr& l, const cStr& r) {
993 cAssert(l.IsValid());
994 cAssert(r.IsValid());
995 return cStr::Compare(l.ToCharPtr(), r.ToCharPtr()) != 0;
996}
997
998// cStr::Equals : bool (const char *, const char *, const int)
999inline bool cStr::Equals(const char* l, const char* r, const int MaxLength) {
1000 return Compare(l, r, MaxLength) == 0;
1001}
1002
1003// cStr::Equals : bool (const char *, const cStr &, const int)
1004inline bool cStr::Equals(const char* l, const cStr& r, const int MaxLength) {
1005 cAssert(r.IsValid());
1006 return Compare(l, r.ToCharPtr(), MaxLength) == 0;
1007}
1008
1009// cStr::Equals : bool (const cStr &, const char *, const int)
1010inline bool cStr::Equals(const cStr& l, const char* r, const int MaxLength) {
1011 cAssert(l.IsValid());
1012 return Compare(l.ToCharPtr(), r, MaxLength) == 0;
1013}
1014
1015// cStr::Equals : bool (const cStr &, const cStr &, const int)
1016inline bool cStr::Equals(const cStr& l, const cStr& r, const int MaxLength) {
1017 cAssert(l.IsValid());
1018 cAssert(r.IsValid());
1019 return Compare(l.ToCharPtr(), r.ToCharPtr(), MaxLength) == 0;
1020}
1021
1022// cStr::EqualsNoCase : bool (const char *, const char *)
1023inline bool cStr::EqualsNoCase(const char* l, const char* r) {
1024 return CompareNoCase(l, r) == 0;
1025}
1026
1027// cStr::EqualsNoCase : bool (const char *, const cStr &)
1028inline bool cStr::EqualsNoCase(const char* l, const cStr& r) {
1029 cAssert(r.IsValid());
1030 return CompareNoCase(l, r.ToCharPtr()) == 0;
1031}
1032
1033// cStr::EqualsNoCase : bool (const cStr &, const char *)
1034inline bool cStr::EqualsNoCase(const cStr& l, const char* r) {
1035 cAssert(l.IsValid());
1036 return CompareNoCase(l.ToCharPtr(), r) == 0;
1037}
1038
1039// cStr::EqualsNoCase : bool (const cStr &, const cStr &)
1040inline bool cStr::EqualsNoCase(const cStr& l, const cStr& r) {
1041 cAssert(l.IsValid());
1042 cAssert(r.IsValid());
1043 return CompareNoCase(l.ToCharPtr(), r.ToCharPtr()) == 0;
1044}
1045
1046// cStr::EqualsNoCase : bool (const cStr *, const cStr *)
1047inline bool cStr::EqualsNoCase(const cStr* l, const cStr* r) {
1048 cAssert(l != nullptr);
1049 cAssert(r != nullptr);
1050 cAssert(l->IsValid());
1051 cAssert(r->IsValid());
1052 return CompareNoCase(l->ToCharPtr(), r->ToCharPtr()) == 0;
1053}
1054
1055// cStr::EqualsNoCase : bool (const char *, const char *, const int)
1056inline bool cStr::EqualsNoCase(const char* l, const char* r, const int MaxLength) {
1057 return CompareNoCase(l, r, MaxLength) == 0;
1058}
1059
1060// cStr::EqualsNoCase : bool (const char *, const cStr &, const int)
1061inline bool cStr::EqualsNoCase(const char* l, const cStr& r, const int MaxLength) {
1062 cAssert(r.IsValid());
1063 return CompareNoCase(l, r.ToCharPtr(), MaxLength) == 0;
1064}
1065
1066// cStr::EqualsNoCase : bool (const cStr &, const char *, const int)
1067inline bool cStr::EqualsNoCase(const cStr& l, const char* r, const int MaxLength) {
1068 cAssert(l.IsValid());
1069 return CompareNoCase(l.ToCharPtr(), r, MaxLength) == 0;
1070}
1071
1072// cStr::EqualsNoCase : bool (const cStr &, const cStr &, const int)
1073inline bool cStr::EqualsNoCase(const cStr& l, const cStr& r, const int MaxLength) {
1074 cAssert(l.IsValid());
1075 cAssert(r.IsValid());
1076 return CompareNoCase(l.ToCharPtr(), r.ToCharPtr(), MaxLength) == 0;
1077}
1078
1079//-----------------------------------------------------------------------------
1080// cStr::Compare(NoCase) (>, >=, <, <=)
1081//-----------------------------------------------------------------------------
1082
1083// cStr::Compare : int (const char *, const char *)
1084inline int cStr::Compare(const char* l, const char* r) {
1085 return Compare(l, r, -1);
1086}
1087
1088// cStr::Compare : int (const char *, const cStr &)
1089inline int cStr::Compare(const char* l, const cStr& r) {
1090 cAssert(r.IsValid());
1091 return Compare(l, r.ToCharPtr());
1092}
1093
1094// cStr::Compare : int (const cStr &, const char *)
1095inline int cStr::Compare(const cStr& l, const char* r) {
1096 cAssert(l.IsValid());
1097 return Compare(l.ToCharPtr(), r);
1098}
1099
1100// cStr::Compare : int (const cStr &, const cStr &)
1101inline int cStr::Compare(const cStr& l, const cStr& r) {
1102 cAssert(l.IsValid());
1103 cAssert(r.IsValid());
1104 return Compare(l.ToCharPtr(), r.ToCharPtr());
1105}
1106
1107// cStr::Compare : int (const cStr *, const cStr *)
1108inline int cStr::Compare(const cStr* l, const cStr* r) {
1109 cAssert(l != nullptr);
1110 cAssert(r != nullptr);
1111 cAssert(l->IsValid());
1112 cAssert(r->IsValid());
1113 return Compare(l->ToCharPtr(), r->ToCharPtr());
1114}
1115
1116// cStr.friend operator > : bool (const char *, const cStr &)
1117inline bool operator > (const char* l, const cStr& r) {
1118 cAssert(r.IsValid());
1119 return cStr::Compare(l, r.ToCharPtr()) > 0;
1120}
1121
1122// cStr.friend operator > : bool (const cStr &, const char *)
1123inline bool operator > (const cStr& l, const char* r) {
1124 cAssert(l.IsValid());
1125 return cStr::Compare(l.ToCharPtr(), r) > 0;
1126}
1127
1128// cStr.friend operator > : bool (const cStr &, const cStr &)
1129inline bool operator > (const cStr& l, const cStr& r) {
1130 cAssert(l.IsValid());
1131 cAssert(r.IsValid());
1132 return cStr::Compare(l.ToCharPtr(), r.ToCharPtr()) > 0;
1133}
1134
1135// cStr.friend operator >= : bool (const char *, const cStr &)
1136inline bool operator >= (const char* l, const cStr& r) {
1137 cAssert(r.IsValid());
1138 return cStr::Compare(l, r.ToCharPtr()) >= 0;
1139}
1140
1141// cStr.friend operator >= : bool (const cStr &, const char *)
1142inline bool operator >= (const cStr& l, const char* r) {
1143 cAssert(l.IsValid());
1144 return cStr::Compare(l.ToCharPtr(), r) >= 0;
1145}
1146
1147// cStr.friend operator >= : bool (const cStr &, const cStr &)
1148inline bool operator >= (const cStr& l, const cStr& r) {
1149 cAssert(l.IsValid());
1150 cAssert(r.IsValid());
1151 return cStr::Compare(l.ToCharPtr(), r.ToCharPtr()) >= 0;
1152}
1153
1154// cStr.friend operator < : bool (const char *, const cStr &)
1155inline bool operator < (const char* l, const cStr& r) {
1156 cAssert(r.IsValid());
1157 return cStr::Compare(l, r.ToCharPtr()) < 0;
1158}
1159
1160// cStr.friend operator < : bool (const cStr &, const char *)
1161inline bool operator < (const cStr& l, const char* r) {
1162 cAssert(l.IsValid());
1163 return cStr::Compare(l.ToCharPtr(), r) < 0;
1164}
1165
1166// cStr.friend operator < : bool (const cStr &, const cStr &)
1167inline bool operator < (const cStr& l, const cStr& r) {
1168 cAssert(l.IsValid());
1169 cAssert(r.IsValid());
1170 return cStr::Compare(l.ToCharPtr(), r.ToCharPtr()) < 0;
1171}
1172
1173// cStr.friend operator <= : bool (const char *, const cStr &)
1174inline bool operator <= (const char* l, const cStr& r) {
1175 cAssert(r.IsValid());
1176 return cStr::Compare(l, r.ToCharPtr()) <= 0;
1177}
1178
1179// cStr.friend operator <= : bool (const cStr &, const char *)
1180inline bool operator <= (const cStr& l, const char* r) {
1181 cAssert(l.IsValid());
1182 return cStr::Compare(l.ToCharPtr(), r) <= 0;
1183}
1184
1185// cStr.friend operator <= : bool (const cStr &, const cStr &)
1186inline bool operator <= (const cStr& l, const cStr& r) {
1187 cAssert(l.IsValid());
1188 cAssert(r.IsValid());
1189 return cStr::Compare(l.ToCharPtr(), r.ToCharPtr()) <= 0;
1190}
1191
1192// cStr::Compare : int (const char *, const cStr &, const int)
1193inline int cStr::Compare(const char* l, const cStr& r, const int MaxLength) {
1194 cAssert(r.IsValid());
1195 return Compare(l, r.ToCharPtr(), MaxLength);
1196}
1197
1198// cStr::Compare : int (const cStr &, const char *, const int)
1199inline int cStr::Compare(const cStr& l, const char* r, const int MaxLength) {
1200 cAssert(l.IsValid());
1201 return Compare(l.ToCharPtr(), r, MaxLength);
1202}
1203
1204// cStr::Compare : int (const cStr &, const cStr &, const int)
1205inline int cStr::Compare(const cStr& l, const cStr& r, const int MaxLength) {
1206 cAssert(l.IsValid());
1207 cAssert(r.IsValid());
1208 return Compare(l.ToCharPtr(), r.ToCharPtr(), MaxLength);
1209}
1210
1211// cStr::CompareNoCase : int (const char *, const char *)
1212inline int cStr::CompareNoCase(const char* l, const char* r) {
1213 return CompareNoCase(l, r, -1);
1214}
1215
1216// cStr::CompareNoCase : int (const char *, const cStr &)
1217inline int cStr::CompareNoCase(const char* l, const cStr& r) {
1218 cAssert(r.IsValid());
1219 return CompareNoCase(l, r.ToCharPtr());
1220}
1221
1222// cStr::CompareNoCase : int (const cStr &, const char *)
1223inline int cStr::CompareNoCase(const cStr& l, const char* r) {
1224 cAssert(l.IsValid());
1225 return CompareNoCase(l.ToCharPtr(), r);
1226}
1227
1228// cStr::CompareNoCase : int (const cStr &, const cStr &)
1229inline int cStr::CompareNoCase(const cStr& l, const cStr& r) {
1230 cAssert(l.IsValid());
1231 cAssert(r.IsValid());
1232 return CompareNoCase(l.ToCharPtr(), r.ToCharPtr());
1233}
1234
1235// cStr::CompareNoCase : int (const cStr *, const cStr *)
1236inline int cStr::CompareNoCase(const cStr* l, const cStr* r) {
1237 cAssert(l != nullptr);
1238 cAssert(r != nullptr);
1239 cAssert(l->IsValid());
1240 cAssert(r->IsValid());
1241 return CompareNoCase(l->ToCharPtr(), r->ToCharPtr());
1242}
1243
1244// cStr::CompareNoCase : int (const char *, const cStr &, const int)
1245inline int cStr::CompareNoCase(const char* l, const cStr& r, const int MaxLength) {
1246 cAssert(r.IsValid());
1247 return CompareNoCase(l, r.ToCharPtr(), MaxLength);
1248}
1249
1250// cStr::CompareNoCase : int (const cStr &, const char *, const int)
1251inline int cStr::CompareNoCase(const cStr& l, const char* r, const int MaxLength) {
1252 cAssert(l.IsValid());
1253 return CompareNoCase(l.ToCharPtr(), r, MaxLength);
1254}
1255
1256// cStr::CompareNoCase : int (const cStr &, const cStr &, const int)
1257inline int cStr::CompareNoCase(const cStr& l, const cStr& r, const int MaxLength) {
1258 cAssert(l.IsValid());
1259 cAssert(r.IsValid());
1260 return CompareNoCase(l.ToCharPtr(), r.ToCharPtr(), MaxLength);
1261}
1262
1263//-----------------------------------------------------------------------------
1264// cStr::EqualsPath
1265//-----------------------------------------------------------------------------
1266
1267// cStr::EqualsPath : bool (const char *, const char *)
1268inline bool cStr::EqualsPath(const char* l, const char* r) {
1269 return ComparePath(l, r) == 0;
1270}
1271
1272// cStr::EqualsPath : bool (const char *, const cStr &)
1273inline bool cStr::EqualsPath(const char* l, const cStr& r) {
1274 cAssert(r.IsValid());
1275 return ComparePath(l, r.ToCharPtr()) == 0;
1276}
1277
1278// cStr::EqualsPath : bool (const cStr &, const char *)
1279inline bool cStr::EqualsPath(const cStr& l, const char* r) {
1280 cAssert(l.IsValid());
1281 return ComparePath(l.ToCharPtr(), r) == 0;
1282}
1283
1284// cStr::EqualsPath : bool (const cStr &, const cStr &)
1285inline bool cStr::EqualsPath(const cStr& l, const cStr& r) {
1286 cAssert(l.IsValid());
1287 cAssert(r.IsValid());
1288 return ComparePath(l.ToCharPtr(), r.ToCharPtr()) == 0;
1289}
1290
1291// cStr::EqualsPath : bool (const cStr *, const cStr *)
1292inline bool cStr::EqualsPath(const cStr* l, const cStr* r) {
1293 cAssert(l != nullptr);
1294 cAssert(r != nullptr);
1295 cAssert(l->IsValid());
1296 cAssert(r->IsValid());
1297 return ComparePath(l->ToCharPtr(), r->ToCharPtr()) == 0;
1298}
1299
1300// cStr::EqualsPath : bool (const char *, const char *, const int)
1301inline bool cStr::EqualsPath(const char* l, const char* r, const int MaxLength) {
1302 return ComparePath(l, r, MaxLength) == 0;
1303}
1304
1305// cStr::EqualsPath : bool (const char *, const cStr &, const int)
1306inline bool cStr::EqualsPath(const char* l, const cStr& r, const int MaxLength) {
1307 cAssert(r.IsValid());
1308 return ComparePath(l, r.ToCharPtr(), MaxLength) == 0;
1309}
1310
1311// cStr::EqualsPath : bool (const cStr &, const char *, const int)
1312inline bool cStr::EqualsPath(const cStr& l, const char* r, const int MaxLength) {
1313 cAssert(l.IsValid());
1314 return ComparePath(l.ToCharPtr(), r, MaxLength) == 0;
1315}
1316
1317// cStr::EqualsPath : bool (const cStr &, const cStr &, const int)
1318inline bool cStr::EqualsPath(const cStr& l, const cStr& r, const int MaxLength) {
1319 cAssert(l.IsValid());
1320 cAssert(r.IsValid());
1321 return ComparePath(l.ToCharPtr(), r.ToCharPtr(), MaxLength) == 0;
1322}
1323
1324//-----------------------------------------------------------------------------
1325// cStr::ComparePath
1326//-----------------------------------------------------------------------------
1327
1328// cStr::ComparePath : int (const char *, const char *)
1329inline int cStr::ComparePath(const char* l, const char* r) {
1330 return ComparePath(l, r, -1);
1331}
1332
1333// cStr::ComparePath : int (const char *, const cStr &)
1334inline int cStr::ComparePath(const char* l, const cStr& r) {
1335 cAssert(r.IsValid());
1336 return ComparePath(l, r.ToCharPtr());
1337}
1338
1339// cStr::ComparePath : int (const cStr &, const char *)
1340inline int cStr::ComparePath(const cStr& l, const char* r) {
1341 cAssert(l.IsValid());
1342 return ComparePath(l.ToCharPtr(), r);
1343}
1344
1345// cStr::ComparePath : int (const cStr &, const cStr &)
1346inline int cStr::ComparePath(const cStr& l, const cStr& r) {
1347 cAssert(l.IsValid());
1348 cAssert(r.IsValid());
1349 return ComparePath(l.ToCharPtr(), r.ToCharPtr());
1350}
1351
1352// cStr::ComparePath : int (const cStr *, const cStr *)
1353inline int cStr::ComparePath(const cStr* l, const cStr* r) {
1354 cAssert(l != nullptr);
1355 cAssert(r != nullptr);
1356 cAssert(l->IsValid());
1357 cAssert(r->IsValid());
1358 return ComparePath(l->ToCharPtr(), r->ToCharPtr());
1359}
1360
1361// cStr::ComparePath : int (const char *, const cStr &, const int)
1362inline int cStr::ComparePath(const char* l, const cStr& r, const int MaxLength) {
1363 cAssert(r.IsValid());
1364 return ComparePath(l, r.ToCharPtr(), MaxLength);
1365}
1366
1367// cStr::ComparePath : int (const cStr &, const char *, const int)
1368inline int cStr::ComparePath(const cStr& l, const char* r, const int MaxLength) {
1369 cAssert(l.IsValid());
1370 return ComparePath(l.ToCharPtr(), r, MaxLength);
1371}
1372
1373// cStr::ComparePath : int (const cStr &, const cStr &, const int)
1374inline int cStr::ComparePath(const cStr& l, const cStr& r, const int MaxLength) {
1375 cAssert(l.IsValid());
1376 cAssert(r.IsValid());
1377 return ComparePath(l.ToCharPtr(), r.ToCharPtr(), MaxLength);
1378}
1379
1380//-----------------------------------------------------------------------------
1381// cStr::StartsWith / cStr::EndsWith
1382//-----------------------------------------------------------------------------
1383
1384// cStr::StartsWith
1385inline bool cStr::StartsWith(const char* Str, const bool NoCase) const {
1386 cAssert(IsValid());
1387 cAssert(Str != nullptr);
1388
1389 int L;
1390
1391 L = Length(Str);
1392 return NoCase ? EqualsNoCase(m_Str, Str, L) : Equals(m_Str, Str, L);
1393}
1394
1395// cStr::EndsWith
1396inline bool cStr::EndsWith(const char* Str, const bool NoCase) const {
1397 cAssert(IsValid());
1398 cAssert(Str != nullptr);
1399
1400 int L;
1401
1402 L = Length(Str);
1403 if (L > m_Length) {
1404 return false;
1405 }
1406
1407 return NoCase ? EqualsNoCase(&m_Str[m_Length - L], Str) : Equals(&m_Str[m_Length - L], Str);
1408} // cStr::EndsWith
1409
1410//-----------------------------------------------------------------------------
1411// cStr::ToString
1412//-----------------------------------------------------------------------------
1413
1414// cStr::ToString : (const bool)
1415inline const cStr cStr::ToString(const bool b) {
1416 return b ? "True" : "False";
1417}
1418
1419// cStr::ToString : (const int)
1420inline const cStr cStr::ToString(const int i) {
1421 return Format("%d", i);
1422}
1423
1424// cStr::ToString : (const int, const int)
1425inline const cStr cStr::ToString(const int i, const int Prec) {
1426 return Format(Format("%%0%dd", Prec), i);
1427}
1428
1429// cStr::ToString : (const float, ...)
1430inline const cStr cStr::ToString(const float f, const int Prec) {
1431 cStr S = Format(Format("%%.%df", Prec), f);
1432 S.Replace(',', '.');
1433 return S;
1434}
1435
1436// cStr::ToString : (const double, ...)
1437inline const cStr cStr::ToString(const double d, const int Prec) {
1438 cStr S = Format(Format("%%.%df", Prec), d);
1439 S.Replace(',', '.');
1440 return S;
1441}
1442
1443// cStr::ToHex : (dword)
1444inline const cStr cStr::ToHex(const dword dw) {
1445 return cStr::Format("0x%08x", dw);
1446}
1447
1448// cStr::ToHex : (qword)
1449inline const cStr cStr::ToHex(const qword qw) {
1450 return cStr::Format("0x%016llx", qw);
1451}
1452
1453// cStr::ToHex : (void *)
1454inline const cStr cStr::ToHex(const void* Ptr) {
1455 return cStr::Format("%p", Ptr);
1456}
1457
1458//-----------------------------------------------------------------------------
1459// cStr::Append
1460//-----------------------------------------------------------------------------
1461
1462// cStr::Append : (const cStr &)
1463inline void cStr::Append(const cStr& Src) {
1464 Append(Src, 0, Src.m_Length);
1465}
1466
1467// cStr::Append : (const char *)
1468inline void cStr::Append(const char* Src) {
1469 Append(Src, 0, Length(Src));
1470}
1471
1472inline void cStr::Append(const wchar_t* Src) {
1473 cStr r(Src);
1474 Append(r);
1475}
1476
1477// cStr::Append : (const char)
1478inline void cStr::Append(const char c) {
1479 Append(c, 1);
1480}
1481
1482// cStr::Append : (const bool)
1483inline void cStr::Append(const bool b) {
1484 Append(ToString(b));
1485}
1486
1487// cStr::Append : (const int)
1488inline void cStr::Append(const int i) {
1489 Append(ToString(i));
1490}
1491
1492// cStr::Append : (const float, const int)
1493inline void cStr::Append(const float f, const int Prec) {
1494 Append(ToString(f, Prec));
1495}
1496
1497// cStr::Append : (const double, const int)
1498inline void cStr::Append(const double d, const int Prec) {
1499 Append(ToString(d, Prec));
1500}
1501
1502//*****************************************************************************
1503// cStr::operator +=
1504//*****************************************************************************
1505
1506// cStr::operator += : (const cStr &)
1507inline void cStr::operator += (const cStr& Src) {
1508 Append(Src);
1509}
1510
1511// cStr::operator += : (const char *)
1512inline void cStr::operator += (const char* Src) {
1513 Append(Src);
1514}
1515
1516inline void cStr::operator += (const wchar_t* Src) {
1517 Append(Src);
1518}
1519
1520// cStr::operator += : (const char)
1521inline void cStr::operator += (const char c) {
1522 Append(c);
1523}
1524
1525// cStr::operator += (const bool)
1526inline void cStr::operator += (const bool b) {
1527 Append(b);
1528}
1529
1530// cStr::operator += : (const int)
1531inline void cStr::operator += (const int i) {
1532 Append(i);
1533}
1534
1535// cStr::operator += : (const float)
1536inline void cStr::operator += (const float f) {
1537 Append(f);
1538}
1539
1540// cStr::operator += : (const double)
1541inline void cStr::operator += (const double d) {
1542 Append(d);
1543}
1544
1545//*****************************************************************************
1546// cStr::operator <<
1547//*****************************************************************************
1548
1549// cStr::operator << : (const cStr &)
1550inline cStr& cStr::operator << (const cStr& Src) {
1551 Append(Src);
1552 return *this;
1553}
1554
1555// cStr::operator << : (const char *)
1556inline cStr& cStr::operator << (const char* Src) {
1557 Append(Src);
1558 return *this;
1559}
1560
1561inline cStr& cStr::operator << (const wchar_t* Src) {
1562 Append(Src);
1563 return *this;
1564}
1565
1566// cStr::operator << : (const char)
1567inline cStr& cStr::operator << (const char c) {
1568 Append(c);
1569 return *this;
1570}
1571
1572// cStr::operator << : (const bool)
1573inline cStr& cStr::operator << (const bool b) {
1574 Append(b);
1575 return *this;
1576}
1577
1578// cStr::operator << : (const int)
1579inline cStr& cStr::operator << (const int i) {
1580 Append(i);
1581 return *this;
1582}
1583
1584// cStr::operator << : (const float)
1585inline cStr& cStr::operator << (const float f) {
1586 Append(f);
1587 return *this;
1588}
1589
1590// cStr::operator << : (const double)
1591inline cStr& cStr::operator << (const double d) {
1592 Append(d);
1593 return *this;
1594}
1595
1596//*****************************************************************************
1597// cStr::friend operator +
1598//*****************************************************************************
1599
1600// cStr::friend operator + : (const cStr &, const cStr &)
1601inline const cStr operator + (const cStr& l, const cStr& r) {
1602 cStr t(l);
1603 t.Append(r);
1604 return t;
1605}
1606
1607// cStr::friend operator + : (const cStr &, const char *)
1608inline const cStr operator + (const cStr& l, const char* r) {
1609 cStr t(l);
1610 t.Append(r);
1611 return t;
1612}
1613
1614// cStr::friend operator + : (const char *, const cStr &)
1615inline const cStr operator + (const char* l, const cStr& r) {
1616 cStr t(l);
1617 t.Append(r);
1618 return t;
1619}
1620
1621// cStr::friend operator + : (const cStr &, const char)
1622inline const cStr operator + (const cStr& l, const char c) {
1623 cStr t(l);
1624 t.Append(c);
1625 return t;
1626}
1627
1628// cStr::friend operator + : (const char, const cStr &)
1629inline const cStr operator + (const char c, const cStr& r) {
1630 cStr t;
1631 t.Append(c);
1632 t.Append(r);
1633 return t;
1634}
1635
1636// cStr::friend operator + : (const cStr &, const bool)
1637inline const cStr operator + (const cStr& l, const bool b) {
1638 cStr t(l);
1639 t.Append(b);
1640 return t;
1641}
1642
1643// cStr::friend operator + : (const bool, const cStr &)
1644inline const cStr operator + (const bool b, const cStr& r) {
1645 cStr t;
1646 t.Append(b);
1647 t.Append(r);
1648 return t;
1649}
1650
1651// cStr::friend operator + : (const cStr &, const int)
1652inline const cStr operator + (const cStr& l, const int i) {
1653 cStr t(l);
1654 t.Append(i);
1655 return t;
1656}
1657
1658// cStr::friend operator + : (const int, const cStr &)
1659inline const cStr operator + (const int i, const cStr& r) {
1660 cStr t;
1661 t.Append(i);
1662 t.Append(r);
1663 return t;
1664}
1665
1666// cStr::friend operator + : (const cStr &, const float)
1667inline const cStr operator + (const cStr& l, const float f) {
1668 cStr t(l);
1669 t.Append(f);
1670 return t;
1671}
1672
1673// cStr::friend operator + : (const float, const cStr &)
1674inline const cStr operator + (const float f, const cStr& r) {
1675 cStr t;
1676 t.Append(f);
1677 t.Append(r);
1678 return t;
1679}
1680
1681// cStr::friend operator + : (const cStr &, const double)
1682inline const cStr operator + (const cStr& l, const double d) {
1683 cStr t(l);
1684 t.Append(d);
1685 return t;
1686}
1687
1688// cStr::friend operator + : (const double, const cStr &)
1689inline const cStr operator + (const double d, const cStr& r) {
1690 cStr t;
1691 t.Append(d);
1692 t.Append(r);
1693 return t;
1694}
1695
1696inline const cStr operator + (const cStr& l, const wchar_t* r) {
1697 cStr s(l);
1698 s.Append(r);
1699 return s;
1700}
1701inline const cStr operator + (const wchar_t* l, const cStr& r) {
1702 cStr s(l);
1703 s.Append(r);
1704 return s;
1705}
1706
1707//-----------------------------------------------------------------------------
1708// cStr::Insert
1709//-----------------------------------------------------------------------------
1710
1711// cStr::Insert : (..., const cStr &)
1712inline void cStr::Insert(const int Index, const cStr& Src) {
1713 Insert(Index, Src, 0, Src.m_Length);
1714}
1715
1716// cStr::Insert : (..., const char *)
1717inline void cStr::Insert(const int Index, const char* Src) {
1718 Insert(Index, Src, 0, Length(Src));
1719}
1720
1721// cStr::Insert : (..., const char)
1722inline void cStr::Insert(const int Index, const char c) {
1723 Insert(Index, c, 1);
1724}
1725
1726// cStr::Insert : (..., const bool)
1727inline void cStr::Insert(const int Index, const bool b) {
1728 Insert(Index, ToString(b));
1729}
1730
1731// cStr::Insert : (..., const int)
1732inline void cStr::Insert(const int Index, const int i) {
1733 Insert(Index, ToString(i));
1734}
1735
1736// cStr::Insert : (..., const float, ...)
1737inline void cStr::Insert(const int Index, const float f, const int Prec) {
1738 Insert(Index, ToString(f, Prec));
1739}
1740
1741// cStr::Insert : (..., const double, ...)
1742inline void cStr::Insert(const int Index, const double d, const int Prec) {
1743 Insert(Index, ToString(d, Prec));
1744}
1745
1746//-----------------------------------------------------------------------------
1747// cStr::Remove
1748//-----------------------------------------------------------------------------
1749
1750// cStr::Remove : (const int)
1751inline void cStr::Remove(const int StartIndex) {
1752 Remove(StartIndex, m_Length - StartIndex);
1753}
1754
1755// cStr::Remove : (const int, const int)
1756inline void cStr::Remove(const int StartIndex, const int Count) {
1757 cAssert(IsValid());
1758 cAssert(StartIndex >= 0);
1759 cAssert(Count >= 0);
1760 cAssert(StartIndex + Count <= m_Length);
1761
1762 if (Count > 0) {
1763 memmove(&m_Str[StartIndex], &m_Str[StartIndex + Count], m_Length - (StartIndex + Count) + 1);
1764 m_Length -= Count;
1765 }
1766}
1767
1768//-----------------------------------------------------------------------------
1769// cStr::Replace : (const char, const char, ...)
1770//-----------------------------------------------------------------------------
1771
1772// cStr::Replace : (const char, const char)
1773inline void cStr::Replace(const char Char, const char WithChar) {
1774 Replace(Char, WithChar, 0, m_Length);
1775}
1776
1777//-----------------------------------------------------------------------------
1778// cStr::Replace : (const char *, const char *, ...)
1779//-----------------------------------------------------------------------------
1780
1781// cStr::Replace : (const char *, const char *)
1782inline int cStr::Replace(const char* String, const char* WithString, const bool NoCase) {
1783 return Replace(String, WithString, 0, m_Length, NoCase);
1784}
1785
1786// cStr::Replace : (const char *, const char *, const int)
1787inline int cStr::Replace(const char* String, const char* WithString, const int StartIndex, const bool NoCase) {
1788 return Replace(String, WithString, StartIndex, m_Length - StartIndex, NoCase);
1789}
1790
1791//-----------------------------------------------------------------------------
1792// cStr::ReplaceFirst : (const char *, const char *, ...)
1793//-----------------------------------------------------------------------------
1794
1795// cStr::ReplaceFirst : (const char *, const char *)
1796inline int cStr::ReplaceFirst(const char* String, const char* WithString, const bool NoCase) {
1797 return ReplaceFirst(String, WithString, 0, m_Length, NoCase);
1798}
1799
1800//-----------------------------------------------------------------------------
1801// cStr::ReplaceAny : (const char *, const char, ...)
1802//-----------------------------------------------------------------------------
1803
1804// cStr::ReplaceAny : (const char *, const char)
1805inline void cStr::ReplaceAny(const char* Chars, const char WithChar) {
1806 ReplaceAny(Chars, WithChar, 0, m_Length);
1807}
1808
1809//-----------------------------------------------------------------------------
1810// cStr::Substring
1811//-----------------------------------------------------------------------------
1812
1813// cStr::Substring : (const int)
1814inline const cStr cStr::Substring(const int StartIndex) const {
1815 cAssert(IsValid());
1816 cAssert(StartIndex >= 0);
1817 cAssert(StartIndex <= m_Length); // For empty string returns empty string
1818 return cStr(m_Str, StartIndex, m_Length - StartIndex);
1819}
1820
1821// cStr::Substring : (const int, const int)
1822inline const cStr cStr::Substring(const int StartIndex, const int Count) const {
1823 cAssert(IsValid());
1824 cAssert(StartIndex >= 0);
1825 cAssert(Count >= 0);
1826 cAssert(StartIndex + Count <= m_Length);
1827 return cStr(m_Str, StartIndex, Count);
1828}
1829
1830//-----------------------------------------------------------------------------
1831// cStr::Trim...
1832//-----------------------------------------------------------------------------
1833
1834// cStr::TrimStart
1835inline void cStr::TrimStart(const char* TrimChars) {
1836 cAssert(IsValid());
1837 if (m_Str) {
1838 cStr t(TrimChars);
1839 while (t.Contains(m_Str[0])) {
1840 memmove(&m_Str[0], &m_Str[1], m_Length);
1841 m_Length--;
1842 }
1843 }
1844}
1845
1846// cStr::TrimEnd
1847inline void cStr::TrimEnd(const char* TrimChars) {
1848 cAssert(IsValid());
1849 if (m_Str) {
1850 int i;
1851 cStr t(TrimChars);
1852 for (i = m_Length; i > 0 && t.Contains(m_Str[i - 1]); i--) {
1853 m_Str[i - 1] = '\0';
1854 m_Length--;
1855 }
1856 }
1857}
1858
1859// cStr::Trim
1860inline void cStr::Trim(const char* TrimChars) {
1861 TrimStart(TrimChars);
1862 TrimEnd(TrimChars);
1863}
1864
1865//-----------------------------------------------------------------------------
1866// cStr::PadLeft / PadRight
1867//-----------------------------------------------------------------------------
1868
1869// cStr::PadLeft
1870inline void cStr::PadLeft(const int TotalWidth, const char PaddingChar) {
1871 cAssert(IsValid());
1872 cAssert(TotalWidth >= 0);
1873
1874 const char TrimChars[2] = {
1875 PaddingChar, '\0'
1876 };
1877
1878 TrimStart(TrimChars);
1879 if (TotalWidth > m_Length) {
1880 Insert(0, PaddingChar, TotalWidth - m_Length);
1881 }
1882}
1883
1884// cStr::PadRight
1885inline void cStr::PadRight(const int TotalWidth, const char PaddingChar) {
1886 cAssert(IsValid());
1887 cAssert(TotalWidth >= 0);
1888
1889 const char TrimChars[2] = {
1890 PaddingChar, '\0'
1891 };
1892
1893 TrimEnd(TrimChars);
1894 if (TotalWidth > m_Length) {
1895 Append(PaddingChar, TotalWidth - m_Length);
1896 }
1897}
1898
1899//-----------------------------------------------------------------------------
1900// cStr::Contains
1901//-----------------------------------------------------------------------------
1902
1903// cStr::Contains : (const char)
1904inline bool cStr::Contains(const char c) const {
1905 return IndexOf(c, 0, m_Length) != -1;
1906}
1907
1908// cStr::Contains : (const char *, const bool)
1909inline bool cStr::Contains(const char* Str, const bool NoCase) const {
1910 return IndexOf(Str, 0, m_Length, NoCase) != -1;
1911}
1912
1913//-----------------------------------------------------------------------------
1914// cStr::IndexOf : (const char, ...)
1915//-----------------------------------------------------------------------------
1916
1917// cStr::IndexOf : (const char)
1918inline int cStr::IndexOf(const char c) const {
1919 return IndexOf(c, 0, m_Length);
1920}
1921
1922// cStr::IndexOf : (const char *, const char)
1923inline int cStr::IndexOf(const char* Src, const char c) {
1924 cAssert(Src != nullptr);
1925 int i = -1, j;
1926 if (Src != nullptr) {
1927 j = 0;
1928 while (*Src != '\0') {
1929 if (*Src == c) {
1930 i = j;
1931 break;
1932 }
1933 Src++;
1934 j++;
1935 }
1936 }
1937 return i;
1938}
1939
1940// cStr::IndexOf : (const char, const int)
1941inline int cStr::IndexOf(const char c, const int StartIndex) const {
1942 return IndexOf(c, StartIndex, m_Length - StartIndex);
1943}
1944
1945// cStr::IndexOf : (const char, const int, const int)
1946inline int cStr::IndexOf(const char c, const int StartIndex, const int Count) const {
1947 cAssert(IsValid());
1948 cAssert(StartIndex >= 0);
1949 cAssert(Count >= 0);
1950 cAssert(StartIndex + Count <= m_Length);
1951 if (m_Str) {
1952 int i1, i;
1953
1954 i1 = StartIndex + Count - 1;
1955 for (i = StartIndex; i <= i1; i++) {
1956 if (m_Str[i] == c) {
1957 return i;
1958 }
1959 }
1960 }
1961
1962 return -1;
1963} // cStr::IndexOf : (const char, ...)
1964
1965//-----------------------------------------------------------------------------
1966// cStr::IndexOf : (const char *, ...)
1967//-----------------------------------------------------------------------------
1968
1969// cStr::IndexOf : (const char *, const bool)
1970inline int cStr::IndexOf(const char* Str, const bool NoCase) const {
1971 return IndexOf(Str, 0, m_Length, NoCase);
1972}
1973
1974// cStr::IndexOf : (const char *, const int, const bool)
1975inline int cStr::IndexOf(const char* Str, const int StartIndex, const bool NoCase) const {
1976 return IndexOf(Str, StartIndex, m_Length - StartIndex, NoCase);
1977}
1978
1979// cStr::IndexOf : (const char *, const int, const int, const bool)
1980inline int cStr::IndexOf(const char* Str, const int StartIndex, const int Count, const bool NoCase) const {
1981 cAssert(IsValid());
1982 cAssert(StartIndex >= 0);
1983 cAssert(Count >= 0);
1984 cAssert(StartIndex + Count <= m_Length);
1985 if (m_Str) {
1986 int L, i1, i;
1987
1988 L = Length(Str);
1989 i1 = StartIndex + Count - 1;
1990
1991 for (i = StartIndex; i <= i1; i++) {
1992 if (NoCase ? EqualsNoCase(&m_Str[i], Str, L) : Equals(&m_Str[i], Str, L)) {
1993 return i;
1994 }
1995 }
1996 }
1997
1998 return -1;
1999} // cStr::IndexOf : (const char *, ...)
2000
2001//-----------------------------------------------------------------------------
2002// cStr::IndexOfAny
2003//-----------------------------------------------------------------------------
2004
2005// cStr::IndexOfAny : (const char *)
2006inline int cStr::IndexOfAny(const char* Chars) const {
2007 return IndexOfAny(Chars, 0, m_Length);
2008}
2009
2010// cStr::IndexOfAny : (const char *, const int)
2011inline int cStr::IndexOfAny(const char* Chars, const int StartIndex) const {
2012 return IndexOfAny(Chars, StartIndex, m_Length - StartIndex);
2013}
2014
2015// cStr::IndexOfAny : (const char *, const int, const int)
2016inline int cStr::IndexOfAny(const char* Chars, const int StartIndex, const int Count) const {
2017 cAssert(IsValid());
2018 cAssert(StartIndex >= 0);
2019 cAssert(Count >= 0);
2020 cAssert(StartIndex + Count <= m_Length);
2021 if (m_Str) {
2022 int i1, i;
2023 char c;
2024 cStr t(Chars);
2025
2026 i1 = StartIndex + Count - 1;
2027 for (i = StartIndex; i <= i1; i++) {
2028 c = m_Str[i];
2029 if (t.Contains(c)) {
2030 return i;
2031 }
2032 }
2033 }
2034
2035 return -1;
2036} // cStr::IndexOfAny : (const char *, ...)
2037
2038//-----------------------------------------------------------------------------
2039// cStr::LastIndexOf : (const char, ...)
2040//-----------------------------------------------------------------------------
2041
2042// cStr::LastIndexOf : (const char)
2043inline int cStr::LastIndexOf(const char c) const {
2044 return LastIndexOf(c, m_Length - 1, m_Length);
2045}
2046
2047// cStr::LastIndexOf : (const char, const int)
2048inline int cStr::LastIndexOf(const char c, const int StartIndex) const {
2049 return LastIndexOf(c, StartIndex, StartIndex + 1);
2050}
2051
2052// cStr::LastIndexOf : (const char, const int, const int)
2053inline int cStr::LastIndexOf(const char c, const int StartIndex, const int Count) const {
2054 cAssert(IsValid());
2055 cAssert(Count >= 0);
2056
2057 if (m_Length == 0 || m_Str == nullptr) {
2058 cAssert(StartIndex >= -1);
2059 cAssert(StartIndex <= 0);
2060
2061 return -1;
2062 }
2063
2064 cAssert(StartIndex >= 0);
2065 cAssert(StartIndex < m_Length);
2066 cAssert(Count <= StartIndex + 1);
2067
2068 int i0, i;
2069
2070 i0 = StartIndex - Count + 1;
2071 for (i = StartIndex; i >= i0; i--) {
2072 if (c == m_Str[i]) {
2073 return i;
2074 }
2075 }
2076
2077 return -1;
2078} // cStr::LastIndexOf : (const char, ...)
2079
2080//-----------------------------------------------------------------------------
2081// cStr::LastIndexOf : (const char *, ...)
2082//-----------------------------------------------------------------------------
2083
2084// cStr::LastIndexOf : (const char *, const bool)
2085inline int cStr::LastIndexOf(const char* Str, const bool NoCase) const {
2086 return LastIndexOf(Str, m_Length - 1, m_Length, NoCase);
2087}
2088
2089// cStr::LastIndexOf : (const char *, const int, const bool)
2090inline int cStr::LastIndexOf(const char* Str, const int StartIndex, const bool NoCase) const {
2091 return LastIndexOf(Str, StartIndex, StartIndex + 1, NoCase);
2092}
2093
2094// cStr::LastIndexOf : (const char *, const int, const int, const bool)
2095inline int cStr::LastIndexOf(const char* Str, const int StartIndex, const int Count, const bool NoCase) const {
2096 cAssert(IsValid());
2097 cAssert(Count >= 0);
2098 if (m_Str == nullptr)return -1;
2099
2100 int L, i0, i;
2101
2102 L = Length(Str);
2103
2104 if (m_Length == 0) {
2105 cAssert(StartIndex >= -1);
2106 cAssert(StartIndex <= 0);
2107
2108 if (L > 0) {
2109 return -1;
2110 }
2111 return 0;
2112 }
2113
2114 cAssert(StartIndex >= 0);
2115 cAssert(StartIndex < m_Length);
2116 cAssert(Count <= StartIndex + 1);
2117
2118 i0 = StartIndex - Count + 1;
2119 for (i = StartIndex; i >= i0; i--) {
2120 if (NoCase ? EqualsNoCase(&m_Str[i], Str, L) : Equals(&m_Str[i], Str, L)) {
2121 return i;
2122 }
2123 }
2124
2125 return -1;
2126} // cStr::LastIndexOf : (const char *, ...)
2127
2128//-----------------------------------------------------------------------------
2129// cStr::LastIndexOfAny
2130//-----------------------------------------------------------------------------
2131
2132// cStr::LastIndexOfAny : (const char *)
2133inline int cStr::LastIndexOfAny(const char* Chars) const {
2134 return LastIndexOfAny(Chars, m_Length - 1, m_Length);
2135}
2136
2137// cStr::LastIndexOfAny : (const char *, const int)
2138inline int cStr::LastIndexOfAny(const char* Chars, const int StartIndex) const {
2139 return LastIndexOfAny(Chars, StartIndex, StartIndex + 1);
2140}
2141
2142// cStr::LastIndexOfAny : (const char *, const int, const int)
2143inline int cStr::LastIndexOfAny(const char* Chars, const int StartIndex, const int Count) const {
2144 cAssert(IsValid());
2145 cAssert(Count >= 0);
2146 if (m_Str == nullptr)return -1;
2147 if (m_Length == 0) {
2148 cAssert(StartIndex >= -1);
2149 cAssert(StartIndex <= 0);
2150
2151 return -1;
2152 }
2153
2154 cAssert(StartIndex >= 0);
2155 cAssert(StartIndex < m_Length);
2156 cAssert(Count <= StartIndex + 1);
2157
2158 int i0, i;
2159 char c;
2160 cStr t(Chars);
2161
2162 i0 = StartIndex - Count + 1;
2163 for (i = StartIndex; i >= i0; i--) {
2164 c = m_Str[i];
2165 if (t.Contains(c)) {
2166 return i;
2167 }
2168 }
2169
2170 return -1;
2171} // cStr::LastIndexOfAny
2172
2173
2174//-----------------------------------------------------------------------------
2175// ToLower / ToUpper, MakeLower / MakeUpper
2176//-----------------------------------------------------------------------------
2177
2178// cStr::ToLower : (const char)
2179inline char cStr::ToLower(const char c) {
2180 if (c >= 'A' && c <= 'Z') {
2181 return c + ('a' - 'A');
2182 }
2183 return c;
2184}
2185
2186// cStr::ToUpper : (const char)
2187inline char cStr::ToUpper(const char c) {
2188 if (c >= 'a' && c <= 'z') {
2189 return c - ('a' - 'A');
2190 }
2191 return c;
2192}
2193
2194// cStr::MakeLower
2195inline void cStr::MakeLower(int start) {
2196 cAssert(IsValid());
2197 if (m_Str == nullptr)return;
2198 int i;
2199 for (i = start; i < m_Length; i++) {
2200 m_Str[i] = ToLower(m_Str[i]);
2201 }
2202}
2203
2204// cStr::MakeUpper
2205inline void cStr::MakeUpper(int start) {
2206 cAssert(IsValid());
2207 if (m_Str == nullptr)return;
2208 int i;
2209 for (i = start; i < m_Length; i++) {
2210 m_Str[i] = ToUpper(m_Str[i]);
2211 }
2212}
2213
2214// cStr::ToLower : const cStr () const
2215inline const cStr cStr::ToLower() const {
2216 cStr S = *this;
2217 S.MakeLower();
2218 return S;
2219}
2220
2221// cStr::ToUpper : const cStr () const
2222inline const cStr cStr::ToUpper() const {
2223 cStr S = *this;
2224 S.MakeUpper();
2225 return S;
2226}
2227
2228//-----------------------------------------------------------------------------
2229// cStr::Join
2230//-----------------------------------------------------------------------------
2231
2232// cStr::Join : (const char *, const cList<cStr> &)
2233inline const cStr cStr::Join(const char* Separator, const cList<cStr>& Strings) {
2234 return Join(Separator, Strings, 0, Strings.Count());
2235}
2236
2237//-----------------------------------------------------------------------------
2238// cStr::Split
2239//-----------------------------------------------------------------------------
2240
2241// cStr::Split
2242inline void cStr::Split(cList<cStr>* List, const char* Delimiters) const {
2243 cAssert(IsValid());
2244 cStr::Split(m_Str, List, Delimiters);
2245}
2246
2247//-----------------------------------------------------------------------------
2248// cStr::CharIs...
2249//-----------------------------------------------------------------------------
2250
2251// cStr::CharIsLower
2252inline bool cStr::CharIsLower(const int c) {
2253 return c >= 'a' && c <= 'z';
2254}
2255
2256// cStr::CharIsUpper
2257inline bool cStr::CharIsUpper(const int c) {
2258 return c >= 'A' && c <= 'Z';
2259}
2260
2261// cStr::CharIsAlpha
2262inline bool cStr::CharIsAlpha(const int c) {
2263 return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
2264}
2265
2266// cStr::CharIsNumeric
2267inline bool cStr::CharIsNumeric(const int c) {
2268 return c >= '0' && c <= '9';
2269}
2270
2271// cStr::CharIsHexadecimal
2272inline bool cStr::CharIsHexadecimal(const int c) {
2273 return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
2274}
2275
2276// cStr::CharIsNewLine
2277inline bool cStr::CharIsNewLine(const int c) {
2278 return c == '\n' || c == '\r' || c == '\v';
2279}
2280
2281// cStr::CharIsTab
2282inline bool cStr::CharIsTab(const int c) {
2283 return c == '\t';
2284}
2285
2286// cStr::CharIsWhitespace
2287inline bool cStr::CharIsWhitespace(const int c) {
2288 return ' ' == c || '\t' == c;
2289}
2290
2291// cStr::CharIsDecimalPoint
2292inline bool cStr::CharIsDecimalPoint(const int c) {
2293 return '.' == c || ',' == c;
2294}
2295
2296// cStr::CharIsSign
2297inline bool cStr::CharIsSign(const int c) {
2298 return '+' == c || '-' == c;
2299}
2300
2301// cStr::CharIsExponent
2302inline bool cStr::CharIsExponent(const int c) {
2303 return 'd' == c || 'D' == c || 'e' == c || 'E' == c;
2304}
2305
2306//-----------------------------------------------------------------------------
2307// cStr::GetHashCode
2308//-----------------------------------------------------------------------------
2309inline int cStr::GetHashCode(const char* Str, const bool NoCase) {
2310 cAssert(Str != nullptr);
2311
2312 int H = 0, i;
2313
2314 for (i = 0; *Str != '\0'; i++) {
2315 H += (NoCase ? ToLower(*Str++) : (*Str++)) * (i + 119);
2316 }
2317 return H;
2318} // cStr::GetHashCode
The array template, refer it as coat::list <...> if you are using the Core API.
Definition cList.h:133
Definition cStr.h:6
static const cStr ToSize(const qword, const bool Pow2=false)
"cStr::ToSize" converts "qword" into short rounded size using Greek prefix
Definition cStr.h:605