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 bool BeginsWithString(const String& s) const;
145 bool EndsWithString(const String& s) const;
147 void TerminateAtIndex(IndexT index);
149 bool ContainsCharFromSet(const String& charSet) const;
151 void TrimLeft(const String& charSet);
153 void TrimRight(const String& charSet);
155 void Trim(const String& charSet);
157 void SubstituteString(const String& str, const String& substStr);
159 void SubstituteChar(char c, char subst);
161 void __cdecl Format(const char* fmtString, ...);
163 void __cdecl FormatArgList(const char* fmtString, va_list argList);
165 static String Sprintf(const char* fmtString, ...);
167 bool CheckValidCharSet(const String& charSet) const;
169 void ReplaceChars(const String& charSet, char replacement);
171 static String Concatenate(const Array<String>& strArray, const String& whiteSpace);
173 static bool MatchPattern(const String& str, const String& pattern);
175 uint32_t HashCode() const;
176
178 void SetCharPtr(const char* s);
180 void Set(const char* ptr, SizeT length);
182 void Set(const char* ptr, size_t length);
184 void SetByte(byte val);
186 void SetUByte(ubyte val);
188 void SetShort(short val);
190 void SetUShort(ushort val);
192 void SetInt(int val);
194 void SetUInt(uint val);
196 void SetLong(long val);
198 void SetSizeT(size_t val);
200 void SetLongLong(long long val);
202 void SetFloat(float val);
204 void SetDouble(double val);
206 void SetBool(bool val);
207
209 void Fill(SizeT length, unsigned char character);
210
211 #if !__OSX__
213 void SetVec2(const Math::vec2& v);
215 void SetVec3(const Math::vec3& v);
217 void SetVec4(const Math::vec4& v);
219 void SetFloat2(const Math::float2& v);
221 void SetFloat3(const Math::float3& v);
223 void SetFloat4(const Math::float4& v);
225 void SetQuaternion(const Math::quat& v);
227 void SetMat4(const Math::mat4& v);
229 void SetTransform44(const Math::transform44& v);
230 #endif
232 template<typename T> void Set(const T& t);
233
235 void AppendChar(char val);
237 void AppendInt(int val);
239 void AppendByte(byte val);
241 void AppendUByte(ubyte val);
243 void AppendFloat(float val);
245 void AppendBool(bool val);
247 void AppendVec2(const Math::vec2& v);
249 void AppendVec3(const Math::vec3& v);
251 void AppendVec4(const Math::vec4& v);
253 void AppendMat4(const Math::mat4& v);
255 template<typename T> void Append(const T& t);
256
258 const char* AsCharPtr() const;
260 const char* Get() const;
262 int AsInt() const;
264 long long AsLongLong() const;
266 float AsFloat() const;
268 bool AsBool() const;
270 Math::vec2 AsVec2() const;
272 Math::vec3 AsVec3() const;
274 Math::vec4 AsVec4() const;
276 Math::float2 AsFloat2() const;
278 Math::float3 AsFloat3() const;
280 Math::float4 AsFloat4() const;
282 Math::mat4 AsMat4() const;
286 Util::Blob AsBlob() const;
288 Util::String AsBase64() const;
290 template<typename T> T As() const;
291
293 bool IsValidInt() const;
295 bool IsValidFloat() const;
297 bool IsValidBool() const;
299 bool IsValidVec2() const;
301 bool IsValidVec4() const;
303 bool IsValidMat4() const;
305 bool IsValidTransform44() const;
307 template<typename T> bool IsValid() const;
308
310 static String FromByte(byte i);
312 static String FromUByte(ubyte i);
314 static String FromShort(short i);
316 static String FromUShort(ushort i);
318 static String FromInt(int i);
320 static String FromUInt(uint i);
322 static String FromLong(long i);
324 static String FromSize(size_t i);
326 static String FromLongLong(long long i);
328 static String FromFloat(float f);
330 static String FromDouble(double f);
332 static String FromBool(bool b);
334 static String FromVec2(const Math::vec2& v);
336 static String FromVec3(const Math::vec3& v);
338 static String FromVec4(const Math::vec4& v);
340 static String FromFloat2(const Math::float2& v);
342 static String FromFloat3(const Math::float3& v);
344 static String FromFloat4(const Math::float4& v);
346 static String FromQuat(const Math::quat& q);
348 static String FromMat4(const Math::mat4& m);
352 static String FromBlob(const Util::Blob & b);
354 static String FromBase64(const String&);
356 template<typename T> static String From(const T& t);
358 static constexpr uint Hash(const char* c, std::size_t s);
359
361 template<typename INTEGER>
362 static String Hex(INTEGER i);
363
365 String GetFileExtension() const;
367 bool CheckFileExtension(const String& ext) const;
369 void ConvertBackslashes();
371 void StripFileExtension();
373 void ChangeFileExtension(const Util::String& newExt);
375 void StripAssignPrefix();
377 void ChangeAssignPrefix(const Util::String& newPref);
379 String ExtractFileName() const;
383 String ExtractDirName() const;
387 void ReplaceIllegalFilenameChars(char replacement);
388
390 inline const char* c_str() const { return this->AsCharPtr(); }
392 inline size_t length() const { return this->Length(); }
394 inline bool empty() const { return this->IsEmpty(); }
395
397 static bool IsDigit(char c);
399 static bool IsAlpha(char c);
401 static bool IsAlNum(char c);
403 static bool IsLower(char c);
405 static bool IsUpper(char c);
406
408 static int StrCmp(const char* str0, const char* str1);
410 static int StrLen(const char* str);
412 static const char* StrChr(const char* str, int c);
413
416
417private:
419 void Delete();
421 char* GetLastSlash() const;
423 void Alloc(SizeT size);
425 void Realloc(SizeT newSize);
426
427 enum
428 {
430 };
435};
436
437//------------------------------------------------------------------------------
440inline
442 heapBuffer(nullptr),
443 strLen(0),
444 heapBufferSize(0)
445{
446 this->localBuffer[0] = 0;
447}
448
449//------------------------------------------------------------------------------
452inline void
454{
455 if (this->heapBuffer)
456 {
458 this->heapBuffer = nullptr;
459 }
460 this->localBuffer[0] = 0;
461 this->strLen = 0;
462 this->heapBufferSize = 0;
463}
464
465//------------------------------------------------------------------------------
468inline
470{
471 this->Delete();
472}
473
474//------------------------------------------------------------------------------
477inline
478String::String(const char* str) :
479 heapBuffer(0),
480 strLen(0),
481 heapBufferSize(0)
482{
483 this->localBuffer[0] = 0;
484 this->SetCharPtr(str);
485}
486
487//------------------------------------------------------------------------------
490inline
491String::String(const char* str, size_t len) :
492 heapBuffer(0),
493 strLen(0),
494 heapBufferSize(0)
495{
496 this->localBuffer[0] = 0;
497 this->Set(str, (SizeT)len);
498}
499
500
501//------------------------------------------------------------------------------
504inline
506 heapBuffer(0),
507 strLen(0),
508 heapBufferSize(0)
509{
510 this->localBuffer[0] = 0;
511 this->SetCharPtr(rhs.AsCharPtr());
512}
513
514//------------------------------------------------------------------------------
517inline
518String::String(String&& rhs) noexcept:
519 heapBuffer(rhs.heapBuffer),
520 strLen(rhs.strLen),
521 heapBufferSize(rhs.heapBufferSize)
522{
523 if (rhs.heapBuffer)
524 {
525 rhs.heapBuffer = nullptr;
526 this->localBuffer[0] = 0;
527 }
528 else
529 {
530 if (this->strLen > 0)
531 {
532 Memory::Copy(rhs.localBuffer, this->localBuffer, this->strLen);
533 }
534 this->localBuffer[this->strLen] = 0;
535 }
536}
537
538//------------------------------------------------------------------------------
541inline const char*
543{
544 if (this->heapBuffer)
545 {
546 return this->heapBuffer;
547 }
548 else
549 {
550 return this->localBuffer;
551 }
552}
553
554//------------------------------------------------------------------------------
557inline const char*
559{
560 return this->AsCharPtr();
561}
562
563//------------------------------------------------------------------------------
566inline void
568{
569 if (&rhs != this)
570 {
571 this->SetCharPtr(rhs.AsCharPtr());
572 }
573}
574
575//------------------------------------------------------------------------------
578inline void
580{
581 if (&rhs != this)
582 {
583 this->Delete();
584 this->strLen = rhs.strLen;
585 rhs.strLen = 0;
586 if (rhs.heapBuffer)
587 {
588 this->heapBuffer = rhs.heapBuffer;
589 this->heapBufferSize = rhs.heapBufferSize;
590 rhs.heapBuffer = nullptr;
591 rhs.heapBufferSize = 0;
592 }
593 else
594 {
595 if (this->strLen > 0)
596 {
597 Memory::Copy(rhs.localBuffer, this->localBuffer, this->strLen);
598 }
599 this->localBuffer[this->strLen] = 0;
600 }
601 }
602}
603
604//------------------------------------------------------------------------------
607inline void
608String::operator=(const char* cStr)
609{
610 this->SetCharPtr(cStr);
611}
612
613//------------------------------------------------------------------------------
616inline void
618{
619 this->AppendRange(str.AsCharPtr(), str.strLen);
620}
621
622//------------------------------------------------------------------------------
625inline void
627{
628 this->Append(rhs);
629}
630
631//------------------------------------------------------------------------------
634inline char
636{
637 n_assert(i <= this->strLen);
638 return this->AsCharPtr()[i];
639}
640
641//------------------------------------------------------------------------------
646inline char&
648{
649 n_assert(i <= this->strLen);
650 return (char&)(this->AsCharPtr())[i];
651}
652
653//------------------------------------------------------------------------------
656inline SizeT
658{
659 return this->strLen;
660}
661
662//------------------------------------------------------------------------------
665inline void
667{
668 this->Delete();
669}
670
671//------------------------------------------------------------------------------
674inline bool
676{
677 return (0 == this->strLen);
678}
679
680//------------------------------------------------------------------------------
683inline bool
685{
686 return (0 != this->strLen);
687}
688
689//------------------------------------------------------------------------------
694inline uint32_t
696{
697 const char* ptr = this->AsCharPtr();
698 return Hash(ptr, this->strLen);
699}
700
701//------------------------------------------------------------------------------
704static inline String
705operator+(const String& s0, const String& s1)
706{
707 String newString = s0;
708 newString.Append(s1);
709 return newString;
710}
711
712//------------------------------------------------------------------------------
716inline void
717String::SubstituteChar(char c, char subst)
718{
719 char* ptr = const_cast<char*>(this->AsCharPtr());
720 IndexT i;
721 for (i = 0; i <= this->strLen; i++)
722 {
723 if (ptr[i] == c)
724 {
725 ptr[i] = subst;
726 }
727 }
728}
729
730//------------------------------------------------------------------------------
734inline void
736{
737 this->SubstituteChar('\\', '/');
738}
739
740//------------------------------------------------------------------------------
743inline bool
745{
746 return (this->GetFileExtension() == ext);
747}
748
749//------------------------------------------------------------------------------
754inline String
756{
757 String pathString;
758 const char* lastSlash = this->GetLastSlash();
759 if (lastSlash)
760 {
761 pathString = &(lastSlash[1]);
762 }
763 else
764 {
765 pathString = *this;
766 }
767 return pathString;
768}
769
770//------------------------------------------------------------------------------
776inline String
778{
779 String pathString(*this);
780 char* lastSlash = pathString.GetLastSlash();
781 if (lastSlash)
782 {
783 lastSlash[1] = 0;
784 }
785 else
786 {
787 pathString = "";
788 }
789 return pathString;
790}
791
792//------------------------------------------------------------------------------
797inline bool
799{
800 IndexT i;
801 for (i = 0; i < this->strLen; i++)
802 {
803 if (InvalidIndex == charSet.FindCharIndex((*this)[i], 0))
804 {
805 return false;
806 }
807 }
808 return true;
809}
810
811//------------------------------------------------------------------------------
814inline bool
816{
817 return this->CheckValidCharSet(" \t-+01234567890");
818}
819
820//------------------------------------------------------------------------------
824inline bool
826{
827 return this->CheckValidCharSet(" \t-+.e1234567890");
828}
829
830//------------------------------------------------------------------------------
833inline void
835{
836 this->ReplaceChars("\\/:*?\"<>|", replacement);
837}
838
839//------------------------------------------------------------------------------
842inline String
844{
845 String str;
846 str.SetByte(i);
847 return str;
848}
849
850//------------------------------------------------------------------------------
853inline String
855{
856 String str;
857 str.SetUByte(i);
858 return str;
859}
860
861//------------------------------------------------------------------------------
864inline String
866{
867 String str;
868 str.SetShort(i);
869 return str;
870}
871
872//------------------------------------------------------------------------------
875inline String
877{
878 String str;
879 str.SetUShort(i);
880 return str;
881}
882
883//------------------------------------------------------------------------------
886inline String
888{
889 String str;
890 str.SetInt(i);
891 return str;
892}
893
894//------------------------------------------------------------------------------
897inline String
899{
900 String str;
901 str.SetUInt(i);
902 return str;
903}
904
905//------------------------------------------------------------------------------
908inline String
910{
911 String str;
912 str.SetLong(i);
913 return str;
914}
915
916//------------------------------------------------------------------------------
919inline String
921{
922 String str;
923 str.SetSizeT(i);
924 return str;
925}
926
927//------------------------------------------------------------------------------
930inline Util::String
932{
933 String str;
934 str.SetLongLong(i);
935 return str;
936}
937
938//------------------------------------------------------------------------------
941inline String
943{
944 String str;
945 str.SetFloat(f);
946 return str;
947}
948
949//------------------------------------------------------------------------------
952inline String
954{
955 String str;
956 str.SetDouble(i);
957 return str;
958}
959
960//------------------------------------------------------------------------------
963inline String
965{
966 String str;
967 str.SetBool(b);
968 return str;
969}
970
971#if !__OSX__
972//------------------------------------------------------------------------------
975inline String
977{
978 String str;
979 str.SetVec2(v);
980 return str;
981}
982
983//------------------------------------------------------------------------------
986inline String
988{
989 String str;
990 str.SetVec3(v);
991 return str;
992}
993
994//------------------------------------------------------------------------------
997inline String
999{
1000 String str;
1001 str.SetVec4(v);
1002 return str;
1003}
1004
1005//------------------------------------------------------------------------------
1008inline String
1010{
1011 String str;
1012 str.SetFloat2(v);
1013 return str;
1014}
1015
1016//------------------------------------------------------------------------------
1019inline String
1021{
1022 String str;
1023 str.SetFloat3(v);
1024 return str;
1025}
1026
1027//------------------------------------------------------------------------------
1030inline String
1032{
1033 String str;
1034 str.SetFloat4(v);
1035 return str;
1036}
1037
1038//------------------------------------------------------------------------------
1041inline String
1043{
1044 String str;
1045 str.SetQuaternion(q);
1046 return str;
1047}
1048
1049//------------------------------------------------------------------------------
1052inline String
1054{
1055 String str;
1056 str.SetMat4(m);
1057 return str;
1058}
1059
1060//------------------------------------------------------------------------------
1063inline String
1065{
1066 String str;
1067 str.SetTransform44(t);
1068 return str;
1069}
1070#endif
1071
1072//------------------------------------------------------------------------------
1075template<typename INTEGER>
1076inline String
1077String::Hex(INTEGER i)
1078{
1079 constexpr SizeT hexLength = sizeof(INTEGER) << 1;
1080 static Util::String digits = "0123456789ABCDEF";
1081
1082 String str("0x");
1083 str.Reserve(hexLength + 2);
1084
1085 for (SizeT n = 0, j = (hexLength - 1) * 4; n < hexLength; ++n, j -= 4)
1086 {
1087 str.AppendChar(digits[(i >> j) & 0x0f]);
1088 }
1089
1090 return str;
1091}
1092
1093//------------------------------------------------------------------------------
1096inline void
1098{
1099 this->AppendRange(&val, 1);
1100}
1101
1102//------------------------------------------------------------------------------
1105inline void
1107{
1108 this->Append(FromInt(val));
1109}
1110
1111//------------------------------------------------------------------------------
1114inline void
1116{
1117 this->Append(FromByte(val));
1118}
1119
1120//------------------------------------------------------------------------------
1123inline void
1125{
1126 this->Append(FromUByte(val));
1127}
1128
1129//------------------------------------------------------------------------------
1132inline void
1134{
1135 this->Append(FromFloat(val));
1136}
1137
1138//------------------------------------------------------------------------------
1141inline void
1143{
1144 this->Append(FromBool(val));
1145}
1146
1147#if !__OSX__
1148//------------------------------------------------------------------------------
1151inline void
1153{
1154 this->Append(FromVec2(val));
1155}
1156
1157//------------------------------------------------------------------------------
1160inline void
1162{
1163 this->Append(FromVec3(val));
1164}
1165
1166//------------------------------------------------------------------------------
1169inline void
1171{
1172 this->Append(FromVec4(val));
1173}
1174
1175//------------------------------------------------------------------------------
1178inline void
1180{
1181 this->Append(FromMat4(val));
1182}
1183#endif
1184
1185
1186//------------------------------------------------------------------------------
1189constexpr uint
1190String::Hash(const char* c, std::size_t s)
1191{
1192 uint hash = 0;
1193 std::size_t i;
1194 for (i = 0; i < s; i++)
1195 {
1196 hash += c[i];
1197 hash += hash << 10;
1198 hash ^= hash >> 6;
1199 }
1200 hash += hash << 3;
1201 hash ^= hash >> 11;
1202 hash += hash << 15;
1203 return hash;
1204}
1205
1207
1208} // namespace Util
1209
1210
1211//------------------------------------------------------------------------------
1215Util::String operator ""_str(const char* c, std::size_t s);
1216
1217//------------------------------------------------------------------------------
1221constexpr uint
1222operator ""_hash(const char* c, std::size_t s)
1223{
1224 return Util::String::Hash(c, s);
1225}
1226
1227//------------------------------------------------------------------------------
1228
A 4x4 matrix which is described by translation, rotation and scale.
Definition transform44.h:20
Nebula's dynamic array class.
Definition array.h:60
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 pinned array is an array which manages its own virtual memory.
Definition String.cs:6
auto Format
Definition string.h:1206
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:40
A 4D vector.
Definition vec4.h:24
Nebula's universal string class.
Definition string.h:50
void SetCharPtr(const char *s)
set content to char ptr
Definition string.cc:763
T As() const
convert to "anything"
static String FromVec3(const Math::vec3 &v)
construct a string from vec3
Definition string.h:987
void SetInt(int val)
set as int value
Definition string.cc:1405
Math::mat4 AsMat4() const
return contents as mat4
Definition string.cc:705
Util::Blob AsBlob() const
return contents as blob
Definition string.cc:1231
static bool IsAlpha(char c)
test if provided character is an alphabet character (A..Z, a..z)
Definition string.cc:1103
static String FromUByte(ubyte i)
construct a string from a ubyte
Definition string.h:854
void SetShort(short val)
set as short value
Definition string.cc:1387
void ToLower()
convert string to lower case
Definition string.cc:913
bool IsValidVec4() const
return true if the content is a valid vec4
Definition string.cc:1605
String ExtractToLastSlash() const
extract path until last slash
Definition string.h:777
static String FromUInt(uint i)
construct a string from a uint
Definition string.h:898
static String FromFloat2(const Math::float2 &v)
construct a string from float2
Definition string.h:1009
void Clear()
clear the string
Definition string.h:666
void SetTransform44(const Math::transform44 &v)
set as transform44 value
Definition string.cc:1577
~String()
destructor
Definition string.h:469
static const char * StrChr(const char *str, int c)
find character in string
Definition string.cc:1159
void Capitalize()
convert first char of string to upper case
Definition string.cc:941
void AppendVec4(const Math::vec4 &v)
append vec4 value
Definition string.h:1170
SizeT Length() const
return length of string
Definition string.h:657
@ LocalStringSize
Definition string.h:429
size_t length() const
Definition string.h:392
void AppendChar(char val)
append character
Definition string.h:1097
bool IsValidBool() const
return true if the content is a valid bool
Definition string.cc:1015
friend bool operator!=(const String &a, const String &b)
inequality operator
Definition string.cc:868
static String FromBool(bool b)
construct a string from a bool
Definition string.h:964
static String FromByte(byte i)
construct a string from a byte
Definition string.h:843
void AppendRange(const char *str, SizeT numChars)
append a range of characters
Definition string.cc:161
void AppendFloat(float val)
append float value
Definition string.h:1133
void AppendByte(byte val)
append byte value
Definition string.h:1115
static String FromQuat(const Math::quat &q)
construct a string from quat
Definition string.h:1042
void ConvertBackslashes()
convert backslashes to slashes
Definition string.h:735
void SetVec2(const Math::vec2 &v)
set as vec2 value
Definition string.cc:1498
int strLen
Definition String.cs:11
static String FromDouble(double f)
construct a string from a double
Definition string.h:953
IndexT FindCharIndex(char c, IndexT startIndex=0) const
return index of character in string, or InvalidIndex if not found
Definition string.cc:371
bool IsValid() const
return true if string object is not empty
Definition string.h:684
void StripFileExtension()
remove file extension
Definition string.cc:801
void SetBool(bool val)
set as bool value
Definition string.cc:1468
void Set(const char *ptr, SizeT length)
set as char ptr, with explicit length
Definition string.cc:112
void AppendBool(bool val)
append bool value
Definition string.h:1142
static String FromTransform44(const Math::transform44 &m)
construct a string from transform44
Definition string.h:1064
void SetDouble(double val)
set as double value
Definition string.cc:1459
void AppendVec2(const Math::vec2 &v)
append vec2 value
Definition string.h:1152
bool AsBool() const
return contents as bool
Definition string.cc:1072
void SetLongLong(long long val)
set as long long value
Definition string.cc:1441
void ToUpper()
convert string to upper case
Definition string.cc:927
friend bool operator<=(const String &a, const String &b)
less-or-equal operator
Definition string.cc:895
static bool IsDigit(char c)
test if provided character is a digit (0..9)
Definition string.cc:1094
static String Concatenate(const Array< String > &strArray, const String &whiteSpace)
concatenate array of strings into new string
Definition string.cc:742
void TrimLeft(const String &charSet)
delete characters from charset at left side of string
Definition string.cc:408
friend bool operator==(const String &a, const String &b)
equality operator
Definition string.cc:830
void StripAssignPrefix()
remove assign prefix (for example tex:)
Definition string.cc:816
void SetFloat4(const Math::float4 &v)
set as vec4 value
Definition string.cc:1543
char operator[](IndexT i) const
read-only index operator
Definition string.h:635
void Fill(SizeT length, unsigned char character)
set string length and fill all characters with arg
Definition string.cc:1484
bool IsValidInt() const
return true if the content is a valid integer
Definition string.h:815
static String FromInt(int i)
construct a string from an int
Definition string.h:887
static String FromFloat(float f)
construct a string from a float
Definition string.h:942
static String FromVec4(const Math::vec4 &v)
construct a string from vec4
Definition string.h:998
void __cdecl FormatArgList(const char *fmtString, va_list argList)
format string printf-style with varargs list
Definition string.cc:78
float AsFloat() const
return contents as float
Definition string.cc:1063
String()
constructor
Definition string.h:441
void ChangeAssignPrefix(const Util::String &newPref)
change assign prefix
Definition string.cc:1196
void ReplaceIllegalFilenameChars(char replacement)
replace illegal filename characters
Definition string.h:834
void Delete()
delete contents
Definition string.h:453
Util::String AsBase64() const
return contents as base64 string
Definition string.cc:1265
bool CopyToBuffer(char *buf, SizeT bufSize) const
copy to char buffer (return false if buffer is too small)
Definition string.cc:38
Math::vec4 AsVec4() const
return contents as vec4
Definition string.cc:1672
bool CheckFileExtension(const String &ext) const
check file extension
Definition string.h:744
void ReplaceChars(const String &charSet, char replacement)
replace any char set character within a string with the replacement character
Definition string.cc:682
String ExtractFileName() const
extract the part after the last directory separator
Definition string.h:755
void Append(const T &t)
generic append
String ExtractToEnd(IndexT fromIndex) const
extract substring to end of this string
Definition string.cc:319
static String FromBase64(const String &)
create from base64
Definition string.cc:1282
void SetMat4(const Math::mat4 &v)
set as mat4 value
Definition string.cc:1561
bool IsValidFloat() const
return true if the content is a valid float
Definition string.h:825
void SetSizeT(size_t val)
set as long value
Definition string.cc:1432
Math::float3 AsFloat3() const
return contents as vec3
Definition string.cc:1698
void TrimRight(const String &charSet)
delete characters from charset at right side of string
Definition string.cc:450
int heapBufferSize
Definition String.cs:12
void Alloc(SizeT size)
allocate the string buffer (discards old content)
Definition string.cc:1301
Math::vec2 AsVec2() const
return contents as vec2
Definition string.cc:1643
static String FromFloat3(const Math::float3 &v)
construct a string from float2
Definition string.h:1020
void ChangeFileExtension(const Util::String &newExt)
change file extension
Definition string.cc:1186
static bool IsUpper(char c)
test if provided character is an upper-case character
Definition string.cc:1130
Math::transform44 AsTransform44() const
return contents as transform44
Definition string.cc:722
void Set(const T &t)
generic setter
void Append(const String &str)
append string
Definition string.h:617
Math::float4 AsFloat4() const
return contents as vec4
Definition string.cc:1711
friend bool operator<(const String &a, const String &b)
less-then operator
Definition string.cc:877
void AppendUByte(ubyte val)
append unsigned byte value
Definition string.h:1124
String ExtractDirName() const
extract the part before the last directory separator
Definition string.cc:580
static constexpr uint Hash(const char *c, std::size_t s)
Hash a string.
Definition string.h:1190
static int StrCmp(const char *str0, const char *str1)
lowlevel string compare wrapper function
Definition string.cc:1139
char * GetLastSlash() const
get pointer to last directory separator
Definition string.cc:1002
SizeT heapBufferSize
Definition string.h:434
static String From(const T &t)
convert from "anything"
void operator=(const String &rhs)
assignment operator
Definition string.h:567
void SetLong(long val)
set as long value
Definition string.cc:1423
static String FromLongLong(long long i)
construct a string from a long long
Definition string.h:931
void SetByte(byte val)
set as byte value
Definition string.cc:1369
Math::float2 AsFloat2() const
return contents as vec2
Definition string.cc:1685
static String FromMat4(const Math::mat4 &m)
construct a string from mat4
Definition string.h:1053
int AsInt() const
return contents as integer
Definition string.cc:1039
void SetVec3(const Math::vec3 &v)
set as vec3 value
Definition string.cc:1507
void SetUInt(uint val)
set as uint value
Definition string.cc:1414
static String FromBlob(const Util::Blob &b)
create from blob
Definition string.cc:1206
static String FromShort(short i)
construct a string from a short
Definition string.h:865
void AppendVec3(const Math::vec3 &v)
append vec3 value
Definition string.h:1161
void Strip(const String &charSet)
terminate string at first occurence of character in set
Definition string.cc:330
static String FromUShort(ushort i)
construct a string from a ushort
Definition string.h:876
void TerminateAtIndex(IndexT index)
terminate string at given index
Definition string.cc:788
bool BeginsWithString(const String &s) const
returns true if string begins with string
Definition string.cc:389
void SetVec4(const Math::vec4 &v)
set as vec4 value
Definition string.cc:1516
void AppendMat4(const Math::mat4 &v)
append mat4 value
Definition string.h:1179
const char * AsCharPtr() const
return contents as character pointer
Definition string.h:542
void AppendInt(int val)
append int value
Definition string.h:1106
static String FromVec2(const Math::vec2 &v)
construct a string from vec2
Definition string.h:976
void Realloc(SizeT newSize)
(re-)allocate the string buffer (copies old content)
Definition string.cc:1324
String ExtractLastDirName() const
extract the last directory of the path
Definition string.cc:540
void SetFloat(float val)
set as float value
Definition string.cc:1450
static int StrLen(const char *str)
lowlevel string length function
Definition string.cc:1149
char * heapBuffer
Definition string.h:431
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:203
static Dictionary< String, String > ParseKeyValuePairs(const String &str)
parse key/value pair string ("key0=value0 key1=value1")
Definition string.cc:1169
void SetFloat2(const Math::float2 &v)
set as vec2 value
Definition string.cc:1525
bool IsValidTransform44() const
return true if content is a valid transform44
Definition string.cc:1629
void Trim(const String &charSet)
trim characters from charset at both sides of string
Definition string.cc:493
friend bool operator>(const String &a, const String &b)
greater-then operator
Definition string.cc:886
bool IsValidMat4() const
return true if content is a valid mat4
Definition string.cc:1617
const char * Get() const
*** OBSOLETE *** only Nebula2 compatibility
Definition string.h:558
static bool IsLower(char c)
test if provided character is a lower case character
Definition string.cc:1121
bool IsEmpty() const
return true if string object is empty
Definition string.h:675
String GetFileExtension() const
get filename extension without dot
Definition string.cc:985
void SubstituteString(const String &str, const String &substStr)
substitute every occurance of a string with another string
Definition string.cc:504
static bool MatchPattern(const String &str, const String &pattern)
pattern matching
Definition string.cc:607
static String FromLong(long i)
construct a string from a long
Definition string.h:909
char localBuffer[LocalStringSize]
Definition string.h:432
void operator+=(const String &rhs)
+= operator
Definition string.h:626
bool EndsWithString(const String &s) const
returns true if string ends with string
Definition string.cc:398
static String Sprintf(const char *fmtString,...)
static constructor for string using printf
Definition string.cc:96
void SetQuaternion(const Math::quat &v)
set as quaternion
Definition string.cc:1552
const char * c_str() const
helpers to interface with libraries that expect std::string like apis
Definition string.h:390
void CamelCaseToWords()
insert spaces before each capital letter in the string.
Definition string.cc:951
static String FromSize(size_t i)
construct a string from a size_t
Definition string.h:920
IndexT FindStringIndex(const String &s, IndexT startIndex=0) const
return start index of substring, or InvalidIndex if not found
Definition string.cc:346
uint32_t HashCode() const
return a 32-bit hash code for the string
Definition string.h:695
void SubstituteChar(char c, char subst)
substitute every occurance of a character with another character
Definition string.h:717
static String Hex(INTEGER i)
construct a hex string from an int
Definition string.h:1077
void SetUByte(ubyte val)
set as ubyte value
Definition string.cc:1378
String ExtractRange(IndexT fromIndex, SizeT numChars) const
extract substring
Definition string.cc:304
long long AsLongLong() const
return contents as long long
Definition string.cc:1051
void SetUShort(ushort val)
set as ushort value
Definition string.cc:1396
static String FromFloat4(const Math::float4 &v)
construct a string from float2
Definition string.h:1031
Math::vec3 AsVec3() const
return contents as vec3
Definition string.cc:1656
friend bool operator>=(const String &a, const String &b)
greater-then operator
Definition string.cc:904
bool CheckValidCharSet(const String &charSet) const
return true if string only contains characters from charSet argument
Definition string.h:798
bool IsValid() const
generic valid checker
bool empty() const
Definition string.h:394
SizeT strLen
Definition string.h:433
void Reserve(SizeT newSize)
reserve internal buffer size to prevent heap allocs
Definition string.cc:1357
bool ContainsCharFromSet(const String &charSet) const
returns true if string contains any character from set
Definition string.cc:973
void SetFloat3(const Math::float3 &v)
set as vec3 value
Definition string.cc:1534
static bool IsAlNum(char c)
test if provided character is an alpha-numeric character (A..Z,a..z,0..9)
Definition string.cc:1112
bool IsValidVec2() const
return true if the content is a valid vec2
Definition string.cc:1593
static const int InvalidIndex
Definition types.h:54
unsigned char ubyte
Definition types.h:34
int SizeT
Definition types.h:49
unsigned int uint
Definition types.h:31
unsigned short ushort
Definition types.h:32
int IndexT
Definition types.h:48