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 this->localBuffer[0] = 0;
549 }
550 else
551 {
552 if (this->strLen > 0)
553 {
554 Memory::Copy(rhs.localBuffer, this->localBuffer, this->strLen);
555 }
556 this->localBuffer[this->strLen] = 0;
557 }
558}
559
560//------------------------------------------------------------------------------
563inline const char*
565{
566 if (this->heapBuffer)
567 {
568 return this->heapBuffer;
569 }
570 else
571 {
572 return this->localBuffer;
573 }
574}
575
576//------------------------------------------------------------------------------
579inline const char*
581{
582 return this->AsCharPtr();
583}
584
585//------------------------------------------------------------------------------
588inline void
590{
591 if (&rhs != this)
592 {
593 this->SetCharPtr(rhs.AsCharPtr());
594 }
595}
596
597//------------------------------------------------------------------------------
600inline void
602{
603 if (&rhs != this)
604 {
605 this->Delete();
606 this->strLen = rhs.strLen;
607 rhs.strLen = 0;
608 if (rhs.heapBuffer)
609 {
610 this->heapBuffer = rhs.heapBuffer;
611 this->heapBufferSize = rhs.heapBufferSize;
612 rhs.heapBuffer = nullptr;
613 rhs.heapBufferSize = 0;
614 }
615 else
616 {
617 if (this->strLen > 0)
618 {
619 Memory::Copy(rhs.localBuffer, this->localBuffer, this->strLen);
620 }
621 this->localBuffer[this->strLen] = 0;
622 }
623 }
624}
625
626//------------------------------------------------------------------------------
629inline void
630String::operator=(const char* cStr)
631{
632 this->SetCharPtr(cStr);
633}
634
635//------------------------------------------------------------------------------
638inline void
640{
641 this->AppendRange(str.AsCharPtr(), str.strLen);
642}
643
644//------------------------------------------------------------------------------
647inline void
649{
650 this->Append(rhs);
651}
652
653//------------------------------------------------------------------------------
656inline char
658{
659 n_assert(i <= this->strLen);
660 return this->AsCharPtr()[i];
661}
662
663//------------------------------------------------------------------------------
668inline char&
670{
671 n_assert(i <= this->strLen);
672 return (char&)(this->AsCharPtr())[i];
673}
674
675//------------------------------------------------------------------------------
678inline SizeT
680{
681 return this->strLen;
682}
683
684//------------------------------------------------------------------------------
687inline void
689{
690 this->Delete();
691}
692
693//------------------------------------------------------------------------------
696inline bool
698{
699 return (0 == this->strLen);
700}
701
702//------------------------------------------------------------------------------
705inline bool
707{
708 return (0 != this->strLen);
709}
710
711//------------------------------------------------------------------------------
716inline uint32_t
718{
719 const char* ptr = this->AsCharPtr();
720 return Hash(ptr, this->strLen);
721}
722
723//------------------------------------------------------------------------------
726static inline String
727operator+(const String& s0, const String& s1)
728{
729 String newString = s0;
730 newString.Append(s1);
731 return newString;
732}
733
734//------------------------------------------------------------------------------
738inline void
739String::SubstituteChar(char c, char subst)
740{
741 char* ptr = const_cast<char*>(this->AsCharPtr());
742 IndexT i;
743 for (i = 0; i <= this->strLen; i++)
744 {
745 if (ptr[i] == c)
746 {
747 ptr[i] = subst;
748 }
749 }
750}
751
752//------------------------------------------------------------------------------
756inline void
758{
759 this->SubstituteChar('\\', '/');
760}
761
762//------------------------------------------------------------------------------
765inline bool
767{
768 return (this->GetFileExtension() == ext);
769}
770
771//------------------------------------------------------------------------------
776inline String
778{
779 String pathString;
780 const char* lastSlash = this->GetLastSlash();
781 if (lastSlash)
782 {
783 pathString = &(lastSlash[1]);
784 }
785 else
786 {
787 pathString = *this;
788 }
789 return pathString;
790}
791
792//------------------------------------------------------------------------------
798inline String
800{
801 String pathString(*this);
802 char* lastSlash = pathString.GetLastSlash();
803 if (lastSlash)
804 {
805 lastSlash[1] = 0;
806 }
807 else
808 {
809 pathString = "";
810 }
811 return pathString;
812}
813
814//------------------------------------------------------------------------------
817inline String
818String::StripSubpath(const String& subpath) const
819{
820 String copy = *this;
821 copy.ConvertBackslashes();
822 IndexT it = 0;
823 while (it < copy.strLen && it < subpath.strLen)
824 {
825 if (subpath[it] != copy[it])
826 break;
827 it++;
828 }
829 while (copy[it] == '/')
830 it++;
831 return copy.ExtractToEnd(it);
832}
833
834//------------------------------------------------------------------------------
839inline bool
841{
842 IndexT i;
843 for (i = 0; i < this->strLen; i++)
844 {
845 if (InvalidIndex == charSet.FindCharIndex((*this)[i], 0))
846 {
847 return false;
848 }
849 }
850 return true;
851}
852
853//------------------------------------------------------------------------------
856inline bool
858{
859 return this->CheckValidCharSet(" \t-+01234567890");
860}
861
862//------------------------------------------------------------------------------
866inline bool
868{
869 return this->CheckValidCharSet(" \t-+.e1234567890");
870}
871
872//------------------------------------------------------------------------------
875inline void
877{
878 this->ReplaceChars("\\/:*?\"<>|", replacement);
879}
880
881//------------------------------------------------------------------------------
884inline String
886{
887 String str;
888 str.SetByte(i);
889 return str;
890}
891
892//------------------------------------------------------------------------------
895inline String
897{
898 String str;
899 str.SetUByte(i);
900 return str;
901}
902
903//------------------------------------------------------------------------------
906inline String
908{
909 String str;
910 str.SetShort(i);
911 return str;
912}
913
914//------------------------------------------------------------------------------
917inline String
919{
920 String str;
921 str.SetUShort(i);
922 return str;
923}
924
925//------------------------------------------------------------------------------
928inline String
930{
931 String str;
932 str.SetInt(i);
933 return str;
934}
935
936//------------------------------------------------------------------------------
939inline String
941{
942 String str;
943 str.SetUInt(i);
944 return str;
945}
946
947//------------------------------------------------------------------------------
950inline String
952{
953 String str;
954 str.SetInt64(i);
955 return str;
956}
957
958//------------------------------------------------------------------------------
961inline String
963{
964 String str;
965 str.SetUInt64(i);
966 return str;
967}
968
969//------------------------------------------------------------------------------
972inline String
974{
975 String str;
976 str.SetLong(i);
977 return str;
978}
979
980//------------------------------------------------------------------------------
983inline String
985{
986 String str;
987 str.SetSizeT(i);
988 return str;
989}
990
991//------------------------------------------------------------------------------
994inline Util::String
996{
997 String str;
998 str.SetLongLong(i);
999 return str;
1000}
1001
1002//------------------------------------------------------------------------------
1005inline String
1007{
1008 String str;
1009 str.SetFloat(f);
1010 return str;
1011}
1012
1013//------------------------------------------------------------------------------
1016inline String
1018{
1019 String str;
1020 str.SetDouble(i);
1021 return str;
1022}
1023
1024//------------------------------------------------------------------------------
1027inline String
1029{
1030 String str;
1031 str.SetBool(b);
1032 return str;
1033}
1034
1035#if !__OSX__
1036//------------------------------------------------------------------------------
1039inline String
1041{
1042 String str;
1043 str.SetVec2(v);
1044 return str;
1045}
1046
1047//------------------------------------------------------------------------------
1050inline String
1052{
1053 String str;
1054 str.SetVec3(v);
1055 return str;
1056}
1057
1058//------------------------------------------------------------------------------
1061inline String
1063{
1064 String str;
1065 str.SetVec4(v);
1066 return str;
1067}
1068
1069//------------------------------------------------------------------------------
1072inline String
1074{
1075 String str;
1076 str.SetFloat2(v);
1077 return str;
1078}
1079
1080//------------------------------------------------------------------------------
1083inline String
1085{
1086 String str;
1087 str.SetFloat3(v);
1088 return str;
1089}
1090
1091//------------------------------------------------------------------------------
1094inline String
1096{
1097 String str;
1098 str.SetFloat4(v);
1099 return str;
1100}
1101
1102//------------------------------------------------------------------------------
1105inline String
1107{
1108 String str;
1109 str.SetQuaternion(q);
1110 return str;
1111}
1112
1113//------------------------------------------------------------------------------
1116inline String
1118{
1119 String str;
1120 str.SetMat4(m);
1121 return str;
1122}
1123
1124//------------------------------------------------------------------------------
1127inline String
1129{
1130 String str;
1131 str.SetTransform44(t);
1132 return str;
1133}
1134#endif
1135
1136//------------------------------------------------------------------------------
1139template<typename INTEGER>
1140inline String
1141String::Hex(INTEGER i)
1142{
1143 constexpr SizeT hexLength = sizeof(INTEGER) << 1;
1144 static Util::String digits = "0123456789ABCDEF";
1145
1146 String str("0x");
1147 str.Reserve(hexLength + 2);
1148
1149 for (SizeT n = 0, j = (hexLength - 1) * 4; n < hexLength; ++n, j -= 4)
1150 {
1151 str.AppendChar(digits[(i >> j) & 0x0f]);
1152 }
1153
1154 return str;
1155}
1156
1157//------------------------------------------------------------------------------
1160inline void
1162{
1163 this->AppendRange(&val, 1);
1164}
1165
1166//------------------------------------------------------------------------------
1169inline void
1171{
1172 this->Append(FromInt(val));
1173}
1174
1175//------------------------------------------------------------------------------
1178inline void
1180{
1181 this->Append(FromByte(val));
1182}
1183
1184//------------------------------------------------------------------------------
1187inline void
1189{
1190 this->Append(FromUByte(val));
1191}
1192
1193//------------------------------------------------------------------------------
1196inline void
1198{
1199 this->Append(FromFloat(val));
1200}
1201
1202//------------------------------------------------------------------------------
1205inline void
1207{
1208 this->Append(FromBool(val));
1209}
1210
1211#if !__OSX__
1212//------------------------------------------------------------------------------
1215inline void
1217{
1218 this->Append(FromVec2(val));
1219}
1220
1221//------------------------------------------------------------------------------
1224inline void
1226{
1227 this->Append(FromVec3(val));
1228}
1229
1230//------------------------------------------------------------------------------
1233inline void
1235{
1236 this->Append(FromVec4(val));
1237}
1238
1239//------------------------------------------------------------------------------
1242inline void
1244{
1245 this->Append(FromMat4(val));
1246}
1247#endif
1248
1249//------------------------------------------------------------------------------
1252inline void
1254{
1255 if (!this->IsEmpty() && this->FindCharIndexReverse('/') != (this->strLen - 1))
1256 {
1257 this->AppendChar('/');
1258 }
1259 this->Append(path);
1260}
1261
1262//------------------------------------------------------------------------------
1265inline String
1266String::AppendPath(const String& base, const String& path)
1267{
1268 String result = base;
1269 if (!result.IsEmpty() && result.FindCharIndexReverse('/') != (result.strLen - 1))
1270 {
1271 result.AppendChar('/');
1272 }
1273 result.Append(path);
1274 return result;
1275}
1276
1277//------------------------------------------------------------------------------
1280constexpr uint
1281String::Hash(const char* c, std::size_t s)
1282{
1283 uint hash = 0;
1284 std::size_t i;
1285 for (i = 0; i < s; i++)
1286 {
1287 hash += c[i];
1288 hash += hash << 10;
1289 hash ^= hash >> 6;
1290 }
1291 hash += hash << 3;
1292 hash ^= hash >> 11;
1293 hash += hash << 15;
1294 return hash;
1295}
1296
1298
1299} // namespace Util
1300
1301
1302//------------------------------------------------------------------------------
1306Util::String operator ""_str(const char* c, std::size_t s);
1307
1308//------------------------------------------------------------------------------
1312constexpr uint
1313operator ""_hash(const char* c, std::size_t s)
1314{
1315 return Util::String::Hash(c, s);
1316}
1317
1318//------------------------------------------------------------------------------
1319
A 4x4 matrix which is described by translation, rotation and scale.
Definition transform44.h:20
The Util::Blob class encapsulates a chunk of raw memory into a C++ object which can be copied,...
Definition blob.h:22
A collection of key/value pairs with quick value retrieval by key at roughly O(log n).
Definition dictionary.h:34
#define n_assert(exp)
Definition debug.h:50
Different curves.
Definition angularpfeedbackloop.h:17
half operator+(half one, half two)
Definition half.h:105
void Copy(const void *from, void *to, size_t numBytes)
Copy a chunk of memory (note the argument order is different from memcpy()!
Definition osxmemory.cc:213
void Free(HeapType heapType, void *ptr)
Free a block of memory.
Definition osxmemory.cc:136
@ StringDataHeap
Definition osxmemoryconfig.h:31
A quad tree designed to return regions of free 2D space.
Definition String.cs:6
auto Format
Definition string.h:1297
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:1420
static String FromBase64(const String &)
create from base64
Definition string.cc:1315
static String FromFloat(float f)
construct a string from a float
Definition string.h:1006
void Clear()
clear the string
Definition string.h:688
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:907
void TrimRight(const String &charSet)
delete characters from charset at right side of string
Definition string.cc:459
Util::Blob AsBlob() const
return contents as blob
Definition string.cc:1264
static String FromVec3(const Math::vec3 &v)
construct a string from vec3
Definition string.h:1051
~String()
destructor
Definition string.h:491
static String FromInt64(int64_t i)
construct a string from a int64
Definition string.h:951
void SetFloat3(const Math::float3 &v)
set as vec3 value
Definition string.cc:1585
static const char * StrChr(const char *str, int c)
find character in string
Definition string.cc:1192
static String FromVec4(const Math::vec4 &v)
construct a string from vec4
Definition string.h:1062
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:1483
static String FromVec2(const Math::vec2 &v)
construct a string from vec2
Definition string.h:1040
static String FromUInt(uint i)
construct a string from a uint
Definition string.h:940
void ChangeFileExtension(const Util::String &newExt)
change file extension
Definition string.cc:1219
void AppendChar(char val)
append character
Definition string.h:1161
static String Concatenate(const Array< String > &strArray, const String &whiteSpace)
concatenate array of strings into new string
Definition string.cc:751
void Trim(const String &charSet)
trim characters from charset at both sides of string
Definition string.cc:502
static Dictionary< String, String > ParseKeyValuePairs(const String &str)
parse key/value pair string ("key0=value0 key1=value1")
Definition string.cc:1202
friend bool operator!=(const String &a, const String &b)
inequality operator
Definition string.cc:877
void SetBool(bool val)
set as bool value
Definition string.cc:1519
void Alloc(SizeT size)
allocate the string buffer (discards old content)
Definition string.cc:1334
static bool IsAlNum(char c)
test if provided character is an alpha-numeric character (A..Z,a..z,0..9)
Definition string.cc:1145
void SetUShort(ushort val)
set as ushort value
Definition string.cc:1429
void SetLongLong(long long val)
set as long long value
Definition string.cc:1492
const char * Get() const
*** OBSOLETE *** only Nebula2 compatibility
Definition string.h:580
static String FromLongLong(long long i)
construct a string from a long long
Definition string.h:995
bool AsBool() const
return contents as bool
Definition string.cc:1105
void SetInt64(int64_t val)
set as int64 value
Definition string.cc:1456
void ReplaceIllegalFilenameChars(char replacement)
replace illegal filename characters
Definition string.h:876
void SubstituteString(const String &str, const String &substStr)
substitute every occurance of a string with another string
Definition string.cc:513
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:904
static String FromSize(size_t i)
construct a string from a size_t
Definition string.h:984
void Realloc(SizeT newSize)
(re-)allocate the string buffer (copies old content)
Definition string.cc:1357
void AppendVec4(const Math::vec4 &v)
append vec4 value
Definition string.h:1234
static int StrCmp(const char *str0, const char *str1)
lowlevel string compare wrapper function
Definition string.cc:1172
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:1011
static String FromBlob(const Util::Blob &b)
create from blob
Definition string.cc:1239
friend bool operator==(const String &a, const String &b)
equality operator
Definition string.cc:839
void SetInt(int val)
set as int value
Definition string.cc:1438
void CamelCaseToWords()
insert spaces before each capital letter in the string.
Definition string.cc:960
Math::vec2 AsVec2() const
return contents as vec2
Definition string.cc:1694
String StripSubpath(const String &subpath) const
strip subpath
Definition string.h:818
static bool IsUpper(char c)
test if provided character is an upper-case character
Definition string.cc:1163
void Reserve(SizeT newSize)
reserve internal buffer size to prevent heap allocs
Definition string.cc:1390
String GetFileExtension() const
get filename extension without dot
Definition string.cc:994
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:1558
void StripAssignPrefix()
remove assign prefix (for example tex:)
Definition string.cc:825
void SetLong(long val)
set as long value
Definition string.cc:1474
int heapBufferSize
Definition String.cs:12
void Capitalize()
convert first char of string to upper case
Definition string.cc:950
Math::float4 AsFloat4() const
return contents as vec4
Definition string.cc:1762
const char * AsCharPtr() const
return contents as character pointer
Definition string.h:564
static bool MatchPattern(const String &str, const String &pattern)
pattern matching
Definition string.cc:616
Math::mat4 AsMat4() const
return contents as mat4
Definition string.cc:714
static bool IsAlpha(char c)
test if provided character is an alphabet character (A..Z, a..z)
Definition string.cc:1136
static bool IsLower(char c)
test if provided character is a lower case character
Definition string.cc:1154
int AsInt() const
return contents as integer
Definition string.cc:1048
bool IsValidTransform44() const
return true if content is a valid transform44
Definition string.cc:1680
void SubstituteChar(char c, char subst)
substitute every occurance of a character with another character
Definition string.h:739
void TrimLeft(const String &charSet)
delete characters from charset at left side of string
Definition string.cc:417
void SetVec4(const Math::vec4 &v)
set as vec4 value
Definition string.cc:1567
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:1206
static String FromQuat(const Math::quat &q)
construct a string from quat
Definition string.h:1106
int strLen
Definition String.cs:11
static String FromLong(long i)
construct a string from a long
Definition string.h:973
void ReplaceChars(const String &charSet, char replacement)
replace any char set character within a string with the replacement character
Definition string.cc:691
friend bool operator<(const String &a, const String &b)
less-then operator
Definition string.cc:886
bool IsValidVec2() const
return true if the content is a valid vec2
Definition string.cc:1644
void AppendUByte(ubyte val)
append unsigned byte value
Definition string.h:1188
void operator+=(const String &rhs)
+= operator
Definition string.h:648
void ConvertBackslashes()
convert backslashes to slashes
Definition string.h:757
void SetUByte(ubyte val)
set as ubyte value
Definition string.cc:1411
static String FromInt(int i)
construct a string from an int
Definition string.h:929
bool ContainsCharFromSet(const String &charSet) const
returns true if string contains any character from set
Definition string.cc:982
static String FromUShort(ushort i)
construct a string from a ushort
Definition string.h:918
bool IsValidVec4() const
return true if the content is a valid vec4
Definition string.cc:1656
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:1549
bool IsValidBool() const
return true if the content is a valid bool
Definition string.cc:1024
Math::float2 AsFloat2() const
return contents as vec2
Definition string.cc:1736
bool IsValidInt() const
return true if the content is a valid integer
Definition string.h:857
String ExtractDirName() const
extract the part before the last directory separator
Definition string.cc:589
uint32_t HashCode() const
return a 32-bit hash code for the string
Definition string.h:717
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:1594
String ExtractFileName() const
extract the part after the last directory separator
Definition string.h:777
static String FromFloat2(const Math::float2 &v)
construct a string from float2
Definition string.h:1073
uint64_t AsUInt64() const
return contents as unsigned uint64_t
Definition string.cc:1084
bool IsValid() const
return true if string object is not empty
Definition string.h:706
static String FromDouble(double f)
construct a string from a double
Definition string.h:1017
void SetFloat(float val)
set as float value
Definition string.cc:1501
static String FromByte(byte i)
construct a string from a byte
Definition string.h:885
static int StrLen(const char *str)
lowlevel string length function
Definition string.cc:1182
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:589
void ToLower()
convert string to lower case
Definition string.cc:922
void SetDouble(double val)
set as double value
Definition string.cc:1510
void Append(const String &str)
append string
Definition string.h:639
void SetUInt(uint val)
set as uint value
Definition string.cc:1447
static String FromFloat4(const Math::float4 &v)
construct a string from float2
Definition string.h:1095
@ LocalStringSize
Definition string.h:451
bool IsValidMat4() const
return true if content is a valid mat4
Definition string.cc:1668
static String FromBool(bool b)
construct a string from a bool
Definition string.h:1028
char operator[](IndexT i) const
read-only index operator
Definition string.h:657
bool CheckFileExtension(const String &ext) const
check file extension
Definition string.h:766
int64_t AsInt64() const
return contents as int64_t
Definition string.cc:1060
void SetQuaternion(const Math::quat &v)
set as quaternion
Definition string.cc:1603
void SetByte(byte val)
set as byte value
Definition string.cc:1402
static String FromUInt64(uint64_t i)
construct a string from a uint64
Definition string.h:962
bool IsValid() const
generic valid checker
friend bool operator>(const String &a, const String &b)
greater-then operator
Definition string.cc:895
void SetFloat2(const Math::float2 &v)
set as vec2 value
Definition string.cc:1576
float AsFloat() const
return contents as float
Definition string.cc:1096
static String FromTransform44(const Math::transform44 &m)
construct a string from transform44
Definition string.h:1128
bool IsValidFloat() const
return true if the content is a valid float
Definition string.h:867
SizeT Length() const
return length of string
Definition string.h:679
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:797
T As() const
convert to "anything"
void AppendByte(byte val)
append byte value
Definition string.h:1179
static bool IsDigit(char c)
test if provided character is a digit (0..9)
Definition string.cc:1127
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:1707
Math::transform44 AsTransform44() const
return contents as transform44
Definition string.cc:731
String()
constructor
Definition string.h:463
void ChangeAssignPrefix(const Util::String &newPref)
change assign prefix
Definition string.cc:1229
void Fill(SizeT length, unsigned char character)
set string length and fill all characters with arg
Definition string.cc:1535
bool CheckValidCharSet(const String &charSet) const
return true if string only contains characters from charSet argument
Definition string.h:840
String ExtractLastDirName() const
extract the last directory of the path
Definition string.cc:549
Util::String AsBase64() const
return contents as base64 string
Definition string.cc:1298
const char * data() const
Definition string.h:416
void SetMat4(const Math::mat4 &v)
set as mat4 value
Definition string.cc:1612
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:1749
static String FromFloat3(const Math::float3 &v)
construct a string from float2
Definition string.h:1084
char * heapBuffer
Definition string.h:453
void AppendMat4(const Math::mat4 &v)
append mat4 value
Definition string.h:1243
static constexpr uint Hash(const char *c, std::size_t s)
Hash a string.
Definition string.h:1281
static String FromUByte(ubyte i)
construct a string from a ubyte
Definition string.h:896
void SetCharPtr(const char *s)
set content to char ptr
Definition string.cc:772
static String Hex(INTEGER i)
construct a hex string from an int
Definition string.h:1141
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:1216
bool EndsWithString(const String &s) const
returns true if string ends with string
Definition string.cc:407
bool IsEmpty() const
return true if string object is empty
Definition string.h:697
friend bool operator>=(const String &a, const String &b)
greater-then operator
Definition string.cc:913
void AppendFloat(float val)
append float value
Definition string.h:1197
void SetUInt64(uint64_t val)
set as uint64 value
Definition string.cc:1465
String ExtractToLastSlash() const
extract path until last slash
Definition string.h:799
void StripFileExtension()
remove file extension
Definition string.cc:810
Math::vec4 AsVec4() const
return contents as vec4
Definition string.cc:1723
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:1225
uint32_t AsUInt() const
return contents as unsigned integer
Definition string.cc:1072
static String FromMat4(const Math::mat4 &m)
construct a string from mat4
Definition string.h:1117
void AppendInt(int val)
append int value
Definition string.h:1170
void ToUpper()
convert string to upper case
Definition string.cc:936
void SetTransform44(const Math::transform44 &v)
set as transform44 value
Definition string.cc:1628
void AppendPath(const String &path)
append a directory/file to the path (adds separator if necessary)
Definition string.h:1253
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