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 IndexT FindCharIndexReverse(char c, IndexT startIndex = 0) const;
145 bool BeginsWithString(const String& s) const;
147 bool EndsWithString(const String& s) const;
149 void TerminateAtIndex(IndexT index);
151 bool ContainsCharFromSet(const String& charSet) const;
153 void TrimLeft(const String& charSet);
155 void TrimRight(const String& charSet);
157 void Trim(const String& charSet);
159 void SubstituteString(const String& str, const String& substStr);
161 void SubstituteChar(char c, char subst);
163 void __cdecl Format(const char* fmtString, ...);
165 void __cdecl FormatArgList(const char* fmtString, va_list argList);
167 static String Sprintf(const char* fmtString, ...);
169 bool CheckValidCharSet(const String& charSet) const;
171 void ReplaceChars(const String& charSet, char replacement);
173 static String Concatenate(const Array<String>& strArray, const String& whiteSpace);
175 static bool MatchPattern(const String& str, const String& pattern);
177 uint32_t HashCode() const;
178
180 void SetCharPtr(const char* s);
182 void Set(const char* ptr, SizeT length);
184 //void Set(const char* ptr, size_t length);
186 void SetByte(byte val);
188 void SetUByte(ubyte val);
190 void SetShort(short val);
192 void SetUShort(ushort val);
194 void SetInt(int val);
196 void SetUInt(uint val);
198 void SetInt64(int64_t val);
200 void SetUInt64(uint64_t val);
202 void SetLong(long val);
204 void SetSizeT(size_t val);
206 void SetLongLong(long long val);
208 void SetFloat(float val);
210 void SetDouble(double val);
212 void SetBool(bool val);
213
215 void Fill(SizeT length, unsigned char character);
216
217 #if !__OSX__
219 void SetVec2(const Math::vec2& v);
221 void SetVec3(const Math::vec3& v);
223 void SetVec4(const Math::vec4& v);
225 void SetFloat2(const Math::float2& v);
227 void SetFloat3(const Math::float3& v);
229 void SetFloat4(const Math::float4& v);
231 void SetQuaternion(const Math::quat& v);
233 void SetMat4(const Math::mat4& v);
235 void SetTransform44(const Math::transform44& v);
236 #endif
238 template<typename T> void Set(const T& t);
239
241 void AppendChar(char val);
243 void AppendInt(int val);
245 void AppendByte(byte val);
247 void AppendUByte(ubyte val);
249 void AppendFloat(float val);
251 void AppendBool(bool val);
253 void AppendVec2(const Math::vec2& v);
255 void AppendVec3(const Math::vec3& v);
257 void AppendVec4(const Math::vec4& v);
259 void AppendMat4(const Math::mat4& v);
261 template<typename T> void Append(const T& t);
262
264 const char* AsCharPtr() const;
266 const char* Get() const;
268 int AsInt() const;
270 int64_t AsInt64() const;
272 uint32_t AsUInt() const;
274 uint64_t AsUInt64() const;
276 float AsFloat() const;
278 bool AsBool() const;
280 Math::vec2 AsVec2() const;
282 Math::vec3 AsVec3() const;
284 Math::vec4 AsVec4() const;
286 Math::float2 AsFloat2() const;
288 Math::float3 AsFloat3() const;
290 Math::float4 AsFloat4() const;
292 Math::mat4 AsMat4() const;
296 Util::Blob AsBlob() const;
298 Util::String AsBase64() const;
300 template<typename T> T As() const;
301
303 bool IsValidInt() const;
305 bool IsValidFloat() const;
307 bool IsValidBool() const;
309 bool IsValidVec2() const;
311 bool IsValidVec4() const;
313 bool IsValidMat4() const;
315 bool IsValidTransform44() const;
317 template<typename T> bool IsValid() const;
318
320 static String FromByte(byte i);
322 static String FromUByte(ubyte i);
324 static String FromShort(short i);
326 static String FromUShort(ushort i);
328 static String FromInt(int i);
330 static String FromUInt(uint i);
332 static String FromInt64(int64_t i);
334 static String FromUInt64(uint64_t i);
336 static String FromLong(long i);
338 static String FromSize(size_t i);
340 static String FromLongLong(long long i);
342 static String FromFloat(float f);
344 static String FromDouble(double f);
346 static String FromBool(bool b);
348 static String FromVec2(const Math::vec2& v);
350 static String FromVec3(const Math::vec3& v);
352 static String FromVec4(const Math::vec4& v);
354 static String FromFloat2(const Math::float2& v);
356 static String FromFloat3(const Math::float3& v);
358 static String FromFloat4(const Math::float4& v);
360 static String FromQuat(const Math::quat& q);
362 static String FromMat4(const Math::mat4& m);
366 static String FromBlob(const Util::Blob & b);
368 static String FromBase64(const String&);
370 template<typename T> static String From(const T& t);
372 static constexpr uint Hash(const char* c, std::size_t s);
373
375 template<typename INTEGER>
376 static String Hex(INTEGER i);
377
379 String GetFileExtension() const;
381 bool CheckFileExtension(const String& ext) const;
383 void ConvertBackslashes();
385 void StripFileExtension();
387 void ChangeFileExtension(const Util::String& newExt);
389 void StripAssignPrefix();
391 void ChangeAssignPrefix(const Util::String& newPref);
393 void ChangeAssignMapping(const Util::String& newMapping, const Util::String& oldMapping);
395 String ExtractFileName() const;
399 String ExtractDirName() const;
403 String StripSubstring(const String& substring) const;
405 void ReplaceIllegalFilenameChars(char replacement);
407 String& AppendPath(const String& path);
409 static String AppendPath(const String& base, const String& path);
410
412 inline const char* c_str() const { return this->AsCharPtr(); }
414 inline size_t length() const { return this->Length(); }
416 inline bool empty() const { return this->IsEmpty(); }
418 inline const char* data() const { return this->AsCharPtr(); }
419
421 static bool IsDigit(char c);
423 static bool IsAlpha(char c);
425 static bool IsAlNum(char c);
427 static bool IsLower(char c);
429 static bool IsUpper(char c);
430
432 static char ToLower(char c);
434 static char ToUpper(char c);
435
437 static int StrCmp(const char* str0, const char* str1);
439 static int StrICmp(const char* str0, const char* str1);
441 static int StrLen(const char* str);
443 static const char* StrChr(const char* str, int c);
444
447
448private:
450 void Delete();
452 char* GetLastSlash() const;
454 void Alloc(SizeT size);
456 void Realloc(SizeT newSize);
457
458 enum
459 {
461 };
466};
467
468//------------------------------------------------------------------------------
471inline
473 heapBuffer(nullptr),
474 strLen(0),
476{
477 this->localBuffer[0] = 0;
478}
479
480//------------------------------------------------------------------------------
483inline void
485{
486 if (this->heapBuffer)
487 {
489 this->heapBuffer = nullptr;
490 }
491 this->localBuffer[0] = 0;
492 this->strLen = 0;
493 this->heapBufferSize = 0;
494}
495
496//------------------------------------------------------------------------------
499inline
501{
502 this->Delete();
503}
504
505//------------------------------------------------------------------------------
508inline
509String::String(const char* str) :
510 heapBuffer(0),
511 strLen(0),
513{
514 this->localBuffer[0] = 0;
515 this->SetCharPtr(str);
516}
517
518//------------------------------------------------------------------------------
521inline
522String::String(const char* str, size_t len) :
523 heapBuffer(0),
524 strLen(0),
526{
527 this->localBuffer[0] = 0;
528 this->Set(str, (SizeT)len);
529}
530
531
532//------------------------------------------------------------------------------
535inline
537 heapBuffer(0),
538 strLen(0),
540{
541 this->localBuffer[0] = 0;
542 this->SetCharPtr(rhs.AsCharPtr());
543}
544
545//------------------------------------------------------------------------------
548inline
549String::String(String&& rhs) noexcept:
550 heapBuffer(rhs.heapBuffer),
551 strLen(rhs.strLen),
552 heapBufferSize(rhs.heapBufferSize)
553{
554 if (rhs.heapBuffer)
555 {
556 rhs.heapBuffer = nullptr;
557 rhs.strLen = 0;
558 rhs.heapBufferSize = 0;
559 this->localBuffer[0] = 0;
560 }
561 else
562 {
563 if (this->strLen > 0)
564 {
565 Memory::Copy(rhs.localBuffer, this->localBuffer, this->strLen);
566 }
567 this->localBuffer[this->strLen] = 0;
568 rhs.heapBuffer = nullptr;
569 rhs.strLen = 0;
570 rhs.heapBufferSize = 0;
571
572 }
573}
574
575//------------------------------------------------------------------------------
578inline const char*
580{
581 if (this->heapBuffer)
582 {
583 return this->heapBuffer;
584 }
585 else
586 {
587 return this->localBuffer;
588 }
589}
590
591//------------------------------------------------------------------------------
594inline const char*
596{
597 return this->AsCharPtr();
598}
599
600//------------------------------------------------------------------------------
603inline void
605{
606 if (&rhs != this)
607 {
608 this->SetCharPtr(rhs.AsCharPtr());
609 }
610}
611
612//------------------------------------------------------------------------------
615inline void
617{
618 if (&rhs != this)
619 {
620 this->Delete();
621 this->strLen = rhs.strLen;
622 rhs.strLen = 0;
623 if (rhs.heapBuffer)
624 {
625 this->heapBuffer = rhs.heapBuffer;
626 this->heapBufferSize = rhs.heapBufferSize;
627 rhs.heapBuffer = nullptr;
628 rhs.heapBufferSize = 0;
629 }
630 else
631 {
632 if (this->strLen > 0)
633 {
634 Memory::Copy(rhs.localBuffer, this->localBuffer, this->strLen);
635 }
636 this->localBuffer[this->strLen] = 0;
637 }
638 }
639}
640
641//------------------------------------------------------------------------------
644inline void
645String::operator=(const char* cStr)
646{
647 this->SetCharPtr(cStr);
648}
649
650//------------------------------------------------------------------------------
653inline void
655{
656 this->AppendRange(str.AsCharPtr(), str.strLen);
657}
658
659//------------------------------------------------------------------------------
662inline void
664{
665 this->Append(rhs);
666}
667
668//------------------------------------------------------------------------------
671inline char
673{
674 n_assert(i <= this->strLen);
675 return this->AsCharPtr()[i];
676}
677
678//------------------------------------------------------------------------------
683inline char&
685{
686 n_assert(i <= this->strLen);
687 return (char&)(this->AsCharPtr())[i];
688}
689
690//------------------------------------------------------------------------------
693inline SizeT
695{
696 return this->strLen;
697}
698
699//------------------------------------------------------------------------------
702inline void
704{
705 this->Delete();
706}
707
708//------------------------------------------------------------------------------
711inline bool
713{
714 return (0 == this->strLen);
715}
716
717//------------------------------------------------------------------------------
720inline bool
722{
723 return (0 != this->strLen);
724}
725
726//------------------------------------------------------------------------------
731inline uint32_t
733{
734 const char* ptr = this->AsCharPtr();
735 return Hash(ptr, this->strLen);
736}
737
738//------------------------------------------------------------------------------
741static inline String
742operator+(const String& s0, const String& s1)
743{
744 String newString = s0;
745 newString.Append(s1);
746 return newString;
747}
748
749//------------------------------------------------------------------------------
753inline void
754String::SubstituteChar(char c, char subst)
755{
756 char* ptr = const_cast<char*>(this->AsCharPtr());
757 IndexT i;
758 for (i = 0; i <= this->strLen; i++)
759 {
760 if (ptr[i] == c)
761 {
762 ptr[i] = subst;
763 }
764 }
765}
766
767//------------------------------------------------------------------------------
771inline void
773{
774 this->SubstituteChar('\\', '/');
775}
776
777//------------------------------------------------------------------------------
780inline bool
782{
783 return (this->GetFileExtension() == ext);
784}
785
786//------------------------------------------------------------------------------
791inline String
793{
794 String pathString;
795 const char* lastSlash = this->GetLastSlash();
796 if (lastSlash)
797 {
798 pathString = &(lastSlash[1]);
799 }
800 else
801 {
802 pathString = *this;
803 }
804 return pathString;
805}
806
807//------------------------------------------------------------------------------
813inline String
815{
816 String pathString(*this);
817 char* lastSlash = pathString.GetLastSlash();
818 if (lastSlash)
819 {
820 lastSlash[1] = 0;
821 pathString.strLen = SizeT(lastSlash - pathString.AsCharPtr()) + 1;
822 }
823 else
824 {
825 pathString = "";
826 }
827 return pathString;
828}
829
830//------------------------------------------------------------------------------
833inline String
834String::StripSubstring(const String& substring) const
835{
836 String copy = *this;
837 copy.ConvertBackslashes();
838 IndexT it = 0;
839 while (it < copy.strLen && it < substring.strLen)
840 {
841 if (substring[it] != copy[it])
842 break;
843 it++;
844 }
845 while (copy[it] == '/')
846 it++;
847
848 if (it < substring.strLen)
849 return copy;
850 return copy.ExtractToEnd(it);
851}
852
853//------------------------------------------------------------------------------
858inline bool
860{
861 IndexT i;
862 for (i = 0; i < this->strLen; i++)
863 {
864 if (InvalidIndex == charSet.FindCharIndex((*this)[i], 0))
865 {
866 return false;
867 }
868 }
869 return true;
870}
871
872//------------------------------------------------------------------------------
875inline bool
877{
878 return this->CheckValidCharSet(" \t-+01234567890");
879}
880
881//------------------------------------------------------------------------------
885inline bool
887{
888 return this->CheckValidCharSet(" \t-+.e1234567890");
889}
890
891//------------------------------------------------------------------------------
894inline void
896{
897 this->ReplaceChars("\\/:*?\"<>|", replacement);
898}
899
900//------------------------------------------------------------------------------
903inline String
905{
906 String str;
907 str.SetByte(i);
908 return str;
909}
910
911//------------------------------------------------------------------------------
914inline String
916{
917 String str;
918 str.SetUByte(i);
919 return str;
920}
921
922//------------------------------------------------------------------------------
925inline String
927{
928 String str;
929 str.SetShort(i);
930 return str;
931}
932
933//------------------------------------------------------------------------------
936inline String
938{
939 String str;
940 str.SetUShort(i);
941 return str;
942}
943
944//------------------------------------------------------------------------------
947inline String
949{
950 String str;
951 str.SetInt(i);
952 return str;
953}
954
955//------------------------------------------------------------------------------
958inline String
960{
961 String str;
962 str.SetUInt(i);
963 return str;
964}
965
966//------------------------------------------------------------------------------
969inline String
971{
972 String str;
973 str.SetInt64(i);
974 return str;
975}
976
977//------------------------------------------------------------------------------
980inline String
982{
983 String str;
984 str.SetUInt64(i);
985 return str;
986}
987
988//------------------------------------------------------------------------------
991inline String
993{
994 String str;
995 str.SetLong(i);
996 return str;
997}
998
999//------------------------------------------------------------------------------
1002inline String
1004{
1005 String str;
1006 str.SetSizeT(i);
1007 return str;
1008}
1009
1010//------------------------------------------------------------------------------
1013inline Util::String
1015{
1016 String str;
1017 str.SetLongLong(i);
1018 return str;
1019}
1020
1021//------------------------------------------------------------------------------
1024inline String
1026{
1027 String str;
1028 str.SetFloat(f);
1029 return str;
1030}
1031
1032//------------------------------------------------------------------------------
1035inline String
1037{
1038 String str;
1039 str.SetDouble(i);
1040 return str;
1041}
1042
1043//------------------------------------------------------------------------------
1046inline String
1048{
1049 String str;
1050 str.SetBool(b);
1051 return str;
1052}
1053
1054#if !__OSX__
1055//------------------------------------------------------------------------------
1058inline String
1060{
1061 String str;
1062 str.SetVec2(v);
1063 return str;
1064}
1065
1066//------------------------------------------------------------------------------
1069inline String
1071{
1072 String str;
1073 str.SetVec3(v);
1074 return str;
1075}
1076
1077//------------------------------------------------------------------------------
1080inline String
1082{
1083 String str;
1084 str.SetVec4(v);
1085 return str;
1086}
1087
1088//------------------------------------------------------------------------------
1091inline String
1093{
1094 String str;
1095 str.SetFloat2(v);
1096 return str;
1097}
1098
1099//------------------------------------------------------------------------------
1102inline String
1104{
1105 String str;
1106 str.SetFloat3(v);
1107 return str;
1108}
1109
1110//------------------------------------------------------------------------------
1113inline String
1115{
1116 String str;
1117 str.SetFloat4(v);
1118 return str;
1119}
1120
1121//------------------------------------------------------------------------------
1124inline String
1126{
1127 String str;
1128 str.SetQuaternion(q);
1129 return str;
1130}
1131
1132//------------------------------------------------------------------------------
1135inline String
1137{
1138 String str;
1139 str.SetMat4(m);
1140 return str;
1141}
1142
1143//------------------------------------------------------------------------------
1146inline String
1148{
1149 String str;
1150 str.SetTransform44(t);
1151 return str;
1152}
1153#endif
1154
1155//------------------------------------------------------------------------------
1158template<typename INTEGER>
1159inline String
1160String::Hex(INTEGER i)
1161{
1162 constexpr SizeT hexLength = sizeof(INTEGER) << 1;
1163 static Util::String digits = "0123456789ABCDEF";
1164
1165 String str("0x");
1166 str.Reserve(hexLength + 2);
1167
1168 for (SizeT n = 0, j = (hexLength - 1) * 4; n < hexLength; ++n, j -= 4)
1169 {
1170 str.AppendChar(digits[(i >> j) & 0x0f]);
1171 }
1172
1173 return str;
1174}
1175
1176//------------------------------------------------------------------------------
1179inline void
1181{
1182 this->AppendRange(&val, 1);
1183}
1184
1185//------------------------------------------------------------------------------
1188inline void
1190{
1191 this->Append(FromInt(val));
1192}
1193
1194//------------------------------------------------------------------------------
1197inline void
1199{
1200 this->Append(FromByte(val));
1201}
1202
1203//------------------------------------------------------------------------------
1206inline void
1208{
1209 this->Append(FromUByte(val));
1210}
1211
1212//------------------------------------------------------------------------------
1215inline void
1217{
1218 this->Append(FromFloat(val));
1219}
1220
1221//------------------------------------------------------------------------------
1224inline void
1226{
1227 this->Append(FromBool(val));
1228}
1229
1230#if !__OSX__
1231//------------------------------------------------------------------------------
1234inline void
1236{
1237 this->Append(FromVec2(val));
1238}
1239
1240//------------------------------------------------------------------------------
1243inline void
1245{
1246 this->Append(FromVec3(val));
1247}
1248
1249//------------------------------------------------------------------------------
1252inline void
1254{
1255 this->Append(FromVec4(val));
1256}
1257
1258//------------------------------------------------------------------------------
1261inline void
1263{
1264 this->Append(FromMat4(val));
1265}
1266#endif
1267
1268//------------------------------------------------------------------------------
1271inline String&
1273{
1274 if (!this->IsEmpty() && this->FindCharIndexReverse('/') != (this->strLen - 1))
1275 {
1276 this->AppendChar('/');
1277 }
1278 this->Append(path);
1279 return *this;
1280}
1281
1282//------------------------------------------------------------------------------
1285inline String
1286String::AppendPath(const String& base, const String& path)
1287{
1288 String result = base;
1289 if (!result.IsEmpty() && result.FindCharIndexReverse('/') != (result.strLen - 1))
1290 {
1291 result.AppendChar('/');
1292 }
1293 result.Append(path);
1294 return result;
1295}
1296
1297//------------------------------------------------------------------------------
1300constexpr uint
1301String::Hash(const char* c, std::size_t s)
1302{
1303 uint hash = 0;
1304 std::size_t i;
1305 for (i = 0; i < s; i++)
1306 {
1307 hash += c[i];
1308 hash += hash << 10;
1309 hash ^= hash >> 6;
1310 }
1311 hash += hash << 3;
1312 hash ^= hash >> 11;
1313 hash += hash << 15;
1314 return hash;
1315}
1316
1318
1319} // namespace Util
1320
1321
1322//------------------------------------------------------------------------------
1326Util::String operator ""_str(const char* c, std::size_t s);
1327
1328//------------------------------------------------------------------------------
1332constexpr uint
1333operator ""_hash(const char* c, std::size_t s)
1334{
1335 return Util::String::Hash(c, s);
1336}
1337
1338//------------------------------------------------------------------------------
1339
A 4x4 matrix which is described by translation, rotation and scale.
Definition transform44.h:20
Nebula's dynamic array class.
Definition array.h:61
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:35
Set()
default constructor
Definition set.h:79
Nebula's universal string class.
Definition string.h:50
void SetCharPtr(const char *s)
set content to char ptr
Definition string.cc:789
T As() const
convert to "anything"
static String FromVec3(const Math::vec3 &v)
construct a string from vec3
Definition string.h:1070
void SetInt(int val)
set as int value
Definition string.cc:1539
Math::mat4 AsMat4() const
return contents as mat4
Definition string.cc:731
Util::Blob AsBlob() const
return contents as blob
Definition string.cc:1338
static bool IsAlpha(char c)
test if provided character is an alphabet character (A..Z, a..z)
Definition string.cc:1154
static String FromUByte(ubyte i)
construct a string from a ubyte
Definition string.h:915
void SetShort(short val)
set as short value
Definition string.cc:1521
void ToLower()
convert string to lower case
Definition string.cc:939
bool IsValidVec4() const
return true if the content is a valid vec4
Definition string.cc:1757
String ExtractToLastSlash() const
extract path until last slash
Definition string.h:814
static String FromUInt(uint i)
construct a string from a uint
Definition string.h:959
static String FromFloat2(const Math::float2 &v)
construct a string from float2
Definition string.h:1092
void Clear()
clear the string
Definition string.h:703
void SetTransform44(const Math::transform44 &v)
set as transform44 value
Definition string.cc:1729
~String()
destructor
Definition string.h:500
static const char * StrChr(const char *str, int c)
find character in string
Definition string.cc:1253
void Capitalize()
convert first char of string to upper case
Definition string.cc:967
void SetInt64(int64_t val)
set as int64 value
Definition string.cc:1557
void AppendVec4(const Math::vec4 &v)
append vec4 value
Definition string.h:1253
SizeT Length() const
return length of string
Definition string.h:694
size_t length() const
Definition string.h:414
void AppendChar(char val)
append character
Definition string.h:1180
bool IsValidBool() const
return true if the content is a valid bool
Definition string.cc:1042
friend bool operator!=(const String &a, const String &b)
inequality operator
Definition string.cc:894
static String FromBool(bool b)
construct a string from a bool
Definition string.h:1047
static String FromByte(byte i)
construct a string from a byte
Definition string.h:904
void AppendRange(const char *str, SizeT numChars)
append a range of characters
Definition string.cc:151
void AppendFloat(float val)
append float value
Definition string.h:1216
static String FromInt64(int64_t i)
construct a string from a int64
Definition string.h:970
void AppendByte(byte val)
append byte value
Definition string.h:1198
static String FromQuat(const Math::quat &q)
construct a string from quat
Definition string.h:1125
void ConvertBackslashes()
convert backslashes to slashes
Definition string.h:772
void SetVec2(const Math::vec2 &v)
set as vec2 value
Definition string.cc:1650
static String FromDouble(double f)
construct a string from a double
Definition string.h:1036
IndexT FindCharIndex(char c, IndexT startIndex=0) const
return index of character in string, or InvalidIndex if not found
Definition string.cc:369
void ChangeAssignMapping(const Util::String &newMapping, const Util::String &oldMapping)
Change assign mapping (not just the prefix).
Definition string.cc:1300
bool IsValid() const
return true if string object is not empty
Definition string.h:721
void StripFileExtension()
remove file extension
Definition string.cc:827
void SetBool(bool val)
set as bool value
Definition string.cc:1620
void AppendBool(bool val)
append bool value
Definition string.h:1225
static String FromTransform44(const Math::transform44 &m)
construct a string from transform44
Definition string.h:1147
void SetDouble(double val)
set as double value
Definition string.cc:1611
void AppendVec2(const Math::vec2 &v)
append vec2 value
Definition string.h:1235
bool AsBool() const
return contents as bool
Definition string.cc:1123
void SetLongLong(long long val)
set as long long value
Definition string.cc:1593
void ToUpper()
convert string to upper case
Definition string.cc:953
friend bool operator<=(const String &a, const String &b)
less-or-equal operator
Definition string.cc:921
static int StrICmp(const char *str0, const char *str1)
lowlevel case-insensitive string compare function
Definition string.cc:1220
static bool IsDigit(char c)
test if provided character is a digit (0..9)
Definition string.cc:1145
static String Concatenate(const Array< String > &strArray, const String &whiteSpace)
concatenate array of strings into new string
Definition string.cc:768
void TrimLeft(const String &charSet)
delete characters from charset at left side of string
Definition string.cc:434
friend bool operator==(const String &a, const String &b)
equality operator
Definition string.cc:856
void SetUInt64(uint64_t val)
set as uint64 value
Definition string.cc:1566
void StripAssignPrefix()
remove assign prefix (for example tex:)
Definition string.cc:842
void SetFloat4(const Math::float4 &v)
set as vec4 value
Definition string.cc:1695
char operator[](IndexT i) const
read-only index operator
Definition string.h:672
void Fill(SizeT length, unsigned char character)
set string length and fill all characters with arg
Definition string.cc:1636
bool IsValidInt() const
return true if the content is a valid integer
Definition string.h:876
static String FromInt(int i)
construct a string from an int
Definition string.h:948
static String FromFloat(float f)
construct a string from a float
Definition string.h:1025
static String FromVec4(const Math::vec4 &v)
construct a string from vec4
Definition string.h:1081
void __cdecl FormatArgList(const char *fmtString, va_list argList)
format string printf-style with varargs list
Definition string.cc:78
float AsFloat() const
return contents as float
Definition string.cc:1114
String()
constructor
Definition string.h:472
void ChangeAssignPrefix(const Util::String &newPref)
change assign prefix
Definition string.cc:1290
void ReplaceIllegalFilenameChars(char replacement)
replace illegal filename characters
Definition string.h:895
void __cdecl Format(const char *fmtString,...)
format string printf-style
Definition string.cc:57
void Delete()
delete contents
Definition string.h:484
Util::String AsBase64() const
return contents as base64 string
Definition string.cc:1391
bool CopyToBuffer(char *buf, SizeT bufSize) const
copy to char buffer (return false if buffer is too small)
Definition string.cc:38
Math::vec4 AsVec4() const
return contents as vec4
Definition string.cc:1824
bool CheckFileExtension(const String &ext) const
check file extension
Definition string.h:781
int64_t AsInt64() const
return contents as int64_t
Definition string.cc:1078
void ReplaceChars(const String &charSet, char replacement)
replace any char set character within a string with the replacement character
Definition string.cc:708
String ExtractFileName() const
extract the part after the last directory separator
Definition string.h:792
void Append(const T &t)
generic append
String ExtractToEnd(IndexT fromIndex) const
extract substring to end of this string
Definition string.cc:317
static String FromBase64(const String &)
create from base64
Definition string.cc:1408
void SetMat4(const Math::mat4 &v)
set as mat4 value
Definition string.cc:1713
bool IsValidFloat() const
return true if the content is a valid float
Definition string.h:886
void SetSizeT(size_t val)
set as long value
Definition string.cc:1584
Math::float3 AsFloat3() const
return contents as vec3
Definition string.cc:1850
void TrimRight(const String &charSet)
delete characters from charset at right side of string
Definition string.cc:476
void Alloc(SizeT size)
allocate the string buffer (discards old content)
Definition string.cc:1435
static String FromUInt64(uint64_t i)
construct a string from a uint64
Definition string.h:981
Math::vec2 AsVec2() const
return contents as vec2
Definition string.cc:1795
static String FromFloat3(const Math::float3 &v)
construct a string from float2
Definition string.h:1103
void ChangeFileExtension(const Util::String &newExt)
change file extension
Definition string.cc:1280
static bool IsUpper(char c)
test if provided character is an upper-case character
Definition string.cc:1181
Math::transform44 AsTransform44() const
return contents as transform44
Definition string.cc:748
void Set(const T &t)
generic setter
void Append(const String &str)
append string
Definition string.h:654
Math::float4 AsFloat4() const
return contents as vec4
Definition string.cc:1863
friend bool operator<(const String &a, const String &b)
less-then operator
Definition string.cc:903
void AppendUByte(ubyte val)
append unsigned byte value
Definition string.h:1207
String ExtractDirName() const
extract the part before the last directory separator
Definition string.cc:606
static constexpr uint Hash(const char *c, std::size_t s)
Hash a string.
Definition string.h:1301
static int StrCmp(const char *str0, const char *str1)
lowlevel string compare wrapper function
Definition string.cc:1208
char * GetLastSlash() const
get pointer to last directory separator, or nullptr if there is none
Definition string.cc:1029
SizeT heapBufferSize
Definition string.h:465
static String From(const T &t)
convert from "anything"
void operator=(const String &rhs)
assignment operator
Definition string.h:604
String StripSubstring(const String &substring) const
removes the leading substring from this string as long as it's matching
Definition string.h:834
void SetLong(long val)
set as long value
Definition string.cc:1575
static String FromLongLong(long long i)
construct a string from a long long
Definition string.h:1014
void SetByte(byte val)
set as byte value
Definition string.cc:1503
Math::float2 AsFloat2() const
return contents as vec2
Definition string.cc:1837
static String FromMat4(const Math::mat4 &m)
construct a string from mat4
Definition string.h:1136
int AsInt() const
return contents as integer
Definition string.cc:1066
const char * data() const
Definition string.h:418
void SetVec3(const Math::vec3 &v)
set as vec3 value
Definition string.cc:1659
void SetUInt(uint val)
set as uint value
Definition string.cc:1548
static String FromBlob(const Util::Blob &b)
create from blob
Definition string.cc:1312
static String FromShort(short i)
construct a string from a short
Definition string.h:926
void AppendVec3(const Math::vec3 &v)
append vec3 value
Definition string.h:1244
void Strip(const String &charSet)
terminate string at first occurence of character in set
Definition string.cc:328
static String FromUShort(ushort i)
construct a string from a ushort
Definition string.h:937
void TerminateAtIndex(IndexT index)
terminate string at given index
Definition string.cc:814
bool BeginsWithString(const String &s) const
returns true if string begins with string
Definition string.cc:406
void SetVec4(const Math::vec4 &v)
set as vec4 value
Definition string.cc:1668
void AppendMat4(const Math::mat4 &v)
append mat4 value
Definition string.h:1262
const char * AsCharPtr() const
return contents as character pointer
Definition string.h:579
void AppendInt(int val)
append int value
Definition string.h:1189
static String FromVec2(const Math::vec2 &v)
construct a string from vec2
Definition string.h:1059
void Realloc(SizeT newSize)
(re-)allocate the string buffer (copies old content)
Definition string.cc:1458
String ExtractLastDirName() const
extract the last directory of the path
Definition string.cc:566
@ LocalStringSize
Definition string.h:460
void SetFloat(float val)
set as float value
Definition string.cc:1602
static int StrLen(const char *str)
lowlevel string length function
Definition string.cc:1243
char * heapBuffer
Definition string.h:462
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:201
static Dictionary< String, String > ParseKeyValuePairs(const String &str)
parse key/value pair string ("key0=value0 key1=value1")
Definition string.cc:1263
void SetFloat2(const Math::float2 &v)
set as vec2 value
Definition string.cc:1677
bool IsValidTransform44() const
return true if content is a valid transform44
Definition string.cc:1781
void Trim(const String &charSet)
trim characters from charset at both sides of string
Definition string.cc:519
friend bool operator>(const String &a, const String &b)
greater-then operator
Definition string.cc:912
bool IsValidMat4() const
return true if content is a valid mat4
Definition string.cc:1769
const char * Get() const
*** OBSOLETE *** only Nebula2 compatibility
Definition string.h:595
static bool IsLower(char c)
test if provided character is a lower case character
Definition string.cc:1172
bool IsEmpty() const
return true if string object is empty
Definition string.h:712
String GetFileExtension() const
get filename extension without dot
Definition string.cc:1011
void SubstituteString(const String &str, const String &substStr)
substitute every occurance of a string with another string
Definition string.cc:530
String & AppendPath(const String &path)
Appends a directory or file to current string.
Definition string.h:1272
static bool MatchPattern(const String &str, const String &pattern)
pattern matching
Definition string.cc:633
static String FromLong(long i)
construct a string from a long
Definition string.h:992
char localBuffer[LocalStringSize]
Definition string.h:463
void operator+=(const String &rhs)
+= operator
Definition string.h:663
bool EndsWithString(const String &s) const
returns true if string ends with string
Definition string.cc:419
static String Sprintf(const char *fmtString,...)
static constructor for string using printf
Definition string.cc:96
void SetQuaternion(const Math::quat &v)
set as quaternion
Definition string.cc:1704
const char * c_str() const
helpers to interface with libraries that expect std::string like apis
Definition string.h:412
void CamelCaseToWords()
insert spaces before each capital letter in the string.
Definition string.cc:977
static String FromSize(size_t i)
construct a string from a size_t
Definition string.h:1003
IndexT FindStringIndex(const String &s, IndexT startIndex=0) const
return start index of substring, or InvalidIndex if not found
Definition string.cc:344
uint32_t HashCode() const
return a 32-bit hash code for the string
Definition string.h:732
uint32_t AsUInt() const
return contents as unsigned integer
Definition string.cc:1090
void SubstituteChar(char c, char subst)
substitute every occurance of a character with another character
Definition string.h:754
static String Hex(INTEGER i)
construct a hex string from an int
Definition string.h:1160
void SetUByte(ubyte val)
set as ubyte value
Definition string.cc:1512
String ExtractRange(IndexT fromIndex, SizeT numChars) const
extract substring
Definition string.cc:302
void SetUShort(ushort val)
set as ushort value
Definition string.cc:1530
static String FromFloat4(const Math::float4 &v)
construct a string from float2
Definition string.h:1114
Math::vec3 AsVec3() const
return contents as vec3
Definition string.cc:1808
friend bool operator>=(const String &a, const String &b)
greater-then operator
Definition string.cc:930
bool CheckValidCharSet(const String &charSet) const
return true if string only contains characters from charSet argument
Definition string.h:859
bool IsValid() const
generic valid checker
uint64_t AsUInt64() const
return contents as unsigned uint64_t
Definition string.cc:1102
bool empty() const
Definition string.h:416
SizeT strLen
Definition string.h:464
IndexT FindCharIndexReverse(char c, IndexT startIndex=0) const
return index of character in string, or InvalidIndex if not found
Definition string.cc:388
void Reserve(SizeT newSize)
reserve internal buffer size to prevent heap allocs
Definition string.cc:1491
bool ContainsCharFromSet(const String &charSet) const
returns true if string contains any character from set
Definition string.cc:999
void SetFloat3(const Math::float3 &v)
set as vec3 value
Definition string.cc:1686
static bool IsAlNum(char c)
test if provided character is an alpha-numeric character (A..Z,a..z,0..9)
Definition string.cc:1163
bool IsValidVec2() const
return true if the content is a valid vec2
Definition string.cc:1745
#define n_assert(exp)
Definition debug.h:58
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 quad tree designed to return regions of free 2D space.
Definition Random.cs:5
auto Format
Definition string.h:1317
Definition scalar.h:58
Definition scalar.h:67
Definition scalar.h:76
A 4x4 single point precision float matrix.
Definition mat4.h:55
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
unsigned char ubyte
Definition types.h:44
int SizeT
Definition types.h:50
unsigned int uint
Definition types.h:41
unsigned short ushort
Definition types.h:42
int IndexT
Definition types.h:49