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 void 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 StrLen(const char* str);
441 static const char* StrChr(const char* str, int c);
442
445
446private:
448 void Delete();
450 char* GetLastSlash() const;
452 void Alloc(SizeT size);
454 void Realloc(SizeT newSize);
455
456 enum
457 {
459 };
464};
465
466//------------------------------------------------------------------------------
469inline
471 heapBuffer(nullptr),
472 strLen(0),
474{
475 this->localBuffer[0] = 0;
476}
477
478//------------------------------------------------------------------------------
481inline void
483{
484 if (this->heapBuffer)
485 {
487 this->heapBuffer = nullptr;
488 }
489 this->localBuffer[0] = 0;
490 this->strLen = 0;
491 this->heapBufferSize = 0;
492}
493
494//------------------------------------------------------------------------------
497inline
499{
500 this->Delete();
501}
502
503//------------------------------------------------------------------------------
506inline
507String::String(const char* str) :
508 heapBuffer(0),
509 strLen(0),
511{
512 this->localBuffer[0] = 0;
513 this->SetCharPtr(str);
514}
515
516//------------------------------------------------------------------------------
519inline
520String::String(const char* str, size_t len) :
521 heapBuffer(0),
522 strLen(0),
524{
525 this->localBuffer[0] = 0;
526 this->Set(str, (SizeT)len);
527}
528
529
530//------------------------------------------------------------------------------
533inline
535 heapBuffer(0),
536 strLen(0),
538{
539 this->localBuffer[0] = 0;
540 this->SetCharPtr(rhs.AsCharPtr());
541}
542
543//------------------------------------------------------------------------------
546inline
547String::String(String&& rhs) noexcept:
548 heapBuffer(rhs.heapBuffer),
549 strLen(rhs.strLen),
550 heapBufferSize(rhs.heapBufferSize)
551{
552 if (rhs.heapBuffer)
553 {
554 rhs.heapBuffer = nullptr;
555 rhs.strLen = 0;
556 rhs.heapBufferSize = 0;
557 this->localBuffer[0] = 0;
558 }
559 else
560 {
561 if (this->strLen > 0)
562 {
563 Memory::Copy(rhs.localBuffer, this->localBuffer, this->strLen);
564 }
565 this->localBuffer[this->strLen] = 0;
566 rhs.heapBuffer = nullptr;
567 rhs.strLen = 0;
568 rhs.heapBufferSize = 0;
569
570 }
571}
572
573//------------------------------------------------------------------------------
576inline const char*
578{
579 if (this->heapBuffer)
580 {
581 return this->heapBuffer;
582 }
583 else
584 {
585 return this->localBuffer;
586 }
587}
588
589//------------------------------------------------------------------------------
592inline const char*
594{
595 return this->AsCharPtr();
596}
597
598//------------------------------------------------------------------------------
601inline void
603{
604 if (&rhs != this)
605 {
606 this->SetCharPtr(rhs.AsCharPtr());
607 }
608}
609
610//------------------------------------------------------------------------------
613inline void
615{
616 if (&rhs != this)
617 {
618 this->Delete();
619 this->strLen = rhs.strLen;
620 rhs.strLen = 0;
621 if (rhs.heapBuffer)
622 {
623 this->heapBuffer = rhs.heapBuffer;
624 this->heapBufferSize = rhs.heapBufferSize;
625 rhs.heapBuffer = nullptr;
626 rhs.heapBufferSize = 0;
627 }
628 else
629 {
630 if (this->strLen > 0)
631 {
632 Memory::Copy(rhs.localBuffer, this->localBuffer, this->strLen);
633 }
634 this->localBuffer[this->strLen] = 0;
635 }
636 }
637}
638
639//------------------------------------------------------------------------------
642inline void
643String::operator=(const char* cStr)
644{
645 this->SetCharPtr(cStr);
646}
647
648//------------------------------------------------------------------------------
651inline void
653{
654 this->AppendRange(str.AsCharPtr(), str.strLen);
655}
656
657//------------------------------------------------------------------------------
660inline void
662{
663 this->Append(rhs);
664}
665
666//------------------------------------------------------------------------------
669inline char
671{
672 n_assert(i <= this->strLen);
673 return this->AsCharPtr()[i];
674}
675
676//------------------------------------------------------------------------------
681inline char&
683{
684 n_assert(i <= this->strLen);
685 return (char&)(this->AsCharPtr())[i];
686}
687
688//------------------------------------------------------------------------------
691inline SizeT
693{
694 return this->strLen;
695}
696
697//------------------------------------------------------------------------------
700inline void
702{
703 this->Delete();
704}
705
706//------------------------------------------------------------------------------
709inline bool
711{
712 return (0 == this->strLen);
713}
714
715//------------------------------------------------------------------------------
718inline bool
720{
721 return (0 != this->strLen);
722}
723
724//------------------------------------------------------------------------------
729inline uint32_t
731{
732 const char* ptr = this->AsCharPtr();
733 return Hash(ptr, this->strLen);
734}
735
736//------------------------------------------------------------------------------
739static inline String
740operator+(const String& s0, const String& s1)
741{
742 String newString = s0;
743 newString.Append(s1);
744 return newString;
745}
746
747//------------------------------------------------------------------------------
751inline void
752String::SubstituteChar(char c, char subst)
753{
754 char* ptr = const_cast<char*>(this->AsCharPtr());
755 IndexT i;
756 for (i = 0; i <= this->strLen; i++)
757 {
758 if (ptr[i] == c)
759 {
760 ptr[i] = subst;
761 }
762 }
763}
764
765//------------------------------------------------------------------------------
769inline void
771{
772 this->SubstituteChar('\\', '/');
773}
774
775//------------------------------------------------------------------------------
778inline bool
780{
781 return (this->GetFileExtension() == ext);
782}
783
784//------------------------------------------------------------------------------
789inline String
791{
792 String pathString;
793 const char* lastSlash = this->GetLastSlash();
794 if (lastSlash)
795 {
796 pathString = &(lastSlash[1]);
797 }
798 else
799 {
800 pathString = *this;
801 }
802 return pathString;
803}
804
805//------------------------------------------------------------------------------
811inline String
813{
814 String pathString(*this);
815 char* lastSlash = pathString.GetLastSlash();
816 if (lastSlash)
817 {
818 lastSlash[1] = 0;
819 }
820 else
821 {
822 pathString = "";
823 }
824 return pathString;
825}
826
827//------------------------------------------------------------------------------
830inline String
831String::StripSubstring(const String& substring) const
832{
833 String copy = *this;
834 copy.ConvertBackslashes();
835 IndexT it = 0;
836 while (it < copy.strLen && it < substring.strLen)
837 {
838 if (substring[it] != copy[it])
839 break;
840 it++;
841 }
842 while (copy[it] == '/')
843 it++;
844
845 if (it < substring.strLen)
846 return copy;
847 return copy.ExtractToEnd(it);
848}
849
850//------------------------------------------------------------------------------
855inline bool
857{
858 IndexT i;
859 for (i = 0; i < this->strLen; i++)
860 {
861 if (InvalidIndex == charSet.FindCharIndex((*this)[i], 0))
862 {
863 return false;
864 }
865 }
866 return true;
867}
868
869//------------------------------------------------------------------------------
872inline bool
874{
875 return this->CheckValidCharSet(" \t-+01234567890");
876}
877
878//------------------------------------------------------------------------------
882inline bool
884{
885 return this->CheckValidCharSet(" \t-+.e1234567890");
886}
887
888//------------------------------------------------------------------------------
891inline void
893{
894 this->ReplaceChars("\\/:*?\"<>|", replacement);
895}
896
897//------------------------------------------------------------------------------
900inline String
902{
903 String str;
904 str.SetByte(i);
905 return str;
906}
907
908//------------------------------------------------------------------------------
911inline String
913{
914 String str;
915 str.SetUByte(i);
916 return str;
917}
918
919//------------------------------------------------------------------------------
922inline String
924{
925 String str;
926 str.SetShort(i);
927 return str;
928}
929
930//------------------------------------------------------------------------------
933inline String
935{
936 String str;
937 str.SetUShort(i);
938 return str;
939}
940
941//------------------------------------------------------------------------------
944inline String
946{
947 String str;
948 str.SetInt(i);
949 return str;
950}
951
952//------------------------------------------------------------------------------
955inline String
957{
958 String str;
959 str.SetUInt(i);
960 return str;
961}
962
963//------------------------------------------------------------------------------
966inline String
968{
969 String str;
970 str.SetInt64(i);
971 return str;
972}
973
974//------------------------------------------------------------------------------
977inline String
979{
980 String str;
981 str.SetUInt64(i);
982 return str;
983}
984
985//------------------------------------------------------------------------------
988inline String
990{
991 String str;
992 str.SetLong(i);
993 return str;
994}
995
996//------------------------------------------------------------------------------
999inline String
1001{
1002 String str;
1003 str.SetSizeT(i);
1004 return str;
1005}
1006
1007//------------------------------------------------------------------------------
1010inline Util::String
1012{
1013 String str;
1014 str.SetLongLong(i);
1015 return str;
1016}
1017
1018//------------------------------------------------------------------------------
1021inline String
1023{
1024 String str;
1025 str.SetFloat(f);
1026 return str;
1027}
1028
1029//------------------------------------------------------------------------------
1032inline String
1034{
1035 String str;
1036 str.SetDouble(i);
1037 return str;
1038}
1039
1040//------------------------------------------------------------------------------
1043inline String
1045{
1046 String str;
1047 str.SetBool(b);
1048 return str;
1049}
1050
1051#if !__OSX__
1052//------------------------------------------------------------------------------
1055inline String
1057{
1058 String str;
1059 str.SetVec2(v);
1060 return str;
1061}
1062
1063//------------------------------------------------------------------------------
1066inline String
1068{
1069 String str;
1070 str.SetVec3(v);
1071 return str;
1072}
1073
1074//------------------------------------------------------------------------------
1077inline String
1079{
1080 String str;
1081 str.SetVec4(v);
1082 return str;
1083}
1084
1085//------------------------------------------------------------------------------
1088inline String
1090{
1091 String str;
1092 str.SetFloat2(v);
1093 return str;
1094}
1095
1096//------------------------------------------------------------------------------
1099inline String
1101{
1102 String str;
1103 str.SetFloat3(v);
1104 return str;
1105}
1106
1107//------------------------------------------------------------------------------
1110inline String
1112{
1113 String str;
1114 str.SetFloat4(v);
1115 return str;
1116}
1117
1118//------------------------------------------------------------------------------
1121inline String
1123{
1124 String str;
1125 str.SetQuaternion(q);
1126 return str;
1127}
1128
1129//------------------------------------------------------------------------------
1132inline String
1134{
1135 String str;
1136 str.SetMat4(m);
1137 return str;
1138}
1139
1140//------------------------------------------------------------------------------
1143inline String
1145{
1146 String str;
1147 str.SetTransform44(t);
1148 return str;
1149}
1150#endif
1151
1152//------------------------------------------------------------------------------
1155template<typename INTEGER>
1156inline String
1157String::Hex(INTEGER i)
1158{
1159 constexpr SizeT hexLength = sizeof(INTEGER) << 1;
1160 static Util::String digits = "0123456789ABCDEF";
1161
1162 String str("0x");
1163 str.Reserve(hexLength + 2);
1164
1165 for (SizeT n = 0, j = (hexLength - 1) * 4; n < hexLength; ++n, j -= 4)
1166 {
1167 str.AppendChar(digits[(i >> j) & 0x0f]);
1168 }
1169
1170 return str;
1171}
1172
1173//------------------------------------------------------------------------------
1176inline void
1178{
1179 this->AppendRange(&val, 1);
1180}
1181
1182//------------------------------------------------------------------------------
1185inline void
1187{
1188 this->Append(FromInt(val));
1189}
1190
1191//------------------------------------------------------------------------------
1194inline void
1196{
1197 this->Append(FromByte(val));
1198}
1199
1200//------------------------------------------------------------------------------
1203inline void
1205{
1206 this->Append(FromUByte(val));
1207}
1208
1209//------------------------------------------------------------------------------
1212inline void
1214{
1215 this->Append(FromFloat(val));
1216}
1217
1218//------------------------------------------------------------------------------
1221inline void
1223{
1224 this->Append(FromBool(val));
1225}
1226
1227#if !__OSX__
1228//------------------------------------------------------------------------------
1231inline void
1233{
1234 this->Append(FromVec2(val));
1235}
1236
1237//------------------------------------------------------------------------------
1240inline void
1242{
1243 this->Append(FromVec3(val));
1244}
1245
1246//------------------------------------------------------------------------------
1249inline void
1251{
1252 this->Append(FromVec4(val));
1253}
1254
1255//------------------------------------------------------------------------------
1258inline void
1260{
1261 this->Append(FromMat4(val));
1262}
1263#endif
1264
1265//------------------------------------------------------------------------------
1268inline void
1270{
1271 if (!this->IsEmpty() && this->FindCharIndexReverse('/') != (this->strLen - 1))
1272 {
1273 this->AppendChar('/');
1274 }
1275 this->Append(path);
1276}
1277
1278//------------------------------------------------------------------------------
1281inline String
1282String::AppendPath(const String& base, const String& path)
1283{
1284 String result = base;
1285 if (!result.IsEmpty() && result.FindCharIndexReverse('/') != (result.strLen - 1))
1286 {
1287 result.AppendChar('/');
1288 }
1289 result.Append(path);
1290 return result;
1291}
1292
1293//------------------------------------------------------------------------------
1296constexpr uint
1297String::Hash(const char* c, std::size_t s)
1298{
1299 uint hash = 0;
1300 std::size_t i;
1301 for (i = 0; i < s; i++)
1302 {
1303 hash += c[i];
1304 hash += hash << 10;
1305 hash ^= hash >> 6;
1306 }
1307 hash += hash << 3;
1308 hash ^= hash >> 11;
1309 hash += hash << 15;
1310 return hash;
1311}
1312
1314
1315} // namespace Util
1316
1317
1318//------------------------------------------------------------------------------
1322Util::String operator ""_str(const char* c, std::size_t s);
1323
1324//------------------------------------------------------------------------------
1328constexpr uint
1329operator ""_hash(const char* c, std::size_t s)
1330{
1331 return Util::String::Hash(c, s);
1332}
1333
1334//------------------------------------------------------------------------------
1335
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
Nebula's universal string class.
Definition string.h:50
void SetCharPtr(const char *s)
set content to char ptr
Definition string.cc:781
T As() const
convert to "anything"
static String FromVec3(const Math::vec3 &v)
construct a string from vec3
Definition string.h:1067
void SetInt(int val)
set as int value
Definition string.cc:1501
Math::mat4 AsMat4() const
return contents as mat4
Definition string.cc:723
Util::Blob AsBlob() const
return contents as blob
Definition string.cc:1304
static bool IsAlpha(char c)
test if provided character is an alphabet character (A..Z, a..z)
Definition string.cc:1145
static String FromUByte(ubyte i)
construct a string from a ubyte
Definition string.h:912
void SetShort(short val)
set as short value
Definition string.cc:1483
void ToLower()
convert string to lower case
Definition string.cc:931
bool IsValidVec4() const
return true if the content is a valid vec4
Definition string.cc:1719
String ExtractToLastSlash() const
extract path until last slash
Definition string.h:812
static String FromUInt(uint i)
construct a string from a uint
Definition string.h:956
static String FromFloat2(const Math::float2 &v)
construct a string from float2
Definition string.h:1089
void Clear()
clear the string
Definition string.h:701
void SetTransform44(const Math::transform44 &v)
set as transform44 value
Definition string.cc:1691
~String()
destructor
Definition string.h:498
static const char * StrChr(const char *str, int c)
find character in string
Definition string.cc:1219
void Capitalize()
convert first char of string to upper case
Definition string.cc:959
void SetInt64(int64_t val)
set as int64 value
Definition string.cc:1519
void AppendVec4(const Math::vec4 &v)
append vec4 value
Definition string.h:1250
SizeT Length() const
return length of string
Definition string.h:692
size_t length() const
Definition string.h:414
void AppendChar(char val)
append character
Definition string.h:1177
bool IsValidBool() const
return true if the content is a valid bool
Definition string.cc:1033
friend bool operator!=(const String &a, const String &b)
inequality operator
Definition string.cc:886
static String FromBool(bool b)
construct a string from a bool
Definition string.h:1044
static String FromByte(byte i)
construct a string from a byte
Definition string.h:901
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:1213
static String FromInt64(int64_t i)
construct a string from a int64
Definition string.h:967
void AppendByte(byte val)
append byte value
Definition string.h:1195
static String FromQuat(const Math::quat &q)
construct a string from quat
Definition string.h:1122
void ConvertBackslashes()
convert backslashes to slashes
Definition string.h:770
void SetVec2(const Math::vec2 &v)
set as vec2 value
Definition string.cc:1612
static String FromDouble(double f)
construct a string from a double
Definition string.h:1033
IndexT FindCharIndex(char c, IndexT startIndex=0) const
return index of character in string, or InvalidIndex if not found
Definition string.cc:361
void ChangeAssignMapping(const Util::String &newMapping, const Util::String &oldMapping)
Change assign mapping (not just the prefix).
Definition string.cc:1266
bool IsValid() const
return true if string object is not empty
Definition string.h:719
void StripFileExtension()
remove file extension
Definition string.cc:819
void SetBool(bool val)
set as bool value
Definition string.cc:1582
void Set(const char *ptr, SizeT length)
set as char ptr, with explicit length
Definition string.cc:112
void AppendBool(bool val)
append bool value
Definition string.h:1222
static String FromTransform44(const Math::transform44 &m)
construct a string from transform44
Definition string.h:1144
void SetDouble(double val)
set as double value
Definition string.cc:1573
void AppendVec2(const Math::vec2 &v)
append vec2 value
Definition string.h:1232
bool AsBool() const
return contents as bool
Definition string.cc:1114
void SetLongLong(long long val)
set as long long value
Definition string.cc:1555
void ToUpper()
convert string to upper case
Definition string.cc:945
friend bool operator<=(const String &a, const String &b)
less-or-equal operator
Definition string.cc:913
static bool IsDigit(char c)
test if provided character is a digit (0..9)
Definition string.cc:1136
static String Concatenate(const Array< String > &strArray, const String &whiteSpace)
concatenate array of strings into new string
Definition string.cc:760
void TrimLeft(const String &charSet)
delete characters from charset at left side of string
Definition string.cc:426
friend bool operator==(const String &a, const String &b)
equality operator
Definition string.cc:848
void SetUInt64(uint64_t val)
set as uint64 value
Definition string.cc:1528
void StripAssignPrefix()
remove assign prefix (for example tex:)
Definition string.cc:834
void SetFloat4(const Math::float4 &v)
set as vec4 value
Definition string.cc:1657
char operator[](IndexT i) const
read-only index operator
Definition string.h:670
void Fill(SizeT length, unsigned char character)
set string length and fill all characters with arg
Definition string.cc:1598
bool IsValidInt() const
return true if the content is a valid integer
Definition string.h:873
static String FromInt(int i)
construct a string from an int
Definition string.h:945
static String FromFloat(float f)
construct a string from a float
Definition string.h:1022
static String FromVec4(const Math::vec4 &v)
construct a string from vec4
Definition string.h:1078
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:1105
String()
constructor
Definition string.h:470
void ChangeAssignPrefix(const Util::String &newPref)
change assign prefix
Definition string.cc:1256
void ReplaceIllegalFilenameChars(char replacement)
replace illegal filename characters
Definition string.h:892
void Delete()
delete contents
Definition string.h:482
Util::String AsBase64() const
return contents as base64 string
Definition string.cc:1357
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:1786
bool CheckFileExtension(const String &ext) const
check file extension
Definition string.h:779
int64_t AsInt64() const
return contents as int64_t
Definition string.cc:1069
void ReplaceChars(const String &charSet, char replacement)
replace any char set character within a string with the replacement character
Definition string.cc:700
String ExtractFileName() const
extract the part after the last directory separator
Definition string.h:790
void Append(const T &t)
generic append
String ExtractToEnd(IndexT fromIndex) const
extract substring to end of this string
Definition string.cc:309
static String FromBase64(const String &)
create from base64
Definition string.cc:1374
void SetMat4(const Math::mat4 &v)
set as mat4 value
Definition string.cc:1675
bool IsValidFloat() const
return true if the content is a valid float
Definition string.h:883
void SetSizeT(size_t val)
set as long value
Definition string.cc:1546
Math::float3 AsFloat3() const
return contents as vec3
Definition string.cc:1812
void TrimRight(const String &charSet)
delete characters from charset at right side of string
Definition string.cc:468
void Alloc(SizeT size)
allocate the string buffer (discards old content)
Definition string.cc:1397
static String FromUInt64(uint64_t i)
construct a string from a uint64
Definition string.h:978
Math::vec2 AsVec2() const
return contents as vec2
Definition string.cc:1757
static String FromFloat3(const Math::float3 &v)
construct a string from float2
Definition string.h:1100
void ChangeFileExtension(const Util::String &newExt)
change file extension
Definition string.cc:1246
static bool IsUpper(char c)
test if provided character is an upper-case character
Definition string.cc:1172
Math::transform44 AsTransform44() const
return contents as transform44
Definition string.cc:740
void Set(const T &t)
generic setter
void Append(const String &str)
append string
Definition string.h:652
Math::float4 AsFloat4() const
return contents as vec4
Definition string.cc:1825
friend bool operator<(const String &a, const String &b)
less-then operator
Definition string.cc:895
void AppendUByte(ubyte val)
append unsigned byte value
Definition string.h:1204
String ExtractDirName() const
extract the part before the last directory separator
Definition string.cc:598
static constexpr uint Hash(const char *c, std::size_t s)
Hash a string.
Definition string.h:1297
static int StrCmp(const char *str0, const char *str1)
lowlevel string compare wrapper function
Definition string.cc:1199
char * GetLastSlash() const
get pointer to last directory separator
Definition string.cc:1020
SizeT heapBufferSize
Definition string.h:463
static String From(const T &t)
convert from "anything"
void operator=(const String &rhs)
assignment operator
Definition string.h:602
String StripSubstring(const String &substring) const
removes the leading substring from this string as long as it's matching
Definition string.h:831
void SetLong(long val)
set as long value
Definition string.cc:1537
static String FromLongLong(long long i)
construct a string from a long long
Definition string.h:1011
void SetByte(byte val)
set as byte value
Definition string.cc:1465
Math::float2 AsFloat2() const
return contents as vec2
Definition string.cc:1799
static String FromMat4(const Math::mat4 &m)
construct a string from mat4
Definition string.h:1133
int AsInt() const
return contents as integer
Definition string.cc:1057
const char * data() const
Definition string.h:418
void SetVec3(const Math::vec3 &v)
set as vec3 value
Definition string.cc:1621
void SetUInt(uint val)
set as uint value
Definition string.cc:1510
static String FromBlob(const Util::Blob &b)
create from blob
Definition string.cc:1278
static String FromShort(short i)
construct a string from a short
Definition string.h:923
void AppendVec3(const Math::vec3 &v)
append vec3 value
Definition string.h:1241
void Strip(const String &charSet)
terminate string at first occurence of character in set
Definition string.cc:320
static String FromUShort(ushort i)
construct a string from a ushort
Definition string.h:934
void TerminateAtIndex(IndexT index)
terminate string at given index
Definition string.cc:806
bool BeginsWithString(const String &s) const
returns true if string begins with string
Definition string.cc:398
void SetVec4(const Math::vec4 &v)
set as vec4 value
Definition string.cc:1630
void AppendMat4(const Math::mat4 &v)
append mat4 value
Definition string.h:1259
const char * AsCharPtr() const
return contents as character pointer
Definition string.h:577
void AppendInt(int val)
append int value
Definition string.h:1186
static String FromVec2(const Math::vec2 &v)
construct a string from vec2
Definition string.h:1056
void Realloc(SizeT newSize)
(re-)allocate the string buffer (copies old content)
Definition string.cc:1420
String ExtractLastDirName() const
extract the last directory of the path
Definition string.cc:558
@ LocalStringSize
Definition string.h:458
void SetFloat(float val)
set as float value
Definition string.cc:1564
static int StrLen(const char *str)
lowlevel string length function
Definition string.cc:1209
char * heapBuffer
Definition string.h:460
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
static Dictionary< String, String > ParseKeyValuePairs(const String &str)
parse key/value pair string ("key0=value0 key1=value1")
Definition string.cc:1229
void SetFloat2(const Math::float2 &v)
set as vec2 value
Definition string.cc:1639
bool IsValidTransform44() const
return true if content is a valid transform44
Definition string.cc:1743
void Trim(const String &charSet)
trim characters from charset at both sides of string
Definition string.cc:511
friend bool operator>(const String &a, const String &b)
greater-then operator
Definition string.cc:904
bool IsValidMat4() const
return true if content is a valid mat4
Definition string.cc:1731
const char * Get() const
*** OBSOLETE *** only Nebula2 compatibility
Definition string.h:593
static bool IsLower(char c)
test if provided character is a lower case character
Definition string.cc:1163
bool IsEmpty() const
return true if string object is empty
Definition string.h:710
String GetFileExtension() const
get filename extension without dot
Definition string.cc:1003
void SubstituteString(const String &str, const String &substStr)
substitute every occurance of a string with another string
Definition string.cc:522
static bool MatchPattern(const String &str, const String &pattern)
pattern matching
Definition string.cc:625
static String FromLong(long i)
construct a string from a long
Definition string.h:989
char localBuffer[LocalStringSize]
Definition string.h:461
void operator+=(const String &rhs)
+= operator
Definition string.h:661
bool EndsWithString(const String &s) const
returns true if string ends with string
Definition string.cc:411
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:1666
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:969
static String FromSize(size_t i)
construct a string from a size_t
Definition string.h:1000
IndexT FindStringIndex(const String &s, IndexT startIndex=0) const
return start index of substring, or InvalidIndex if not found
Definition string.cc:336
uint32_t HashCode() const
return a 32-bit hash code for the string
Definition string.h:730
uint32_t AsUInt() const
return contents as unsigned integer
Definition string.cc:1081
void SubstituteChar(char c, char subst)
substitute every occurance of a character with another character
Definition string.h:752
static String Hex(INTEGER i)
construct a hex string from an int
Definition string.h:1157
void AppendPath(const String &path)
append a directory/file to the path (adds separator if necessary)
Definition string.h:1269
void SetUByte(ubyte val)
set as ubyte value
Definition string.cc:1474
String ExtractRange(IndexT fromIndex, SizeT numChars) const
extract substring
Definition string.cc:294
void SetUShort(ushort val)
set as ushort value
Definition string.cc:1492
static String FromFloat4(const Math::float4 &v)
construct a string from float2
Definition string.h:1111
Math::vec3 AsVec3() const
return contents as vec3
Definition string.cc:1770
friend bool operator>=(const String &a, const String &b)
greater-then operator
Definition string.cc:922
bool CheckValidCharSet(const String &charSet) const
return true if string only contains characters from charSet argument
Definition string.h:856
bool IsValid() const
generic valid checker
uint64_t AsUInt64() const
return contents as unsigned uint64_t
Definition string.cc:1093
bool empty() const
Definition string.h:416
SizeT strLen
Definition string.h:462
IndexT FindCharIndexReverse(char c, IndexT startIndex=0) const
return index of character in string, or InvalidIndex if not found
Definition string.cc:380
void Reserve(SizeT newSize)
reserve internal buffer size to prevent heap allocs
Definition string.cc:1453
bool ContainsCharFromSet(const String &charSet) const
returns true if string contains any character from set
Definition string.cc:991
void SetFloat3(const Math::float3 &v)
set as vec3 value
Definition string.cc:1648
static bool IsAlNum(char c)
test if provided character is an alpha-numeric character (A..Z,a..z,0..9)
Definition string.cc:1154
bool IsValidVec2() const
return true if the content is a valid vec2
Definition string.cc:1707
#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 quad tree designed to return regions of free 2D space.
Definition Random.cs:4
auto Format
Definition string.h:1313
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
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