Nebula
Loading...
Searching...
No Matches
string.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
27#include "core/types.h"
28#include "core/sysfunc.h"
29#include "util/array.h"
30#include "util/dictionary.h"
31#include "memory/heap.h"
32
34
35namespace Math
36{
37 struct mat4;
38 struct vec2;
39 struct vec3;
40 struct vec4;
41 struct quat;
42 class transform44;
43};
44
45//------------------------------------------------------------------------------
46namespace Util
47{
48class Blob;
49class String
50{
51public:
53 String();
55 String(const String& rhs);
57 String(String&& rhs) noexcept;
59 String(const char* cStr);
61 String(const char* cStr, size_t len);
63 ~String();
64
66 void operator=(const String& rhs);
68 void operator=(String&& rhs) noexcept;
70 void operator=(const char* cStr);
72 void operator +=(const String& rhs);
74 friend bool operator==(const String& a, const String& b);
76 friend bool operator==(const String& a, const char* cStr);
78 friend bool operator==(const char* cStr, const String& a);
80 friend bool operator==(const String&, std::nullptr_t);
82 friend bool operator !=(const String& a, const String& b);
84 friend bool operator <(const String& a, const String& b);
86 friend bool operator >(const String& a, const String& b);
88 friend bool operator <=(const String& a, const String& b);
90 friend bool operator >=(const String& a, const String& b);
92 char operator[](IndexT i) const;
94 char& operator[](IndexT i);
95
97 void Reserve(SizeT newSize);
99 SizeT Length() const;
101 void Clear();
103 bool IsEmpty() const;
105 bool IsValid() const;
107 bool CopyToBuffer(char* buf, SizeT bufSize) const;
108
110 void Append(const String& str);
112 void Append(const char* str);
114 void AppendRange(const char* str, SizeT numChars);
115
117 void ToLower();
119 void ToUpper();
121 void Capitalize();
123 void CamelCaseToWords();
125 SizeT Tokenize(const String& whiteSpace, Array<String>& outTokens) const;
127 Array<String> Tokenize(const String& whiteSpace) const;
129 SizeT Tokenize(const String& whiteSpace, char fence, Array<String>& outTokens) const;
131 Array<String> Tokenize(const String& whiteSpace, char fence) const;
133 String ExtractRange(IndexT fromIndex, SizeT numChars) const;
135 String ExtractToEnd(IndexT fromIndex) const;
137 void Strip(const String& charSet);
139 IndexT FindStringIndex(const String& s, IndexT startIndex = 0) const;
141 IndexT FindCharIndex(char c, IndexT startIndex = 0) const;
143 bool BeginsWithString(const String& s) const;
145 bool EndsWithString(const String& s) const;
147 void TerminateAtIndex(IndexT index);
149 bool ContainsCharFromSet(const String& charSet) const;
151 void TrimLeft(const String& charSet);
153 void TrimRight(const String& charSet);
155 void Trim(const String& charSet);
157 void SubstituteString(const String& str, const String& substStr);
159 void SubstituteChar(char c, char subst);
161 void __cdecl Format(const char* fmtString, ...);
163 void __cdecl FormatArgList(const char* fmtString, va_list argList);
165 static String Sprintf(const char* fmtString, ...);
167 bool CheckValidCharSet(const String& charSet) const;
169 void ReplaceChars(const String& charSet, char replacement);
171 static String Concatenate(const Array<String>& strArray, const String& whiteSpace);
173 static bool MatchPattern(const String& str, const String& pattern);
175 uint32_t HashCode() const;
176
178 void SetCharPtr(const char* s);
180 void Set(const char* ptr, SizeT length);
182 //void Set(const char* ptr, size_t length);
184 void SetByte(byte val);
186 void SetUByte(ubyte val);
188 void SetShort(short val);
190 void SetUShort(ushort val);
192 void SetInt(int val);
194 void SetUInt(uint val);
196 void SetLong(long val);
198 void SetSizeT(size_t val);
200 void SetLongLong(long long val);
202 void SetFloat(float val);
204 void SetDouble(double val);
206 void SetBool(bool val);
207
209 void Fill(SizeT length, unsigned char character);
210
211 #if !__OSX__
213 void SetVec2(const Math::vec2& v);
215 void SetVec3(const Math::vec3& v);
217 void SetVec4(const Math::vec4& v);
219 void SetFloat2(const Math::float2& v);
221 void SetFloat3(const Math::float3& v);
223 void SetFloat4(const Math::float4& v);
225 void SetQuaternion(const Math::quat& v);
227 void SetMat4(const Math::mat4& v);
229 void SetTransform44(const Math::transform44& v);
230 #endif
232 template<typename T> void Set(const T& t);
233
235 void AppendChar(char val);
237 void AppendInt(int val);
239 void AppendByte(byte val);
241 void AppendUByte(ubyte val);
243 void AppendFloat(float val);
245 void AppendBool(bool val);
247 void AppendVec2(const Math::vec2& v);
249 void AppendVec3(const Math::vec3& v);
251 void AppendVec4(const Math::vec4& v);
253 void AppendMat4(const Math::mat4& v);
255 template<typename T> void Append(const T& t);
256
258 const char* AsCharPtr() const;
260 const char* Get() const;
262 int AsInt() const;
264 long long AsLongLong() const;
266 float AsFloat() const;
268 bool AsBool() const;
270 Math::vec2 AsVec2() const;
272 Math::vec3 AsVec3() const;
274 Math::vec4 AsVec4() const;
276 Math::float2 AsFloat2() const;
278 Math::float3 AsFloat3() const;
280 Math::float4 AsFloat4() const;
282 Math::mat4 AsMat4() const;
286 Util::Blob AsBlob() const;
288 Util::String AsBase64() const;
290 template<typename T> T As() const;
291
293 bool IsValidInt() const;
295 bool IsValidFloat() const;
297 bool IsValidBool() const;
299 bool IsValidVec2() const;
301 bool IsValidVec4() const;
303 bool IsValidMat4() const;
305 bool IsValidTransform44() const;
307 template<typename T> bool IsValid() const;
308
310 static String FromByte(byte i);
312 static String FromUByte(ubyte i);
314 static String FromShort(short i);
316 static String FromUShort(ushort i);
318 static String FromInt(int i);
320 static String FromUInt(uint i);
322 static String FromLong(long i);
324 static String FromSize(size_t i);
326 static String FromLongLong(long long i);
328 static String FromFloat(float f);
330 static String FromDouble(double f);
332 static String FromBool(bool b);
334 static String FromVec2(const Math::vec2& v);
336 static String FromVec3(const Math::vec3& v);
338 static String FromVec4(const Math::vec4& v);
340 static String FromFloat2(const Math::float2& v);
342 static String FromFloat3(const Math::float3& v);
344 static String FromFloat4(const Math::float4& v);
346 static String FromQuat(const Math::quat& q);
348 static String FromMat4(const Math::mat4& m);
352 static String FromBlob(const Util::Blob & b);
354 static String FromBase64(const String&);
356 template<typename T> static String From(const T& t);
358 static constexpr uint Hash(const char* c, std::size_t s);
359
361 template<typename INTEGER>
362 static String Hex(INTEGER i);
363
365 String GetFileExtension() const;
367 bool CheckFileExtension(const String& ext) const;
369 void ConvertBackslashes();
371 void StripFileExtension();
373 void ChangeFileExtension(const Util::String& newExt);
375 void StripAssignPrefix();
377 void ChangeAssignPrefix(const Util::String& newPref);
379 String ExtractFileName() const;
383 String ExtractDirName() const;
387 void ReplaceIllegalFilenameChars(char replacement);
388
390 inline const char* c_str() const { return this->AsCharPtr(); }
392 inline size_t length() const { return this->Length(); }
394 inline bool empty() const { return this->IsEmpty(); }
396 inline const char* data() const { return this->AsCharPtr(); }
397
399 static bool IsDigit(char c);
401 static bool IsAlpha(char c);
403 static bool IsAlNum(char c);
405 static bool IsLower(char c);
407 static bool IsUpper(char c);
408
410 static int StrCmp(const char* str0, const char* str1);
412 static int StrLen(const char* str);
414 static const char* StrChr(const char* str, int c);
415
418
419private:
421 void Delete();
423 char* GetLastSlash() const;
425 void Alloc(SizeT size);
427 void Realloc(SizeT newSize);
428
429 enum
430 {
432 };
437};
438
439//------------------------------------------------------------------------------
442inline
444 heapBuffer(nullptr),
445 strLen(0),
447{
448 this->localBuffer[0] = 0;
449}
450
451//------------------------------------------------------------------------------
454inline void
456{
457 if (this->heapBuffer)
458 {
460 this->heapBuffer = nullptr;
461 }
462 this->localBuffer[0] = 0;
463 this->strLen = 0;
464 this->heapBufferSize = 0;
465}
466
467//------------------------------------------------------------------------------
470inline
472{
473 this->Delete();
474}
475
476//------------------------------------------------------------------------------
479inline
480String::String(const char* str) :
481 heapBuffer(0),
482 strLen(0),
484{
485 this->localBuffer[0] = 0;
486 this->SetCharPtr(str);
487}
488
489//------------------------------------------------------------------------------
492inline
493String::String(const char* str, size_t len) :
494 heapBuffer(0),
495 strLen(0),
497{
498 this->localBuffer[0] = 0;
499 this->Set(str, (SizeT)len);
500}
501
502
503//------------------------------------------------------------------------------
506inline
508 heapBuffer(0),
509 strLen(0),
511{
512 this->localBuffer[0] = 0;
513 this->SetCharPtr(rhs.AsCharPtr());
514}
515
516//------------------------------------------------------------------------------
519inline
520String::String(String&& rhs) noexcept:
521 heapBuffer(rhs.heapBuffer),
522 strLen(rhs.strLen),
523 heapBufferSize(rhs.heapBufferSize)
524{
525 if (rhs.heapBuffer)
526 {
527 rhs.heapBuffer = nullptr;
528 this->localBuffer[0] = 0;
529 }
530 else
531 {
532 if (this->strLen > 0)
533 {
534 Memory::Copy(rhs.localBuffer, this->localBuffer, this->strLen);
535 }
536 this->localBuffer[this->strLen] = 0;
537 }
538}
539
540//------------------------------------------------------------------------------
543inline const char*
545{
546 if (this->heapBuffer)
547 {
548 return this->heapBuffer;
549 }
550 else
551 {
552 return this->localBuffer;
553 }
554}
555
556//------------------------------------------------------------------------------
559inline const char*
561{
562 return this->AsCharPtr();
563}
564
565//------------------------------------------------------------------------------
568inline void
570{
571 if (&rhs != this)
572 {
573 this->SetCharPtr(rhs.AsCharPtr());
574 }
575}
576
577//------------------------------------------------------------------------------
580inline void
582{
583 if (&rhs != this)
584 {
585 this->Delete();
586 this->strLen = rhs.strLen;
587 rhs.strLen = 0;
588 if (rhs.heapBuffer)
589 {
590 this->heapBuffer = rhs.heapBuffer;
591 this->heapBufferSize = rhs.heapBufferSize;
592 rhs.heapBuffer = nullptr;
593 rhs.heapBufferSize = 0;
594 }
595 else
596 {
597 if (this->strLen > 0)
598 {
599 Memory::Copy(rhs.localBuffer, this->localBuffer, this->strLen);
600 }
601 this->localBuffer[this->strLen] = 0;
602 }
603 }
604}
605
606//------------------------------------------------------------------------------
609inline void
610String::operator=(const char* cStr)
611{
612 this->SetCharPtr(cStr);
613}
614
615//------------------------------------------------------------------------------
618inline void
620{
621 this->AppendRange(str.AsCharPtr(), str.strLen);
622}
623
624//------------------------------------------------------------------------------
627inline void
629{
630 this->Append(rhs);
631}
632
633//------------------------------------------------------------------------------
636inline char
638{
639 n_assert(i <= this->strLen);
640 return this->AsCharPtr()[i];
641}
642
643//------------------------------------------------------------------------------
648inline char&
650{
651 n_assert(i <= this->strLen);
652 return (char&)(this->AsCharPtr())[i];
653}
654
655//------------------------------------------------------------------------------
658inline SizeT
660{
661 return this->strLen;
662}
663
664//------------------------------------------------------------------------------
667inline void
669{
670 this->Delete();
671}
672
673//------------------------------------------------------------------------------
676inline bool
678{
679 return (0 == this->strLen);
680}
681
682//------------------------------------------------------------------------------
685inline bool
687{
688 return (0 != this->strLen);
689}
690
691//------------------------------------------------------------------------------
696inline uint32_t
698{
699 const char* ptr = this->AsCharPtr();
700 return Hash(ptr, this->strLen);
701}
702
703//------------------------------------------------------------------------------
706static inline String
707operator+(const String& s0, const String& s1)
708{
709 String newString = s0;
710 newString.Append(s1);
711 return newString;
712}
713
714//------------------------------------------------------------------------------
718inline void
719String::SubstituteChar(char c, char subst)
720{
721 char* ptr = const_cast<char*>(this->AsCharPtr());
722 IndexT i;
723 for (i = 0; i <= this->strLen; i++)
724 {
725 if (ptr[i] == c)
726 {
727 ptr[i] = subst;
728 }
729 }
730}
731
732//------------------------------------------------------------------------------
736inline void
738{
739 this->SubstituteChar('\\', '/');
740}
741
742//------------------------------------------------------------------------------
745inline bool
747{
748 return (this->GetFileExtension() == ext);
749}
750
751//------------------------------------------------------------------------------
756inline String
758{
759 String pathString;
760 const char* lastSlash = this->GetLastSlash();
761 if (lastSlash)
762 {
763 pathString = &(lastSlash[1]);
764 }
765 else
766 {
767 pathString = *this;
768 }
769 return pathString;
770}
771
772//------------------------------------------------------------------------------
778inline String
780{
781 String pathString(*this);
782 char* lastSlash = pathString.GetLastSlash();
783 if (lastSlash)
784 {
785 lastSlash[1] = 0;
786 }
787 else
788 {
789 pathString = "";
790 }
791 return pathString;
792}
793
794//------------------------------------------------------------------------------
799inline bool
801{
802 IndexT i;
803 for (i = 0; i < this->strLen; i++)
804 {
805 if (InvalidIndex == charSet.FindCharIndex((*this)[i], 0))
806 {
807 return false;
808 }
809 }
810 return true;
811}
812
813//------------------------------------------------------------------------------
816inline bool
818{
819 return this->CheckValidCharSet(" \t-+01234567890");
820}
821
822//------------------------------------------------------------------------------
826inline bool
828{
829 return this->CheckValidCharSet(" \t-+.e1234567890");
830}
831
832//------------------------------------------------------------------------------
835inline void
837{
838 this->ReplaceChars("\\/:*?\"<>|", replacement);
839}
840
841//------------------------------------------------------------------------------
844inline String
846{
847 String str;
848 str.SetByte(i);
849 return str;
850}
851
852//------------------------------------------------------------------------------
855inline String
857{
858 String str;
859 str.SetUByte(i);
860 return str;
861}
862
863//------------------------------------------------------------------------------
866inline String
868{
869 String str;
870 str.SetShort(i);
871 return str;
872}
873
874//------------------------------------------------------------------------------
877inline String
879{
880 String str;
881 str.SetUShort(i);
882 return str;
883}
884
885//------------------------------------------------------------------------------
888inline String
890{
891 String str;
892 str.SetInt(i);
893 return str;
894}
895
896//------------------------------------------------------------------------------
899inline String
901{
902 String str;
903 str.SetUInt(i);
904 return str;
905}
906
907//------------------------------------------------------------------------------
910inline String
912{
913 String str;
914 str.SetLong(i);
915 return str;
916}
917
918//------------------------------------------------------------------------------
921inline String
923{
924 String str;
925 str.SetSizeT(i);
926 return str;
927}
928
929//------------------------------------------------------------------------------
932inline Util::String
934{
935 String str;
936 str.SetLongLong(i);
937 return str;
938}
939
940//------------------------------------------------------------------------------
943inline String
945{
946 String str;
947 str.SetFloat(f);
948 return str;
949}
950
951//------------------------------------------------------------------------------
954inline String
956{
957 String str;
958 str.SetDouble(i);
959 return str;
960}
961
962//------------------------------------------------------------------------------
965inline String
967{
968 String str;
969 str.SetBool(b);
970 return str;
971}
972
973#if !__OSX__
974//------------------------------------------------------------------------------
977inline String
979{
980 String str;
981 str.SetVec2(v);
982 return str;
983}
984
985//------------------------------------------------------------------------------
988inline String
990{
991 String str;
992 str.SetVec3(v);
993 return str;
994}
995
996//------------------------------------------------------------------------------
999inline String
1001{
1002 String str;
1003 str.SetVec4(v);
1004 return str;
1005}
1006
1007//------------------------------------------------------------------------------
1010inline String
1012{
1013 String str;
1014 str.SetFloat2(v);
1015 return str;
1016}
1017
1018//------------------------------------------------------------------------------
1021inline String
1023{
1024 String str;
1025 str.SetFloat3(v);
1026 return str;
1027}
1028
1029//------------------------------------------------------------------------------
1032inline String
1034{
1035 String str;
1036 str.SetFloat4(v);
1037 return str;
1038}
1039
1040//------------------------------------------------------------------------------
1043inline String
1045{
1046 String str;
1047 str.SetQuaternion(q);
1048 return str;
1049}
1050
1051//------------------------------------------------------------------------------
1054inline String
1056{
1057 String str;
1058 str.SetMat4(m);
1059 return str;
1060}
1061
1062//------------------------------------------------------------------------------
1065inline String
1067{
1068 String str;
1069 str.SetTransform44(t);
1070 return str;
1071}
1072#endif
1073
1074//------------------------------------------------------------------------------
1077template<typename INTEGER>
1078inline String
1079String::Hex(INTEGER i)
1080{
1081 constexpr SizeT hexLength = sizeof(INTEGER) << 1;
1082 static Util::String digits = "0123456789ABCDEF";
1083
1084 String str("0x");
1085 str.Reserve(hexLength + 2);
1086
1087 for (SizeT n = 0, j = (hexLength - 1) * 4; n < hexLength; ++n, j -= 4)
1088 {
1089 str.AppendChar(digits[(i >> j) & 0x0f]);
1090 }
1091
1092 return str;
1093}
1094
1095//------------------------------------------------------------------------------
1098inline void
1100{
1101 this->AppendRange(&val, 1);
1102}
1103
1104//------------------------------------------------------------------------------
1107inline void
1109{
1110 this->Append(FromInt(val));
1111}
1112
1113//------------------------------------------------------------------------------
1116inline void
1118{
1119 this->Append(FromByte(val));
1120}
1121
1122//------------------------------------------------------------------------------
1125inline void
1127{
1128 this->Append(FromUByte(val));
1129}
1130
1131//------------------------------------------------------------------------------
1134inline void
1136{
1137 this->Append(FromFloat(val));
1138}
1139
1140//------------------------------------------------------------------------------
1143inline void
1145{
1146 this->Append(FromBool(val));
1147}
1148
1149#if !__OSX__
1150//------------------------------------------------------------------------------
1153inline void
1155{
1156 this->Append(FromVec2(val));
1157}
1158
1159//------------------------------------------------------------------------------
1162inline void
1164{
1165 this->Append(FromVec3(val));
1166}
1167
1168//------------------------------------------------------------------------------
1171inline void
1173{
1174 this->Append(FromVec4(val));
1175}
1176
1177//------------------------------------------------------------------------------
1180inline void
1182{
1183 this->Append(FromMat4(val));
1184}
1185#endif
1186
1187
1188//------------------------------------------------------------------------------
1191constexpr uint
1192String::Hash(const char* c, std::size_t s)
1193{
1194 uint hash = 0;
1195 std::size_t i;
1196 for (i = 0; i < s; i++)
1197 {
1198 hash += c[i];
1199 hash += hash << 10;
1200 hash ^= hash >> 6;
1201 }
1202 hash += hash << 3;
1203 hash ^= hash >> 11;
1204 hash += hash << 15;
1205 return hash;
1206}
1207
1209
1210} // namespace Util
1211
1212
1213//------------------------------------------------------------------------------
1217Util::String operator ""_str(const char* c, std::size_t s);
1218
1219//------------------------------------------------------------------------------
1223constexpr uint
1224operator ""_hash(const char* c, std::size_t s)
1225{
1226 return Util::String::Hash(c, s);
1227}
1228
1229//------------------------------------------------------------------------------
1230
A 4x4 matrix which is described by translation, rotation and scale.
Definition transform44.h:20
The Util::Blob class encapsulates a chunk of raw memory into a C++ object which can be copied,...
Definition blob.h:22
A collection of key/value pairs with quick value retrieval by key at roughly O(log n).
Definition dictionary.h:34
#define n_assert(exp)
Definition debug.h:50
Different curves.
Definition angularpfeedbackloop.h:17
half operator+(half one, half two)
Definition half.h:105
void Copy(const void *from, void *to, size_t numBytes)
Copy a chunk of memory (note the argument order is different from memcpy()!
Definition osxmemory.cc:213
void Free(HeapType heapType, void *ptr)
Free a block of memory.
Definition osxmemory.cc:136
@ StringDataHeap
Definition osxmemoryconfig.h:31
A pinned array is an array which manages its own virtual memory.
Definition String.cs:6
auto Format
Definition string.h:1208
Definition scalar.h:58
Definition scalar.h:67
Definition scalar.h:76
A 4x4 single point precision float matrix.
Definition mat4.h:49
A quaternion is usually used to represent an orientation in 3D space.
Definition quat.h:30
A 2-component float vector class.
Definition vec2.h:21
A 3D vector.
Definition vec3.h:37
A 4D vector.
Definition vec4.h:24
Nebula's universal string class.
Definition String.cs:8
void SetShort(short val)
set as short value
Definition string.cc:1377
static String FromBase64(const String &)
create from base64
Definition string.cc:1272
static String FromFloat(float f)
construct a string from a float
Definition string.h:944
void Clear()
clear the string
Definition string.h:668
void AppendRange(const char *str, SizeT numChars)
append a range of characters
Definition string.cc:151
static String FromShort(short i)
construct a string from a short
Definition string.h:867
void TrimRight(const String &charSet)
delete characters from charset at right side of string
Definition string.cc:440
Util::Blob AsBlob() const
return contents as blob
Definition string.cc:1221
static String FromVec3(const Math::vec3 &v)
construct a string from vec3
Definition string.h:989
~String()
destructor
Definition string.h:471
void SetFloat3(const Math::float3 &v)
set as vec3 value
Definition string.cc:1524
static const char * StrChr(const char *str, int c)
find character in string
Definition string.cc:1149
static String FromVec4(const Math::vec4 &v)
construct a string from vec4
Definition string.h:1000
void SetSizeT(size_t val)
set as long value
Definition string.cc:1422
static String FromVec2(const Math::vec2 &v)
construct a string from vec2
Definition string.h:978
static String FromUInt(uint i)
construct a string from a uint
Definition string.h:900
void ChangeFileExtension(const Util::String &newExt)
change file extension
Definition string.cc:1176
void AppendChar(char val)
append character
Definition string.h:1099
static String Concatenate(const Array< String > &strArray, const String &whiteSpace)
concatenate array of strings into new string
Definition string.cc:732
void Trim(const String &charSet)
trim characters from charset at both sides of string
Definition string.cc:483
static Dictionary< String, String > ParseKeyValuePairs(const String &str)
parse key/value pair string ("key0=value0 key1=value1")
Definition string.cc:1159
friend bool operator!=(const String &a, const String &b)
inequality operator
Definition string.cc:858
void SetBool(bool val)
set as bool value
Definition string.cc:1458
void Alloc(SizeT size)
allocate the string buffer (discards old content)
Definition string.cc:1291
static bool IsAlNum(char c)
test if provided character is an alpha-numeric character (A..Z,a..z,0..9)
Definition string.cc:1102
void SetUShort(ushort val)
set as ushort value
Definition string.cc:1386
void SetLongLong(long long val)
set as long long value
Definition string.cc:1431
const char * Get() const
*** OBSOLETE *** only Nebula2 compatibility
Definition string.h:560
static String FromLongLong(long long i)
construct a string from a long long
Definition string.h:933
bool AsBool() const
return contents as bool
Definition string.cc:1062
void ReplaceIllegalFilenameChars(char replacement)
replace illegal filename characters
Definition string.h:836
void SubstituteString(const String &str, const String &substStr)
substitute every occurance of a string with another string
Definition string.cc:494
void Set(const T &t)
generic setter
void Set(const char *ptr, SizeT length)
set as char ptr, with explicit length
Definition string.cc:112
friend bool operator<=(const String &a, const String &b)
less-or-equal operator
Definition string.cc:885
static String FromSize(size_t i)
construct a string from a size_t
Definition string.h:922
void Realloc(SizeT newSize)
(re-)allocate the string buffer (copies old content)
Definition string.cc:1314
void AppendVec4(const Math::vec4 &v)
append vec4 value
Definition string.h:1172
static int StrCmp(const char *str0, const char *str1)
lowlevel string compare wrapper function
Definition string.cc:1129
void Strip(const String &charSet)
terminate string at first occurence of character in set
Definition string.cc:320
char * GetLastSlash() const
get pointer to last directory separator
Definition string.cc:992
static String FromBlob(const Util::Blob &b)
create from blob
Definition string.cc:1196
friend bool operator==(const String &a, const String &b)
equality operator
Definition string.cc:820
void SetInt(int val)
set as int value
Definition string.cc:1395
void CamelCaseToWords()
insert spaces before each capital letter in the string.
Definition string.cc:941
Math::vec2 AsVec2() const
return contents as vec2
Definition string.cc:1633
static bool IsUpper(char c)
test if provided character is an upper-case character
Definition string.cc:1120
void Reserve(SizeT newSize)
reserve internal buffer size to prevent heap allocs
Definition string.cc:1347
long long AsLongLong() const
return contents as long long
Definition string.cc:1041
String GetFileExtension() const
get filename extension without dot
Definition string.cc:975
String ExtractRange(IndexT fromIndex, SizeT numChars) const
extract substring
Definition string.cc:294
void Delete()
delete contents
Definition string.h:455
void SetVec3(const Math::vec3 &v)
set as vec3 value
Definition string.cc:1497
void StripAssignPrefix()
remove assign prefix (for example tex:)
Definition string.cc:806
void SetLong(long val)
set as long value
Definition string.cc:1413
int heapBufferSize
Definition String.cs:12
void Capitalize()
convert first char of string to upper case
Definition string.cc:931
Math::float4 AsFloat4() const
return contents as vec4
Definition string.cc:1701
const char * AsCharPtr() const
return contents as character pointer
Definition string.h:544
static bool MatchPattern(const String &str, const String &pattern)
pattern matching
Definition string.cc:597
Math::mat4 AsMat4() const
return contents as mat4
Definition string.cc:695
static bool IsAlpha(char c)
test if provided character is an alphabet character (A..Z, a..z)
Definition string.cc:1093
static bool IsLower(char c)
test if provided character is a lower case character
Definition string.cc:1111
int AsInt() const
return contents as integer
Definition string.cc:1029
bool IsValidTransform44() const
return true if content is a valid transform44
Definition string.cc:1619
void SubstituteChar(char c, char subst)
substitute every occurance of a character with another character
Definition string.h:719
void TrimLeft(const String &charSet)
delete characters from charset at left side of string
Definition string.cc:398
void SetVec4(const Math::vec4 &v)
set as vec4 value
Definition string.cc:1506
static String From(const T &t)
convert from "anything"
char localBuffer[LocalStringSize]
Definition string.h:434
void Append(const T &t)
generic append
void AppendBool(bool val)
append bool value
Definition string.h:1144
static String FromQuat(const Math::quat &q)
construct a string from quat
Definition string.h:1044
int strLen
Definition String.cs:11
static String FromLong(long i)
construct a string from a long
Definition string.h:911
void ReplaceChars(const String &charSet, char replacement)
replace any char set character within a string with the replacement character
Definition string.cc:672
friend bool operator<(const String &a, const String &b)
less-then operator
Definition string.cc:867
bool IsValidVec2() const
return true if the content is a valid vec2
Definition string.cc:1583
void AppendUByte(ubyte val)
append unsigned byte value
Definition string.h:1126
void operator+=(const String &rhs)
+= operator
Definition string.h:628
void ConvertBackslashes()
convert backslashes to slashes
Definition string.h:737
void SetUByte(ubyte val)
set as ubyte value
Definition string.cc:1368
static String FromInt(int i)
construct a string from an int
Definition string.h:889
bool ContainsCharFromSet(const String &charSet) const
returns true if string contains any character from set
Definition string.cc:963
static String FromUShort(ushort i)
construct a string from a ushort
Definition string.h:878
bool IsValidVec4() const
return true if the content is a valid vec4
Definition string.cc:1595
IndexT FindCharIndex(char c, IndexT startIndex=0) const
return index of character in string, or InvalidIndex if not found
Definition string.cc:361
void SetVec2(const Math::vec2 &v)
set as vec2 value
Definition string.cc:1488
bool IsValidBool() const
return true if the content is a valid bool
Definition string.cc:1005
Math::float2 AsFloat2() const
return contents as vec2
Definition string.cc:1675
bool IsValidInt() const
return true if the content is a valid integer
Definition string.h:817
String ExtractDirName() const
extract the part before the last directory separator
Definition string.cc:570
uint32_t HashCode() const
return a 32-bit hash code for the string
Definition string.h:697
IndexT FindStringIndex(const String &s, IndexT startIndex=0) const
return start index of substring, or InvalidIndex if not found
Definition string.cc:336
void SetFloat4(const Math::float4 &v)
set as vec4 value
Definition string.cc:1533
String ExtractFileName() const
extract the part after the last directory separator
Definition string.h:757
static String FromFloat2(const Math::float2 &v)
construct a string from float2
Definition string.h:1011
bool IsValid() const
return true if string object is not empty
Definition string.h:686
static String FromDouble(double f)
construct a string from a double
Definition string.h:955
void SetFloat(float val)
set as float value
Definition string.cc:1440
static String FromByte(byte i)
construct a string from a byte
Definition string.h:845
static int StrLen(const char *str)
lowlevel string length function
Definition string.cc:1139
size_t length() const
Definition string.h:392
bool CopyToBuffer(char *buf, SizeT bufSize) const
copy to char buffer (return false if buffer is too small)
Definition string.cc:38
void operator=(const String &rhs)
assignment operator
Definition string.h:569
void ToLower()
convert string to lower case
Definition string.cc:903
void SetDouble(double val)
set as double value
Definition string.cc:1449
void Append(const String &str)
append string
Definition string.h:619
void SetUInt(uint val)
set as uint value
Definition string.cc:1404
static String FromFloat4(const Math::float4 &v)
construct a string from float2
Definition string.h:1033
@ LocalStringSize
Definition string.h:431
bool IsValidMat4() const
return true if content is a valid mat4
Definition string.cc:1607
static String FromBool(bool b)
construct a string from a bool
Definition string.h:966
char operator[](IndexT i) const
read-only index operator
Definition string.h:637
bool CheckFileExtension(const String &ext) const
check file extension
Definition string.h:746
void SetQuaternion(const Math::quat &v)
set as quaternion
Definition string.cc:1542
void SetByte(byte val)
set as byte value
Definition string.cc:1359
bool IsValid() const
generic valid checker
friend bool operator>(const String &a, const String &b)
greater-then operator
Definition string.cc:876
void SetFloat2(const Math::float2 &v)
set as vec2 value
Definition string.cc:1515
float AsFloat() const
return contents as float
Definition string.cc:1053
static String FromTransform44(const Math::transform44 &m)
construct a string from transform44
Definition string.h:1066
bool IsValidFloat() const
return true if the content is a valid float
Definition string.h:827
SizeT Length() const
return length of string
Definition string.h:659
const char * c_str() const
helpers to interface with libraries that expect std::string like apis
Definition string.h:390
void TerminateAtIndex(IndexT index)
terminate string at given index
Definition string.cc:778
T As() const
convert to "anything"
void AppendByte(byte val)
append byte value
Definition string.h:1117
static bool IsDigit(char c)
test if provided character is a digit (0..9)
Definition string.cc:1084
void __cdecl FormatArgList(const char *fmtString, va_list argList)
format string printf-style with varargs list
Definition string.cc:78
Math::vec3 AsVec3() const
return contents as vec3
Definition string.cc:1646
Math::transform44 AsTransform44() const
return contents as transform44
Definition string.cc:712
String()
constructor
Definition string.h:443
void ChangeAssignPrefix(const Util::String &newPref)
change assign prefix
Definition string.cc:1186
void Fill(SizeT length, unsigned char character)
set string length and fill all characters with arg
Definition string.cc:1474
bool CheckValidCharSet(const String &charSet) const
return true if string only contains characters from charSet argument
Definition string.h:800
String ExtractLastDirName() const
extract the last directory of the path
Definition string.cc:530
Util::String AsBase64() const
return contents as base64 string
Definition string.cc:1255
const char * data() const
Definition string.h:396
void SetMat4(const Math::mat4 &v)
set as mat4 value
Definition string.cc:1551
bool empty() const
Definition string.h:394
bool BeginsWithString(const String &s) const
returns true if string begins with string
Definition string.cc:379
static String Sprintf(const char *fmtString,...)
static constructor for string using printf
Definition string.cc:96
Math::float3 AsFloat3() const
return contents as vec3
Definition string.cc:1688
static String FromFloat3(const Math::float3 &v)
construct a string from float2
Definition string.h:1022
char * heapBuffer
Definition string.h:433
void AppendMat4(const Math::mat4 &v)
append mat4 value
Definition string.h:1181
static constexpr uint Hash(const char *c, std::size_t s)
Hash a string.
Definition string.h:1192
static String FromUByte(ubyte i)
construct a string from a ubyte
Definition string.h:856
void SetCharPtr(const char *s)
set content to char ptr
Definition string.cc:753
static String Hex(INTEGER i)
construct a hex string from an int
Definition string.h:1079
String ExtractToEnd(IndexT fromIndex) const
extract substring to end of this string
Definition string.cc:309
void AppendVec2(const Math::vec2 &v)
append vec2 value
Definition string.h:1154
bool EndsWithString(const String &s) const
returns true if string ends with string
Definition string.cc:388
bool IsEmpty() const
return true if string object is empty
Definition string.h:677
friend bool operator>=(const String &a, const String &b)
greater-then operator
Definition string.cc:894
void AppendFloat(float val)
append float value
Definition string.h:1135
String ExtractToLastSlash() const
extract path until last slash
Definition string.h:779
void StripFileExtension()
remove file extension
Definition string.cc:791
Math::vec4 AsVec4() const
return contents as vec4
Definition string.cc:1662
SizeT Tokenize(const String &whiteSpace, Array< String > &outTokens) const
tokenize string into a provided String array (faster if tokens array can be reused)
Definition string.cc:193
void AppendVec3(const Math::vec3 &v)
append vec3 value
Definition string.h:1163
static String FromMat4(const Math::mat4 &m)
construct a string from mat4
Definition string.h:1055
void AppendInt(int val)
append int value
Definition string.h:1108
void ToUpper()
convert string to upper case
Definition string.cc:917
void SetTransform44(const Math::transform44 &v)
set as transform44 value
Definition string.cc:1567
static const int InvalidIndex
Definition types.h:47
unsigned char ubyte
Definition types.h:36
int SizeT
Definition types.h:42
unsigned int uint
Definition types.h:33
unsigned short ushort
Definition types.h:34
int IndexT
Definition types.h:41