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 String ExtractFileName() const;
397 String ExtractDirName() const;
401 String StripSubpath(const String& subpath) const;
403 void ReplaceIllegalFilenameChars(char replacement);
405 void AppendPath(const String& path);
407 static String AppendPath(const String& base, const String& path);
408
410 inline const char* c_str() const { return this->AsCharPtr(); }
412 inline size_t length() const { return this->Length(); }
414 inline bool empty() const { return this->IsEmpty(); }
416 inline const char* data() const { return this->AsCharPtr(); }
417
419 static bool IsDigit(char c);
421 static bool IsAlpha(char c);
423 static bool IsAlNum(char c);
425 static bool IsLower(char c);
427 static bool IsUpper(char c);
428
430 static int StrCmp(const char* str0, const char* str1);
432 static int StrLen(const char* str);
434 static const char* StrChr(const char* str, int c);
435
438
439private:
441 void Delete();
443 char* GetLastSlash() const;
445 void Alloc(SizeT size);
447 void Realloc(SizeT newSize);
448
449 enum
450 {
452 };
457};
458
459//------------------------------------------------------------------------------
462inline
464 heapBuffer(nullptr),
465 strLen(0),
467{
468 this->localBuffer[0] = 0;
469}
470
471//------------------------------------------------------------------------------
474inline void
476{
477 if (this->heapBuffer)
478 {
480 this->heapBuffer = nullptr;
481 }
482 this->localBuffer[0] = 0;
483 this->strLen = 0;
484 this->heapBufferSize = 0;
485}
486
487//------------------------------------------------------------------------------
490inline
492{
493 this->Delete();
494}
495
496//------------------------------------------------------------------------------
499inline
500String::String(const char* str) :
501 heapBuffer(0),
502 strLen(0),
504{
505 this->localBuffer[0] = 0;
506 this->SetCharPtr(str);
507}
508
509//------------------------------------------------------------------------------
512inline
513String::String(const char* str, size_t len) :
514 heapBuffer(0),
515 strLen(0),
517{
518 this->localBuffer[0] = 0;
519 this->Set(str, (SizeT)len);
520}
521
522
523//------------------------------------------------------------------------------
526inline
528 heapBuffer(0),
529 strLen(0),
531{
532 this->localBuffer[0] = 0;
533 this->SetCharPtr(rhs.AsCharPtr());
534}
535
536//------------------------------------------------------------------------------
539inline
540String::String(String&& rhs) noexcept:
541 heapBuffer(rhs.heapBuffer),
542 strLen(rhs.strLen),
543 heapBufferSize(rhs.heapBufferSize)
544{
545 if (rhs.heapBuffer)
546 {
547 rhs.heapBuffer = nullptr;
548 rhs.strLen = 0;
549 rhs.heapBufferSize = 0;
550 this->localBuffer[0] = 0;
551 }
552 else
553 {
554 if (this->strLen > 0)
555 {
556 Memory::Copy(rhs.localBuffer, this->localBuffer, this->strLen);
557 }
558 this->localBuffer[this->strLen] = 0;
559 rhs.heapBuffer = nullptr;
560 rhs.strLen = 0;
561 rhs.heapBufferSize = 0;
562
563 }
564}
565
566//------------------------------------------------------------------------------
569inline const char*
571{
572 if (this->heapBuffer)
573 {
574 return this->heapBuffer;
575 }
576 else
577 {
578 return this->localBuffer;
579 }
580}
581
582//------------------------------------------------------------------------------
585inline const char*
587{
588 return this->AsCharPtr();
589}
590
591//------------------------------------------------------------------------------
594inline void
596{
597 if (&rhs != this)
598 {
599 this->SetCharPtr(rhs.AsCharPtr());
600 }
601}
602
603//------------------------------------------------------------------------------
606inline void
608{
609 if (&rhs != this)
610 {
611 this->Delete();
612 this->strLen = rhs.strLen;
613 rhs.strLen = 0;
614 if (rhs.heapBuffer)
615 {
616 this->heapBuffer = rhs.heapBuffer;
617 this->heapBufferSize = rhs.heapBufferSize;
618 rhs.heapBuffer = nullptr;
619 rhs.heapBufferSize = 0;
620 }
621 else
622 {
623 if (this->strLen > 0)
624 {
625 Memory::Copy(rhs.localBuffer, this->localBuffer, this->strLen);
626 }
627 this->localBuffer[this->strLen] = 0;
628 }
629 }
630}
631
632//------------------------------------------------------------------------------
635inline void
636String::operator=(const char* cStr)
637{
638 this->SetCharPtr(cStr);
639}
640
641//------------------------------------------------------------------------------
644inline void
646{
647 this->AppendRange(str.AsCharPtr(), str.strLen);
648}
649
650//------------------------------------------------------------------------------
653inline void
655{
656 this->Append(rhs);
657}
658
659//------------------------------------------------------------------------------
662inline char
664{
665 n_assert(i <= this->strLen);
666 return this->AsCharPtr()[i];
667}
668
669//------------------------------------------------------------------------------
674inline char&
676{
677 n_assert(i <= this->strLen);
678 return (char&)(this->AsCharPtr())[i];
679}
680
681//------------------------------------------------------------------------------
684inline SizeT
686{
687 return this->strLen;
688}
689
690//------------------------------------------------------------------------------
693inline void
695{
696 this->Delete();
697}
698
699//------------------------------------------------------------------------------
702inline bool
704{
705 return (0 == this->strLen);
706}
707
708//------------------------------------------------------------------------------
711inline bool
713{
714 return (0 != this->strLen);
715}
716
717//------------------------------------------------------------------------------
722inline uint32_t
724{
725 const char* ptr = this->AsCharPtr();
726 return Hash(ptr, this->strLen);
727}
728
729//------------------------------------------------------------------------------
732static inline String
733operator+(const String& s0, const String& s1)
734{
735 String newString = s0;
736 newString.Append(s1);
737 return newString;
738}
739
740//------------------------------------------------------------------------------
744inline void
745String::SubstituteChar(char c, char subst)
746{
747 char* ptr = const_cast<char*>(this->AsCharPtr());
748 IndexT i;
749 for (i = 0; i <= this->strLen; i++)
750 {
751 if (ptr[i] == c)
752 {
753 ptr[i] = subst;
754 }
755 }
756}
757
758//------------------------------------------------------------------------------
762inline void
764{
765 this->SubstituteChar('\\', '/');
766}
767
768//------------------------------------------------------------------------------
771inline bool
773{
774 return (this->GetFileExtension() == ext);
775}
776
777//------------------------------------------------------------------------------
782inline String
784{
785 String pathString;
786 const char* lastSlash = this->GetLastSlash();
787 if (lastSlash)
788 {
789 pathString = &(lastSlash[1]);
790 }
791 else
792 {
793 pathString = *this;
794 }
795 return pathString;
796}
797
798//------------------------------------------------------------------------------
804inline String
806{
807 String pathString(*this);
808 char* lastSlash = pathString.GetLastSlash();
809 if (lastSlash)
810 {
811 lastSlash[1] = 0;
812 }
813 else
814 {
815 pathString = "";
816 }
817 return pathString;
818}
819
820//------------------------------------------------------------------------------
823inline String
824String::StripSubpath(const String& subpath) const
825{
826 String copy = *this;
827 copy.ConvertBackslashes();
828 IndexT it = 0;
829 while (it < copy.strLen && it < subpath.strLen)
830 {
831 if (subpath[it] != copy[it])
832 break;
833 it++;
834 }
835 while (copy[it] == '/')
836 it++;
837 return copy.ExtractToEnd(it);
838}
839
840//------------------------------------------------------------------------------
845inline bool
847{
848 IndexT i;
849 for (i = 0; i < this->strLen; i++)
850 {
851 if (InvalidIndex == charSet.FindCharIndex((*this)[i], 0))
852 {
853 return false;
854 }
855 }
856 return true;
857}
858
859//------------------------------------------------------------------------------
862inline bool
864{
865 return this->CheckValidCharSet(" \t-+01234567890");
866}
867
868//------------------------------------------------------------------------------
872inline bool
874{
875 return this->CheckValidCharSet(" \t-+.e1234567890");
876}
877
878//------------------------------------------------------------------------------
881inline void
883{
884 this->ReplaceChars("\\/:*?\"<>|", replacement);
885}
886
887//------------------------------------------------------------------------------
890inline String
892{
893 String str;
894 str.SetByte(i);
895 return str;
896}
897
898//------------------------------------------------------------------------------
901inline String
903{
904 String str;
905 str.SetUByte(i);
906 return str;
907}
908
909//------------------------------------------------------------------------------
912inline String
914{
915 String str;
916 str.SetShort(i);
917 return str;
918}
919
920//------------------------------------------------------------------------------
923inline String
925{
926 String str;
927 str.SetUShort(i);
928 return str;
929}
930
931//------------------------------------------------------------------------------
934inline String
936{
937 String str;
938 str.SetInt(i);
939 return str;
940}
941
942//------------------------------------------------------------------------------
945inline String
947{
948 String str;
949 str.SetUInt(i);
950 return str;
951}
952
953//------------------------------------------------------------------------------
956inline String
958{
959 String str;
960 str.SetInt64(i);
961 return str;
962}
963
964//------------------------------------------------------------------------------
967inline String
969{
970 String str;
971 str.SetUInt64(i);
972 return str;
973}
974
975//------------------------------------------------------------------------------
978inline String
980{
981 String str;
982 str.SetLong(i);
983 return str;
984}
985
986//------------------------------------------------------------------------------
989inline String
991{
992 String str;
993 str.SetSizeT(i);
994 return str;
995}
996
997//------------------------------------------------------------------------------
1000inline Util::String
1002{
1003 String str;
1004 str.SetLongLong(i);
1005 return str;
1006}
1007
1008//------------------------------------------------------------------------------
1011inline String
1013{
1014 String str;
1015 str.SetFloat(f);
1016 return str;
1017}
1018
1019//------------------------------------------------------------------------------
1022inline String
1024{
1025 String str;
1026 str.SetDouble(i);
1027 return str;
1028}
1029
1030//------------------------------------------------------------------------------
1033inline String
1035{
1036 String str;
1037 str.SetBool(b);
1038 return str;
1039}
1040
1041#if !__OSX__
1042//------------------------------------------------------------------------------
1045inline String
1047{
1048 String str;
1049 str.SetVec2(v);
1050 return str;
1051}
1052
1053//------------------------------------------------------------------------------
1056inline String
1058{
1059 String str;
1060 str.SetVec3(v);
1061 return str;
1062}
1063
1064//------------------------------------------------------------------------------
1067inline String
1069{
1070 String str;
1071 str.SetVec4(v);
1072 return str;
1073}
1074
1075//------------------------------------------------------------------------------
1078inline String
1080{
1081 String str;
1082 str.SetFloat2(v);
1083 return str;
1084}
1085
1086//------------------------------------------------------------------------------
1089inline String
1091{
1092 String str;
1093 str.SetFloat3(v);
1094 return str;
1095}
1096
1097//------------------------------------------------------------------------------
1100inline String
1102{
1103 String str;
1104 str.SetFloat4(v);
1105 return str;
1106}
1107
1108//------------------------------------------------------------------------------
1111inline String
1113{
1114 String str;
1115 str.SetQuaternion(q);
1116 return str;
1117}
1118
1119//------------------------------------------------------------------------------
1122inline String
1124{
1125 String str;
1126 str.SetMat4(m);
1127 return str;
1128}
1129
1130//------------------------------------------------------------------------------
1133inline String
1135{
1136 String str;
1137 str.SetTransform44(t);
1138 return str;
1139}
1140#endif
1141
1142//------------------------------------------------------------------------------
1145template<typename INTEGER>
1146inline String
1147String::Hex(INTEGER i)
1148{
1149 constexpr SizeT hexLength = sizeof(INTEGER) << 1;
1150 static Util::String digits = "0123456789ABCDEF";
1151
1152 String str("0x");
1153 str.Reserve(hexLength + 2);
1154
1155 for (SizeT n = 0, j = (hexLength - 1) * 4; n < hexLength; ++n, j -= 4)
1156 {
1157 str.AppendChar(digits[(i >> j) & 0x0f]);
1158 }
1159
1160 return str;
1161}
1162
1163//------------------------------------------------------------------------------
1166inline void
1168{
1169 this->AppendRange(&val, 1);
1170}
1171
1172//------------------------------------------------------------------------------
1175inline void
1177{
1178 this->Append(FromInt(val));
1179}
1180
1181//------------------------------------------------------------------------------
1184inline void
1186{
1187 this->Append(FromByte(val));
1188}
1189
1190//------------------------------------------------------------------------------
1193inline void
1195{
1196 this->Append(FromUByte(val));
1197}
1198
1199//------------------------------------------------------------------------------
1202inline void
1204{
1205 this->Append(FromFloat(val));
1206}
1207
1208//------------------------------------------------------------------------------
1211inline void
1213{
1214 this->Append(FromBool(val));
1215}
1216
1217#if !__OSX__
1218//------------------------------------------------------------------------------
1221inline void
1223{
1224 this->Append(FromVec2(val));
1225}
1226
1227//------------------------------------------------------------------------------
1230inline void
1232{
1233 this->Append(FromVec3(val));
1234}
1235
1236//------------------------------------------------------------------------------
1239inline void
1241{
1242 this->Append(FromVec4(val));
1243}
1244
1245//------------------------------------------------------------------------------
1248inline void
1250{
1251 this->Append(FromMat4(val));
1252}
1253#endif
1254
1255//------------------------------------------------------------------------------
1258inline void
1260{
1261 if (!this->IsEmpty() && this->FindCharIndexReverse('/') != (this->strLen - 1))
1262 {
1263 this->AppendChar('/');
1264 }
1265 this->Append(path);
1266}
1267
1268//------------------------------------------------------------------------------
1271inline String
1272String::AppendPath(const String& base, const String& path)
1273{
1274 String result = base;
1275 if (!result.IsEmpty() && result.FindCharIndexReverse('/') != (result.strLen - 1))
1276 {
1277 result.AppendChar('/');
1278 }
1279 result.Append(path);
1280 return result;
1281}
1282
1283//------------------------------------------------------------------------------
1286constexpr uint
1287String::Hash(const char* c, std::size_t s)
1288{
1289 uint hash = 0;
1290 std::size_t i;
1291 for (i = 0; i < s; i++)
1292 {
1293 hash += c[i];
1294 hash += hash << 10;
1295 hash ^= hash >> 6;
1296 }
1297 hash += hash << 3;
1298 hash ^= hash >> 11;
1299 hash += hash << 15;
1300 return hash;
1301}
1302
1304
1305} // namespace Util
1306
1307
1308//------------------------------------------------------------------------------
1312Util::String operator ""_str(const char* c, std::size_t s);
1313
1314//------------------------------------------------------------------------------
1318constexpr uint
1319operator ""_hash(const char* c, std::size_t s)
1320{
1321 return Util::String::Hash(c, s);
1322}
1323
1324//------------------------------------------------------------------------------
1325
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:35
#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 String.cs:6
auto Format
Definition string.h:1303
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:1453
static String FromBase64(const String &)
create from base64
Definition string.cc:1344
static String FromFloat(float f)
construct a string from a float
Definition string.h:1012
void Clear()
clear the string
Definition string.h:694
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:913
void TrimRight(const String &charSet)
delete characters from charset at right side of string
Definition string.cc:468
Util::Blob AsBlob() const
return contents as blob
Definition string.cc:1274
static String FromVec3(const Math::vec3 &v)
construct a string from vec3
Definition string.h:1057
~String()
destructor
Definition string.h:491
static String FromInt64(int64_t i)
construct a string from a int64
Definition string.h:957
void SetFloat3(const Math::float3 &v)
set as vec3 value
Definition string.cc:1618
static const char * StrChr(const char *str, int c)
find character in string
Definition string.cc:1201
static String FromVec4(const Math::vec4 &v)
construct a string from vec4
Definition string.h:1068
IndexT FindCharIndexReverse(char c, IndexT startIndex=0) const
return index of character in string, or InvalidIndex if not found
Definition string.cc:380
void SetSizeT(size_t val)
set as long value
Definition string.cc:1516
static String FromVec2(const Math::vec2 &v)
construct a string from vec2
Definition string.h:1046
static String FromUInt(uint i)
construct a string from a uint
Definition string.h:946
void ChangeFileExtension(const Util::String &newExt)
change file extension
Definition string.cc:1228
void AppendChar(char val)
append character
Definition string.h:1167
static String Concatenate(const Array< String > &strArray, const String &whiteSpace)
concatenate array of strings into new string
Definition string.cc:760
void Trim(const String &charSet)
trim characters from charset at both sides of string
Definition string.cc:511
static Dictionary< String, String > ParseKeyValuePairs(const String &str)
parse key/value pair string ("key0=value0 key1=value1")
Definition string.cc:1211
friend bool operator!=(const String &a, const String &b)
inequality operator
Definition string.cc:886
void SetBool(bool val)
set as bool value
Definition string.cc:1552
void Alloc(SizeT size)
allocate the string buffer (discards old content)
Definition string.cc:1367
static bool IsAlNum(char c)
test if provided character is an alpha-numeric character (A..Z,a..z,0..9)
Definition string.cc:1154
void SetUShort(ushort val)
set as ushort value
Definition string.cc:1462
void SetLongLong(long long val)
set as long long value
Definition string.cc:1525
const char * Get() const
*** OBSOLETE *** only Nebula2 compatibility
Definition string.h:586
static String FromLongLong(long long i)
construct a string from a long long
Definition string.h:1001
bool AsBool() const
return contents as bool
Definition string.cc:1114
void SetInt64(int64_t val)
set as int64 value
Definition string.cc:1489
void ReplaceIllegalFilenameChars(char replacement)
replace illegal filename characters
Definition string.h:882
void SubstituteString(const String &str, const String &substStr)
substitute every occurance of a string with another string
Definition string.cc:522
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:913
static String FromSize(size_t i)
construct a string from a size_t
Definition string.h:990
void Realloc(SizeT newSize)
(re-)allocate the string buffer (copies old content)
Definition string.cc:1390
void AppendVec4(const Math::vec4 &v)
append vec4 value
Definition string.h:1240
static int StrCmp(const char *str0, const char *str1)
lowlevel string compare wrapper function
Definition string.cc:1181
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:1020
static String FromBlob(const Util::Blob &b)
create from blob
Definition string.cc:1248
friend bool operator==(const String &a, const String &b)
equality operator
Definition string.cc:848
void SetInt(int val)
set as int value
Definition string.cc:1471
void CamelCaseToWords()
insert spaces before each capital letter in the string.
Definition string.cc:969
Math::vec2 AsVec2() const
return contents as vec2
Definition string.cc:1727
String StripSubpath(const String &subpath) const
strip subpath
Definition string.h:824
static bool IsUpper(char c)
test if provided character is an upper-case character
Definition string.cc:1172
void Reserve(SizeT newSize)
reserve internal buffer size to prevent heap allocs
Definition string.cc:1423
String GetFileExtension() const
get filename extension without dot
Definition string.cc:1003
String ExtractRange(IndexT fromIndex, SizeT numChars) const
extract substring
Definition string.cc:294
void Delete()
delete contents
Definition string.h:475
void SetVec3(const Math::vec3 &v)
set as vec3 value
Definition string.cc:1591
void StripAssignPrefix()
remove assign prefix (for example tex:)
Definition string.cc:834
void SetLong(long val)
set as long value
Definition string.cc:1507
int heapBufferSize
Definition String.cs:12
void Capitalize()
convert first char of string to upper case
Definition string.cc:959
Math::float4 AsFloat4() const
return contents as vec4
Definition string.cc:1795
const char * AsCharPtr() const
return contents as character pointer
Definition string.h:570
static bool MatchPattern(const String &str, const String &pattern)
pattern matching
Definition string.cc:625
Math::mat4 AsMat4() const
return contents as mat4
Definition string.cc:723
static bool IsAlpha(char c)
test if provided character is an alphabet character (A..Z, a..z)
Definition string.cc:1145
static bool IsLower(char c)
test if provided character is a lower case character
Definition string.cc:1163
int AsInt() const
return contents as integer
Definition string.cc:1057
bool IsValidTransform44() const
return true if content is a valid transform44
Definition string.cc:1713
void SubstituteChar(char c, char subst)
substitute every occurance of a character with another character
Definition string.h:745
void TrimLeft(const String &charSet)
delete characters from charset at left side of string
Definition string.cc:426
void SetVec4(const Math::vec4 &v)
set as vec4 value
Definition string.cc:1600
static String From(const T &t)
convert from "anything"
char localBuffer[LocalStringSize]
Definition string.h:454
void Append(const T &t)
generic append
void AppendBool(bool val)
append bool value
Definition string.h:1212
static String FromQuat(const Math::quat &q)
construct a string from quat
Definition string.h:1112
int strLen
Definition String.cs:11
static String FromLong(long i)
construct a string from a long
Definition string.h:979
void ReplaceChars(const String &charSet, char replacement)
replace any char set character within a string with the replacement character
Definition string.cc:700
friend bool operator<(const String &a, const String &b)
less-then operator
Definition string.cc:895
bool IsValidVec2() const
return true if the content is a valid vec2
Definition string.cc:1677
void AppendUByte(ubyte val)
append unsigned byte value
Definition string.h:1194
void operator+=(const String &rhs)
+= operator
Definition string.h:654
void ConvertBackslashes()
convert backslashes to slashes
Definition string.h:763
void SetUByte(ubyte val)
set as ubyte value
Definition string.cc:1444
static String FromInt(int i)
construct a string from an int
Definition string.h:935
bool ContainsCharFromSet(const String &charSet) const
returns true if string contains any character from set
Definition string.cc:991
static String FromUShort(ushort i)
construct a string from a ushort
Definition string.h:924
bool IsValidVec4() const
return true if the content is a valid vec4
Definition string.cc:1689
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:1582
bool IsValidBool() const
return true if the content is a valid bool
Definition string.cc:1033
Math::float2 AsFloat2() const
return contents as vec2
Definition string.cc:1769
bool IsValidInt() const
return true if the content is a valid integer
Definition string.h:863
String ExtractDirName() const
extract the part before the last directory separator
Definition string.cc:598
uint32_t HashCode() const
return a 32-bit hash code for the string
Definition string.h:723
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:1627
String ExtractFileName() const
extract the part after the last directory separator
Definition string.h:783
static String FromFloat2(const Math::float2 &v)
construct a string from float2
Definition string.h:1079
uint64_t AsUInt64() const
return contents as unsigned uint64_t
Definition string.cc:1093
bool IsValid() const
return true if string object is not empty
Definition string.h:712
static String FromDouble(double f)
construct a string from a double
Definition string.h:1023
void SetFloat(float val)
set as float value
Definition string.cc:1534
static String FromByte(byte i)
construct a string from a byte
Definition string.h:891
static int StrLen(const char *str)
lowlevel string length function
Definition string.cc:1191
size_t length() const
Definition string.h:412
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:595
void ToLower()
convert string to lower case
Definition string.cc:931
void SetDouble(double val)
set as double value
Definition string.cc:1543
void Append(const String &str)
append string
Definition string.h:645
void SetUInt(uint val)
set as uint value
Definition string.cc:1480
static String FromFloat4(const Math::float4 &v)
construct a string from float2
Definition string.h:1101
@ LocalStringSize
Definition string.h:451
bool IsValidMat4() const
return true if content is a valid mat4
Definition string.cc:1701
static String FromBool(bool b)
construct a string from a bool
Definition string.h:1034
char operator[](IndexT i) const
read-only index operator
Definition string.h:663
bool CheckFileExtension(const String &ext) const
check file extension
Definition string.h:772
int64_t AsInt64() const
return contents as int64_t
Definition string.cc:1069
void SetQuaternion(const Math::quat &v)
set as quaternion
Definition string.cc:1636
void SetByte(byte val)
set as byte value
Definition string.cc:1435
static String FromUInt64(uint64_t i)
construct a string from a uint64
Definition string.h:968
bool IsValid() const
generic valid checker
friend bool operator>(const String &a, const String &b)
greater-then operator
Definition string.cc:904
void SetFloat2(const Math::float2 &v)
set as vec2 value
Definition string.cc:1609
float AsFloat() const
return contents as float
Definition string.cc:1105
static String FromTransform44(const Math::transform44 &m)
construct a string from transform44
Definition string.h:1134
bool IsValidFloat() const
return true if the content is a valid float
Definition string.h:873
SizeT Length() const
return length of string
Definition string.h:685
const char * c_str() const
helpers to interface with libraries that expect std::string like apis
Definition string.h:410
void TerminateAtIndex(IndexT index)
terminate string at given index
Definition string.cc:806
T As() const
convert to "anything"
void AppendByte(byte val)
append byte value
Definition string.h:1185
static bool IsDigit(char c)
test if provided character is a digit (0..9)
Definition string.cc:1136
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:1740
Math::transform44 AsTransform44() const
return contents as transform44
Definition string.cc:740
String()
constructor
Definition string.h:463
void ChangeAssignPrefix(const Util::String &newPref)
change assign prefix
Definition string.cc:1238
void Fill(SizeT length, unsigned char character)
set string length and fill all characters with arg
Definition string.cc:1568
bool CheckValidCharSet(const String &charSet) const
return true if string only contains characters from charSet argument
Definition string.h:846
String ExtractLastDirName() const
extract the last directory of the path
Definition string.cc:558
Util::String AsBase64() const
return contents as base64 string
Definition string.cc:1327
const char * data() const
Definition string.h:416
void SetMat4(const Math::mat4 &v)
set as mat4 value
Definition string.cc:1645
bool empty() const
Definition string.h:414
bool BeginsWithString(const String &s) const
returns true if string begins with string
Definition string.cc:398
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:1782
static String FromFloat3(const Math::float3 &v)
construct a string from float2
Definition string.h:1090
char * heapBuffer
Definition string.h:453
void AppendMat4(const Math::mat4 &v)
append mat4 value
Definition string.h:1249
static constexpr uint Hash(const char *c, std::size_t s)
Hash a string.
Definition string.h:1287
static String FromUByte(ubyte i)
construct a string from a ubyte
Definition string.h:902
void SetCharPtr(const char *s)
set content to char ptr
Definition string.cc:781
static String Hex(INTEGER i)
construct a hex string from an int
Definition string.h:1147
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:1222
bool EndsWithString(const String &s) const
returns true if string ends with string
Definition string.cc:411
bool IsEmpty() const
return true if string object is empty
Definition string.h:703
friend bool operator>=(const String &a, const String &b)
greater-then operator
Definition string.cc:922
void AppendFloat(float val)
append float value
Definition string.h:1203
void SetUInt64(uint64_t val)
set as uint64 value
Definition string.cc:1498
String ExtractToLastSlash() const
extract path until last slash
Definition string.h:805
void StripFileExtension()
remove file extension
Definition string.cc:819
Math::vec4 AsVec4() const
return contents as vec4
Definition string.cc:1756
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:1231
uint32_t AsUInt() const
return contents as unsigned integer
Definition string.cc:1081
static String FromMat4(const Math::mat4 &m)
construct a string from mat4
Definition string.h:1123
void AppendInt(int val)
append int value
Definition string.h:1176
void ToUpper()
convert string to upper case
Definition string.cc:945
void SetTransform44(const Math::transform44 &v)
set as transform44 value
Definition string.cc:1661
void AppendPath(const String &path)
append a directory/file to the path (adds separator if necessary)
Definition string.h:1259
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