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 StripSubpath(const String& subpath) 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 int StrCmp(const char* str0, const char* str1);
434 static int StrLen(const char* str);
436 static const char* StrChr(const char* str, int c);
437
440
441private:
443 void Delete();
445 char* GetLastSlash() const;
447 void Alloc(SizeT size);
449 void Realloc(SizeT newSize);
450
451 enum
452 {
454 };
459};
460
461//------------------------------------------------------------------------------
464inline
466 heapBuffer(nullptr),
467 strLen(0),
469{
470 this->localBuffer[0] = 0;
471}
472
473//------------------------------------------------------------------------------
476inline void
478{
479 if (this->heapBuffer)
480 {
482 this->heapBuffer = nullptr;
483 }
484 this->localBuffer[0] = 0;
485 this->strLen = 0;
486 this->heapBufferSize = 0;
487}
488
489//------------------------------------------------------------------------------
492inline
494{
495 this->Delete();
496}
497
498//------------------------------------------------------------------------------
501inline
502String::String(const char* str) :
503 heapBuffer(0),
504 strLen(0),
506{
507 this->localBuffer[0] = 0;
508 this->SetCharPtr(str);
509}
510
511//------------------------------------------------------------------------------
514inline
515String::String(const char* str, size_t len) :
516 heapBuffer(0),
517 strLen(0),
519{
520 this->localBuffer[0] = 0;
521 this->Set(str, (SizeT)len);
522}
523
524
525//------------------------------------------------------------------------------
528inline
530 heapBuffer(0),
531 strLen(0),
533{
534 this->localBuffer[0] = 0;
535 this->SetCharPtr(rhs.AsCharPtr());
536}
537
538//------------------------------------------------------------------------------
541inline
542String::String(String&& rhs) noexcept:
543 heapBuffer(rhs.heapBuffer),
544 strLen(rhs.strLen),
545 heapBufferSize(rhs.heapBufferSize)
546{
547 if (rhs.heapBuffer)
548 {
549 rhs.heapBuffer = nullptr;
550 rhs.strLen = 0;
551 rhs.heapBufferSize = 0;
552 this->localBuffer[0] = 0;
553 }
554 else
555 {
556 if (this->strLen > 0)
557 {
558 Memory::Copy(rhs.localBuffer, this->localBuffer, this->strLen);
559 }
560 this->localBuffer[this->strLen] = 0;
561 rhs.heapBuffer = nullptr;
562 rhs.strLen = 0;
563 rhs.heapBufferSize = 0;
564
565 }
566}
567
568//------------------------------------------------------------------------------
571inline const char*
573{
574 if (this->heapBuffer)
575 {
576 return this->heapBuffer;
577 }
578 else
579 {
580 return this->localBuffer;
581 }
582}
583
584//------------------------------------------------------------------------------
587inline const char*
589{
590 return this->AsCharPtr();
591}
592
593//------------------------------------------------------------------------------
596inline void
598{
599 if (&rhs != this)
600 {
601 this->SetCharPtr(rhs.AsCharPtr());
602 }
603}
604
605//------------------------------------------------------------------------------
608inline void
610{
611 if (&rhs != this)
612 {
613 this->Delete();
614 this->strLen = rhs.strLen;
615 rhs.strLen = 0;
616 if (rhs.heapBuffer)
617 {
618 this->heapBuffer = rhs.heapBuffer;
619 this->heapBufferSize = rhs.heapBufferSize;
620 rhs.heapBuffer = nullptr;
621 rhs.heapBufferSize = 0;
622 }
623 else
624 {
625 if (this->strLen > 0)
626 {
627 Memory::Copy(rhs.localBuffer, this->localBuffer, this->strLen);
628 }
629 this->localBuffer[this->strLen] = 0;
630 }
631 }
632}
633
634//------------------------------------------------------------------------------
637inline void
638String::operator=(const char* cStr)
639{
640 this->SetCharPtr(cStr);
641}
642
643//------------------------------------------------------------------------------
646inline void
648{
649 this->AppendRange(str.AsCharPtr(), str.strLen);
650}
651
652//------------------------------------------------------------------------------
655inline void
657{
658 this->Append(rhs);
659}
660
661//------------------------------------------------------------------------------
664inline char
666{
667 n_assert(i <= this->strLen);
668 return this->AsCharPtr()[i];
669}
670
671//------------------------------------------------------------------------------
676inline char&
678{
679 n_assert(i <= this->strLen);
680 return (char&)(this->AsCharPtr())[i];
681}
682
683//------------------------------------------------------------------------------
686inline SizeT
688{
689 return this->strLen;
690}
691
692//------------------------------------------------------------------------------
695inline void
697{
698 this->Delete();
699}
700
701//------------------------------------------------------------------------------
704inline bool
706{
707 return (0 == this->strLen);
708}
709
710//------------------------------------------------------------------------------
713inline bool
715{
716 return (0 != this->strLen);
717}
718
719//------------------------------------------------------------------------------
724inline uint32_t
726{
727 const char* ptr = this->AsCharPtr();
728 return Hash(ptr, this->strLen);
729}
730
731//------------------------------------------------------------------------------
734static inline String
735operator+(const String& s0, const String& s1)
736{
737 String newString = s0;
738 newString.Append(s1);
739 return newString;
740}
741
742//------------------------------------------------------------------------------
746inline void
747String::SubstituteChar(char c, char subst)
748{
749 char* ptr = const_cast<char*>(this->AsCharPtr());
750 IndexT i;
751 for (i = 0; i <= this->strLen; i++)
752 {
753 if (ptr[i] == c)
754 {
755 ptr[i] = subst;
756 }
757 }
758}
759
760//------------------------------------------------------------------------------
764inline void
766{
767 this->SubstituteChar('\\', '/');
768}
769
770//------------------------------------------------------------------------------
773inline bool
775{
776 return (this->GetFileExtension() == ext);
777}
778
779//------------------------------------------------------------------------------
784inline String
786{
787 String pathString;
788 const char* lastSlash = this->GetLastSlash();
789 if (lastSlash)
790 {
791 pathString = &(lastSlash[1]);
792 }
793 else
794 {
795 pathString = *this;
796 }
797 return pathString;
798}
799
800//------------------------------------------------------------------------------
806inline String
808{
809 String pathString(*this);
810 char* lastSlash = pathString.GetLastSlash();
811 if (lastSlash)
812 {
813 lastSlash[1] = 0;
814 }
815 else
816 {
817 pathString = "";
818 }
819 return pathString;
820}
821
822//------------------------------------------------------------------------------
825inline String
826String::StripSubpath(const String& subpath) const
827{
828 String copy = *this;
829 copy.ConvertBackslashes();
830 IndexT it = 0;
831 while (it < copy.strLen && it < subpath.strLen)
832 {
833 if (subpath[it] != copy[it])
834 break;
835 it++;
836 }
837 while (copy[it] == '/')
838 it++;
839 return copy.ExtractToEnd(it);
840}
841
842//------------------------------------------------------------------------------
847inline bool
849{
850 IndexT i;
851 for (i = 0; i < this->strLen; i++)
852 {
853 if (InvalidIndex == charSet.FindCharIndex((*this)[i], 0))
854 {
855 return false;
856 }
857 }
858 return true;
859}
860
861//------------------------------------------------------------------------------
864inline bool
866{
867 return this->CheckValidCharSet(" \t-+01234567890");
868}
869
870//------------------------------------------------------------------------------
874inline bool
876{
877 return this->CheckValidCharSet(" \t-+.e1234567890");
878}
879
880//------------------------------------------------------------------------------
883inline void
885{
886 this->ReplaceChars("\\/:*?\"<>|", replacement);
887}
888
889//------------------------------------------------------------------------------
892inline String
894{
895 String str;
896 str.SetByte(i);
897 return str;
898}
899
900//------------------------------------------------------------------------------
903inline String
905{
906 String str;
907 str.SetUByte(i);
908 return str;
909}
910
911//------------------------------------------------------------------------------
914inline String
916{
917 String str;
918 str.SetShort(i);
919 return str;
920}
921
922//------------------------------------------------------------------------------
925inline String
927{
928 String str;
929 str.SetUShort(i);
930 return str;
931}
932
933//------------------------------------------------------------------------------
936inline String
938{
939 String str;
940 str.SetInt(i);
941 return str;
942}
943
944//------------------------------------------------------------------------------
947inline String
949{
950 String str;
951 str.SetUInt(i);
952 return str;
953}
954
955//------------------------------------------------------------------------------
958inline String
960{
961 String str;
962 str.SetInt64(i);
963 return str;
964}
965
966//------------------------------------------------------------------------------
969inline String
971{
972 String str;
973 str.SetUInt64(i);
974 return str;
975}
976
977//------------------------------------------------------------------------------
980inline String
982{
983 String str;
984 str.SetLong(i);
985 return str;
986}
987
988//------------------------------------------------------------------------------
991inline String
993{
994 String str;
995 str.SetSizeT(i);
996 return str;
997}
998
999//------------------------------------------------------------------------------
1002inline Util::String
1004{
1005 String str;
1006 str.SetLongLong(i);
1007 return str;
1008}
1009
1010//------------------------------------------------------------------------------
1013inline String
1015{
1016 String str;
1017 str.SetFloat(f);
1018 return str;
1019}
1020
1021//------------------------------------------------------------------------------
1024inline String
1026{
1027 String str;
1028 str.SetDouble(i);
1029 return str;
1030}
1031
1032//------------------------------------------------------------------------------
1035inline String
1037{
1038 String str;
1039 str.SetBool(b);
1040 return str;
1041}
1042
1043#if !__OSX__
1044//------------------------------------------------------------------------------
1047inline String
1049{
1050 String str;
1051 str.SetVec2(v);
1052 return str;
1053}
1054
1055//------------------------------------------------------------------------------
1058inline String
1060{
1061 String str;
1062 str.SetVec3(v);
1063 return str;
1064}
1065
1066//------------------------------------------------------------------------------
1069inline String
1071{
1072 String str;
1073 str.SetVec4(v);
1074 return str;
1075}
1076
1077//------------------------------------------------------------------------------
1080inline String
1082{
1083 String str;
1084 str.SetFloat2(v);
1085 return str;
1086}
1087
1088//------------------------------------------------------------------------------
1091inline String
1093{
1094 String str;
1095 str.SetFloat3(v);
1096 return str;
1097}
1098
1099//------------------------------------------------------------------------------
1102inline String
1104{
1105 String str;
1106 str.SetFloat4(v);
1107 return str;
1108}
1109
1110//------------------------------------------------------------------------------
1113inline String
1115{
1116 String str;
1117 str.SetQuaternion(q);
1118 return str;
1119}
1120
1121//------------------------------------------------------------------------------
1124inline String
1126{
1127 String str;
1128 str.SetMat4(m);
1129 return str;
1130}
1131
1132//------------------------------------------------------------------------------
1135inline String
1137{
1138 String str;
1139 str.SetTransform44(t);
1140 return str;
1141}
1142#endif
1143
1144//------------------------------------------------------------------------------
1147template<typename INTEGER>
1148inline String
1149String::Hex(INTEGER i)
1150{
1151 constexpr SizeT hexLength = sizeof(INTEGER) << 1;
1152 static Util::String digits = "0123456789ABCDEF";
1153
1154 String str("0x");
1155 str.Reserve(hexLength + 2);
1156
1157 for (SizeT n = 0, j = (hexLength - 1) * 4; n < hexLength; ++n, j -= 4)
1158 {
1159 str.AppendChar(digits[(i >> j) & 0x0f]);
1160 }
1161
1162 return str;
1163}
1164
1165//------------------------------------------------------------------------------
1168inline void
1170{
1171 this->AppendRange(&val, 1);
1172}
1173
1174//------------------------------------------------------------------------------
1177inline void
1179{
1180 this->Append(FromInt(val));
1181}
1182
1183//------------------------------------------------------------------------------
1186inline void
1188{
1189 this->Append(FromByte(val));
1190}
1191
1192//------------------------------------------------------------------------------
1195inline void
1197{
1198 this->Append(FromUByte(val));
1199}
1200
1201//------------------------------------------------------------------------------
1204inline void
1206{
1207 this->Append(FromFloat(val));
1208}
1209
1210//------------------------------------------------------------------------------
1213inline void
1215{
1216 this->Append(FromBool(val));
1217}
1218
1219#if !__OSX__
1220//------------------------------------------------------------------------------
1223inline void
1225{
1226 this->Append(FromVec2(val));
1227}
1228
1229//------------------------------------------------------------------------------
1232inline void
1234{
1235 this->Append(FromVec3(val));
1236}
1237
1238//------------------------------------------------------------------------------
1241inline void
1243{
1244 this->Append(FromVec4(val));
1245}
1246
1247//------------------------------------------------------------------------------
1250inline void
1252{
1253 this->Append(FromMat4(val));
1254}
1255#endif
1256
1257//------------------------------------------------------------------------------
1260inline void
1262{
1263 if (!this->IsEmpty() && this->FindCharIndexReverse('/') != (this->strLen - 1))
1264 {
1265 this->AppendChar('/');
1266 }
1267 this->Append(path);
1268}
1269
1270//------------------------------------------------------------------------------
1273inline String
1274String::AppendPath(const String& base, const String& path)
1275{
1276 String result = base;
1277 if (!result.IsEmpty() && result.FindCharIndexReverse('/') != (result.strLen - 1))
1278 {
1279 result.AppendChar('/');
1280 }
1281 result.Append(path);
1282 return result;
1283}
1284
1285//------------------------------------------------------------------------------
1288constexpr uint
1289String::Hash(const char* c, std::size_t s)
1290{
1291 uint hash = 0;
1292 std::size_t i;
1293 for (i = 0; i < s; i++)
1294 {
1295 hash += c[i];
1296 hash += hash << 10;
1297 hash ^= hash >> 6;
1298 }
1299 hash += hash << 3;
1300 hash ^= hash >> 11;
1301 hash += hash << 15;
1302 return hash;
1303}
1304
1306
1307} // namespace Util
1308
1309
1310//------------------------------------------------------------------------------
1314Util::String operator ""_str(const char* c, std::size_t s);
1315
1316//------------------------------------------------------------------------------
1320constexpr uint
1321operator ""_hash(const char* c, std::size_t s)
1322{
1323 return Util::String::Hash(c, s);
1324}
1325
1326//------------------------------------------------------------------------------
1327
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:1305
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:1465
static String FromBase64(const String &)
create from base64
Definition string.cc:1356
static String FromFloat(float f)
construct a string from a float
Definition string.h:1014
void Clear()
clear the string
Definition string.h:696
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:915
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:1286
static String FromVec3(const Math::vec3 &v)
construct a string from vec3
Definition string.h:1059
~String()
destructor
Definition string.h:493
static String FromInt64(int64_t i)
construct a string from a int64
Definition string.h:959
void SetFloat3(const Math::float3 &v)
set as vec3 value
Definition string.cc:1630
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:1070
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:1528
static String FromVec2(const Math::vec2 &v)
construct a string from vec2
Definition string.h:1048
static String FromUInt(uint i)
construct a string from a uint
Definition string.h:948
void ChangeFileExtension(const Util::String &newExt)
change file extension
Definition string.cc:1228
void AppendChar(char val)
append character
Definition string.h:1169
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:1564
void Alloc(SizeT size)
allocate the string buffer (discards old content)
Definition string.cc:1379
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:1474
void SetLongLong(long long val)
set as long long value
Definition string.cc:1537
const char * Get() const
*** OBSOLETE *** only Nebula2 compatibility
Definition string.h:588
static String FromLongLong(long long i)
construct a string from a long long
Definition string.h:1003
bool AsBool() const
return contents as bool
Definition string.cc:1114
void SetInt64(int64_t val)
set as int64 value
Definition string.cc:1501
void ReplaceIllegalFilenameChars(char replacement)
replace illegal filename characters
Definition string.h:884
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:992
void Realloc(SizeT newSize)
(re-)allocate the string buffer (copies old content)
Definition string.cc:1402
void AppendVec4(const Math::vec4 &v)
append vec4 value
Definition string.h:1242
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:1260
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:1483
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:1739
String StripSubpath(const String &subpath) const
strip subpath
Definition string.h:826
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:1435
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:477
void SetVec3(const Math::vec3 &v)
set as vec3 value
Definition string.cc:1603
void StripAssignPrefix()
remove assign prefix (for example tex:)
Definition string.cc:834
void SetLong(long val)
set as long value
Definition string.cc:1519
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:1807
const char * AsCharPtr() const
return contents as character pointer
Definition string.h:572
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:1725
void SubstituteChar(char c, char subst)
substitute every occurance of a character with another character
Definition string.h:747
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:1612
static String From(const T &t)
convert from "anything"
char localBuffer[LocalStringSize]
Definition string.h:456
void Append(const T &t)
generic append
void AppendBool(bool val)
append bool value
Definition string.h:1214
static String FromQuat(const Math::quat &q)
construct a string from quat
Definition string.h:1114
int strLen
Definition String.cs:11
static String FromLong(long i)
construct a string from a long
Definition string.h:981
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:1689
void AppendUByte(ubyte val)
append unsigned byte value
Definition string.h:1196
void operator+=(const String &rhs)
+= operator
Definition string.h:656
void ConvertBackslashes()
convert backslashes to slashes
Definition string.h:765
void SetUByte(ubyte val)
set as ubyte value
Definition string.cc:1456
static String FromInt(int i)
construct a string from an int
Definition string.h:937
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:926
bool IsValidVec4() const
return true if the content is a valid vec4
Definition string.cc:1701
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:1594
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:1781
bool IsValidInt() const
return true if the content is a valid integer
Definition string.h:865
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:725
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:1639
String ExtractFileName() const
extract the part after the last directory separator
Definition string.h:785
static String FromFloat2(const Math::float2 &v)
construct a string from float2
Definition string.h:1081
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:714
static String FromDouble(double f)
construct a string from a double
Definition string.h:1025
void SetFloat(float val)
set as float value
Definition string.cc:1546
static String FromByte(byte i)
construct a string from a byte
Definition string.h:893
static int StrLen(const char *str)
lowlevel string length function
Definition string.cc:1191
size_t length() const
Definition string.h:414
bool CopyToBuffer(char *buf, SizeT bufSize) const
copy to char buffer (return false if buffer is too small)
Definition string.cc:38
void ChangeAssignMapping(const Util::String &newMapping, const Util::String &oldMapping)
Change assign mapping (not just the prefix).
Definition string.cc:1248
void operator=(const String &rhs)
assignment operator
Definition string.h:597
void ToLower()
convert string to lower case
Definition string.cc:931
void SetDouble(double val)
set as double value
Definition string.cc:1555
void Append(const String &str)
append string
Definition string.h:647
void SetUInt(uint val)
set as uint value
Definition string.cc:1492
static String FromFloat4(const Math::float4 &v)
construct a string from float2
Definition string.h:1103
@ LocalStringSize
Definition string.h:453
bool IsValidMat4() const
return true if content is a valid mat4
Definition string.cc:1713
static String FromBool(bool b)
construct a string from a bool
Definition string.h:1036
char operator[](IndexT i) const
read-only index operator
Definition string.h:665
bool CheckFileExtension(const String &ext) const
check file extension
Definition string.h:774
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:1648
void SetByte(byte val)
set as byte value
Definition string.cc:1447
static String FromUInt64(uint64_t i)
construct a string from a uint64
Definition string.h:970
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:1621
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:1136
bool IsValidFloat() const
return true if the content is a valid float
Definition string.h:875
SizeT Length() const
return length of string
Definition string.h:687
const char * c_str() const
helpers to interface with libraries that expect std::string like apis
Definition string.h:412
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:1187
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:1752
Math::transform44 AsTransform44() const
return contents as transform44
Definition string.cc:740
String()
constructor
Definition string.h:465
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:1580
bool CheckValidCharSet(const String &charSet) const
return true if string only contains characters from charSet argument
Definition string.h:848
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:1339
const char * data() const
Definition string.h:418
void SetMat4(const Math::mat4 &v)
set as mat4 value
Definition string.cc:1657
bool empty() const
Definition string.h:416
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:1794
static String FromFloat3(const Math::float3 &v)
construct a string from float2
Definition string.h:1092
char * heapBuffer
Definition string.h:455
void AppendMat4(const Math::mat4 &v)
append mat4 value
Definition string.h:1251
static constexpr uint Hash(const char *c, std::size_t s)
Hash a string.
Definition string.h:1289
static String FromUByte(ubyte i)
construct a string from a ubyte
Definition string.h:904
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:1149
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:1224
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:705
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:1205
void SetUInt64(uint64_t val)
set as uint64 value
Definition string.cc:1510
String ExtractToLastSlash() const
extract path until last slash
Definition string.h:807
void StripFileExtension()
remove file extension
Definition string.cc:819
Math::vec4 AsVec4() const
return contents as vec4
Definition string.cc:1768
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:1233
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:1125
void AppendInt(int val)
append int value
Definition string.h:1178
void ToUpper()
convert string to upper case
Definition string.cc:945
void SetTransform44(const Math::transform44 &v)
set as transform44 value
Definition string.cc:1673
void AppendPath(const String &path)
append a directory/file to the path (adds separator if necessary)
Definition string.h:1261
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