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 FirstCharToUpper();
123 SizeT Tokenize(const String& whiteSpace, Array<String>& outTokens) const;
125 Array<String> Tokenize(const String& whiteSpace) const;
127 SizeT Tokenize(const String& whiteSpace, char fence, Array<String>& outTokens) const;
129 Array<String> Tokenize(const String& whiteSpace, char fence) const;
131 String ExtractRange(IndexT fromIndex, SizeT numChars) const;
133 String ExtractToEnd(IndexT fromIndex) const;
135 void Strip(const String& charSet);
137 IndexT FindStringIndex(const String& s, IndexT startIndex = 0) const;
139 IndexT FindCharIndex(char c, IndexT startIndex = 0) const;
141 bool BeginsWithString(const String& s) const;
143 bool EndsWithString(const String& s) const;
145 void TerminateAtIndex(IndexT index);
147 bool ContainsCharFromSet(const String& charSet) const;
149 void TrimLeft(const String& charSet);
151 void TrimRight(const String& charSet);
153 void Trim(const String& charSet);
155 void SubstituteString(const String& str, const String& substStr);
157 void SubstituteChar(char c, char subst);
159 void __cdecl Format(const char* fmtString, ...);
161 void __cdecl FormatArgList(const char* fmtString, va_list argList);
163 static String Sprintf(const char* fmtString, ...);
165 bool CheckValidCharSet(const String& charSet) const;
167 void ReplaceChars(const String& charSet, char replacement);
169 static String Concatenate(const Array<String>& strArray, const String& whiteSpace);
171 static bool MatchPattern(const String& str, const String& pattern);
173 uint32_t HashCode() const;
174
176 void SetCharPtr(const char* s);
178 void Set(const char* ptr, SizeT length);
180 void Set(const char* ptr, size_t length);
182 void SetByte(byte val);
184 void SetUByte(ubyte val);
186 void SetShort(short val);
188 void SetUShort(ushort val);
190 void SetInt(int val);
192 void SetUInt(uint val);
194 void SetLong(long val);
196 void SetSizeT(size_t val);
198 void SetLongLong(long long val);
200 void SetFloat(float val);
202 void SetDouble(double val);
204 void SetBool(bool val);
205
207 void Fill(SizeT length, unsigned char character);
208
209 #if !__OSX__
211 void SetVec2(const Math::vec2& v);
213 void SetVec3(const Math::vec3& v);
215 void SetVec4(const Math::vec4& v);
217 void SetFloat2(const Math::float2& v);
219 void SetFloat3(const Math::float3& v);
221 void SetFloat4(const Math::float4& v);
223 void SetQuaternion(const Math::quat& v);
225 void SetMat4(const Math::mat4& v);
227 void SetTransform44(const Math::transform44& v);
228 #endif
230 template<typename T> void Set(const T& t);
231
233 void AppendChar(char val);
235 void AppendInt(int val);
237 void AppendByte(byte val);
239 void AppendUByte(ubyte val);
241 void AppendFloat(float val);
243 void AppendBool(bool val);
245 void AppendVec2(const Math::vec2& v);
247 void AppendVec3(const Math::vec3& v);
249 void AppendVec4(const Math::vec4& v);
251 void AppendMat4(const Math::mat4& v);
253 template<typename T> void Append(const T& t);
254
256 const char* AsCharPtr() const;
258 const char* Get() const;
260 int AsInt() const;
262 long long AsLongLong() const;
264 float AsFloat() const;
266 bool AsBool() const;
268 Math::vec2 AsVec2() const;
270 Math::vec3 AsVec3() const;
272 Math::vec4 AsVec4() const;
274 Math::float2 AsFloat2() const;
276 Math::float3 AsFloat3() const;
278 Math::float4 AsFloat4() const;
280 Math::mat4 AsMat4() const;
284 Util::Blob AsBlob() const;
286 Util::String AsBase64() const;
288 template<typename T> T As() const;
289
291 bool IsValidInt() const;
293 bool IsValidFloat() const;
295 bool IsValidBool() const;
297 bool IsValidVec2() const;
299 bool IsValidVec4() const;
301 bool IsValidMat4() const;
303 bool IsValidTransform44() const;
305 template<typename T> bool IsValid() const;
306
308 static String FromByte(byte i);
310 static String FromUByte(ubyte i);
312 static String FromShort(short i);
314 static String FromUShort(ushort i);
316 static String FromInt(int i);
318 static String FromUInt(uint i);
320 static String FromLong(long i);
322 static String FromSize(size_t i);
324 static String FromLongLong(long long i);
326 static String FromFloat(float f);
328 static String FromDouble(double f);
330 static String FromBool(bool b);
332 static String FromVec2(const Math::vec2& v);
334 static String FromVec3(const Math::vec3& v);
336 static String FromVec4(const Math::vec4& v);
338 static String FromFloat2(const Math::float2& v);
340 static String FromFloat3(const Math::float3& v);
342 static String FromFloat4(const Math::float4& v);
344 static String FromQuat(const Math::quat& q);
346 static String FromMat4(const Math::mat4& m);
350 static String FromBlob(const Util::Blob & b);
352 static String FromBase64(const String&);
354 template<typename T> static String From(const T& t);
356 static constexpr uint Hash(const char* c, std::size_t s);
357
359 template<typename INTEGER>
360 static String Hex(INTEGER i);
361
363 String GetFileExtension() const;
365 bool CheckFileExtension(const String& ext) const;
367 void ConvertBackslashes();
369 void StripFileExtension();
371 void ChangeFileExtension(const Util::String& newExt);
373 void StripAssignPrefix();
375 void ChangeAssignPrefix(const Util::String& newPref);
377 String ExtractFileName() const;
381 String ExtractDirName() const;
385 void ReplaceIllegalFilenameChars(char replacement);
386
388 inline const char* c_str() const { return this->AsCharPtr(); }
390 inline size_t length() const { return this->Length(); }
392 inline bool empty() const { return this->IsEmpty(); }
393
395 static bool IsDigit(char c);
397 static bool IsAlpha(char c);
399 static bool IsAlNum(char c);
401 static bool IsLower(char c);
403 static bool IsUpper(char c);
404
406 static int StrCmp(const char* str0, const char* str1);
408 static int StrLen(const char* str);
410 static const char* StrChr(const char* str, int c);
411
414
415private:
417 void Delete();
419 char* GetLastSlash() const;
421 void Alloc(SizeT size);
423 void Realloc(SizeT newSize);
424
425 enum
426 {
428 };
433};
434
435//------------------------------------------------------------------------------
438inline
440 heapBuffer(nullptr),
441 strLen(0),
442 heapBufferSize(0)
443{
444 this->localBuffer[0] = 0;
445}
446
447//------------------------------------------------------------------------------
450inline void
452{
453 if (this->heapBuffer)
454 {
456 this->heapBuffer = nullptr;
457 }
458 this->localBuffer[0] = 0;
459 this->strLen = 0;
460 this->heapBufferSize = 0;
461}
462
463//------------------------------------------------------------------------------
466inline
468{
469 this->Delete();
470}
471
472//------------------------------------------------------------------------------
475inline
476String::String(const char* str) :
477 heapBuffer(0),
478 strLen(0),
479 heapBufferSize(0)
480{
481 this->localBuffer[0] = 0;
482 this->SetCharPtr(str);
483}
484
485//------------------------------------------------------------------------------
488inline
489String::String(const char* str, size_t len) :
490 heapBuffer(0),
491 strLen(0),
492 heapBufferSize(0)
493{
494 this->localBuffer[0] = 0;
495 this->Set(str, (SizeT)len);
496}
497
498
499//------------------------------------------------------------------------------
502inline
504 heapBuffer(0),
505 strLen(0),
506 heapBufferSize(0)
507{
508 this->localBuffer[0] = 0;
509 this->SetCharPtr(rhs.AsCharPtr());
510}
511
512//------------------------------------------------------------------------------
515inline
516String::String(String&& rhs) noexcept:
517 heapBuffer(rhs.heapBuffer),
518 strLen(rhs.strLen),
519 heapBufferSize(rhs.heapBufferSize)
520{
521 if (rhs.heapBuffer)
522 {
523 rhs.heapBuffer = nullptr;
524 this->localBuffer[0] = 0;
525 }
526 else
527 {
528 if (this->strLen > 0)
529 {
530 Memory::Copy(rhs.localBuffer, this->localBuffer, this->strLen);
531 }
532 this->localBuffer[this->strLen] = 0;
533 }
534}
535
536//------------------------------------------------------------------------------
539inline const char*
541{
542 if (this->heapBuffer)
543 {
544 return this->heapBuffer;
545 }
546 else
547 {
548 return this->localBuffer;
549 }
550}
551
552//------------------------------------------------------------------------------
555inline const char*
557{
558 return this->AsCharPtr();
559}
560
561//------------------------------------------------------------------------------
564inline void
566{
567 if (&rhs != this)
568 {
569 this->SetCharPtr(rhs.AsCharPtr());
570 }
571}
572
573//------------------------------------------------------------------------------
576inline void
578{
579 if (&rhs != this)
580 {
581 this->Delete();
582 this->strLen = rhs.strLen;
583 rhs.strLen = 0;
584 if (rhs.heapBuffer)
585 {
586 this->heapBuffer = rhs.heapBuffer;
587 this->heapBufferSize = rhs.heapBufferSize;
588 rhs.heapBuffer = nullptr;
589 rhs.heapBufferSize = 0;
590 }
591 else
592 {
593 if (this->strLen > 0)
594 {
595 Memory::Copy(rhs.localBuffer, this->localBuffer, this->strLen);
596 }
597 this->localBuffer[this->strLen] = 0;
598 }
599 }
600}
601
602//------------------------------------------------------------------------------
605inline void
606String::operator=(const char* cStr)
607{
608 this->SetCharPtr(cStr);
609}
610
611//------------------------------------------------------------------------------
614inline void
616{
617 this->AppendRange(str.AsCharPtr(), str.strLen);
618}
619
620//------------------------------------------------------------------------------
623inline void
625{
626 this->Append(rhs);
627}
628
629//------------------------------------------------------------------------------
632inline char
634{
635 n_assert(i <= this->strLen);
636 return this->AsCharPtr()[i];
637}
638
639//------------------------------------------------------------------------------
644inline char&
646{
647 n_assert(i <= this->strLen);
648 return (char&)(this->AsCharPtr())[i];
649}
650
651//------------------------------------------------------------------------------
654inline SizeT
656{
657 return this->strLen;
658}
659
660//------------------------------------------------------------------------------
663inline void
665{
666 this->Delete();
667}
668
669//------------------------------------------------------------------------------
672inline bool
674{
675 return (0 == this->strLen);
676}
677
678//------------------------------------------------------------------------------
681inline bool
683{
684 return (0 != this->strLen);
685}
686
687//------------------------------------------------------------------------------
692inline uint32_t
694{
695 const char* ptr = this->AsCharPtr();
696 return Hash(ptr, this->strLen);
697}
698
699//------------------------------------------------------------------------------
702static inline String
703operator+(const String& s0, const String& s1)
704{
705 String newString = s0;
706 newString.Append(s1);
707 return newString;
708}
709
710//------------------------------------------------------------------------------
714inline void
715String::SubstituteChar(char c, char subst)
716{
717 char* ptr = const_cast<char*>(this->AsCharPtr());
718 IndexT i;
719 for (i = 0; i <= this->strLen; i++)
720 {
721 if (ptr[i] == c)
722 {
723 ptr[i] = subst;
724 }
725 }
726}
727
728//------------------------------------------------------------------------------
732inline void
734{
735 this->SubstituteChar('\\', '/');
736}
737
738//------------------------------------------------------------------------------
741inline bool
743{
744 return (this->GetFileExtension() == ext);
745}
746
747//------------------------------------------------------------------------------
752inline String
754{
755 String pathString;
756 const char* lastSlash = this->GetLastSlash();
757 if (lastSlash)
758 {
759 pathString = &(lastSlash[1]);
760 }
761 else
762 {
763 pathString = *this;
764 }
765 return pathString;
766}
767
768//------------------------------------------------------------------------------
774inline String
776{
777 String pathString(*this);
778 char* lastSlash = pathString.GetLastSlash();
779 if (lastSlash)
780 {
781 lastSlash[1] = 0;
782 }
783 else
784 {
785 pathString = "";
786 }
787 return pathString;
788}
789
790//------------------------------------------------------------------------------
795inline bool
797{
798 IndexT i;
799 for (i = 0; i < this->strLen; i++)
800 {
801 if (InvalidIndex == charSet.FindCharIndex((*this)[i], 0))
802 {
803 return false;
804 }
805 }
806 return true;
807}
808
809//------------------------------------------------------------------------------
812inline bool
814{
815 return this->CheckValidCharSet(" \t-+01234567890");
816}
817
818//------------------------------------------------------------------------------
822inline bool
824{
825 return this->CheckValidCharSet(" \t-+.e1234567890");
826}
827
828//------------------------------------------------------------------------------
831inline void
833{
834 this->ReplaceChars("\\/:*?\"<>|", replacement);
835}
836
837//------------------------------------------------------------------------------
840inline String
842{
843 String str;
844 str.SetByte(i);
845 return str;
846}
847
848//------------------------------------------------------------------------------
851inline String
853{
854 String str;
855 str.SetUByte(i);
856 return str;
857}
858
859//------------------------------------------------------------------------------
862inline String
864{
865 String str;
866 str.SetShort(i);
867 return str;
868}
869
870//------------------------------------------------------------------------------
873inline String
875{
876 String str;
877 str.SetUShort(i);
878 return str;
879}
880
881//------------------------------------------------------------------------------
884inline String
886{
887 String str;
888 str.SetInt(i);
889 return str;
890}
891
892//------------------------------------------------------------------------------
895inline String
897{
898 String str;
899 str.SetUInt(i);
900 return str;
901}
902
903//------------------------------------------------------------------------------
906inline String
908{
909 String str;
910 str.SetLong(i);
911 return str;
912}
913
914//------------------------------------------------------------------------------
917inline String
919{
920 String str;
921 str.SetSizeT(i);
922 return str;
923}
924
925//------------------------------------------------------------------------------
928inline Util::String
930{
931 String str;
932 str.SetLongLong(i);
933 return str;
934}
935
936//------------------------------------------------------------------------------
939inline String
941{
942 String str;
943 str.SetFloat(f);
944 return str;
945}
946
947//------------------------------------------------------------------------------
950inline String
952{
953 String str;
954 str.SetDouble(i);
955 return str;
956}
957
958//------------------------------------------------------------------------------
961inline String
963{
964 String str;
965 str.SetBool(b);
966 return str;
967}
968
969#if !__OSX__
970//------------------------------------------------------------------------------
973inline String
975{
976 String str;
977 str.SetVec2(v);
978 return str;
979}
980
981//------------------------------------------------------------------------------
984inline String
986{
987 String str;
988 str.SetVec3(v);
989 return str;
990}
991
992//------------------------------------------------------------------------------
995inline String
997{
998 String str;
999 str.SetVec4(v);
1000 return str;
1001}
1002
1003//------------------------------------------------------------------------------
1006inline String
1008{
1009 String str;
1010 str.SetFloat2(v);
1011 return str;
1012}
1013
1014//------------------------------------------------------------------------------
1017inline String
1019{
1020 String str;
1021 str.SetFloat3(v);
1022 return str;
1023}
1024
1025//------------------------------------------------------------------------------
1028inline String
1030{
1031 String str;
1032 str.SetFloat4(v);
1033 return str;
1034}
1035
1036//------------------------------------------------------------------------------
1039inline String
1041{
1042 String str;
1043 str.SetQuaternion(q);
1044 return str;
1045}
1046
1047//------------------------------------------------------------------------------
1050inline String
1052{
1053 String str;
1054 str.SetMat4(m);
1055 return str;
1056}
1057
1058//------------------------------------------------------------------------------
1061inline String
1063{
1064 String str;
1065 str.SetTransform44(t);
1066 return str;
1067}
1068#endif
1069
1070//------------------------------------------------------------------------------
1073template<typename INTEGER>
1074inline String
1075String::Hex(INTEGER i)
1076{
1077 constexpr SizeT hexLength = sizeof(INTEGER) << 1;
1078 static Util::String digits = "0123456789ABCDEF";
1079
1080 String str("0x");
1081 str.Reserve(hexLength + 2);
1082
1083 for (SizeT n = 0, j = (hexLength - 1) * 4; n < hexLength; ++n, j -= 4)
1084 {
1085 str.AppendChar(digits[(i >> j) & 0x0f]);
1086 }
1087
1088 return str;
1089}
1090
1091//------------------------------------------------------------------------------
1094inline void
1096{
1097 this->AppendRange(&val, 1);
1098}
1099
1100//------------------------------------------------------------------------------
1103inline void
1105{
1106 this->Append(FromInt(val));
1107}
1108
1109//------------------------------------------------------------------------------
1112inline void
1114{
1115 this->Append(FromByte(val));
1116}
1117
1118//------------------------------------------------------------------------------
1121inline void
1123{
1124 this->Append(FromUByte(val));
1125}
1126
1127//------------------------------------------------------------------------------
1130inline void
1132{
1133 this->Append(FromFloat(val));
1134}
1135
1136//------------------------------------------------------------------------------
1139inline void
1141{
1142 this->Append(FromBool(val));
1143}
1144
1145#if !__OSX__
1146//------------------------------------------------------------------------------
1149inline void
1151{
1152 this->Append(FromVec2(val));
1153}
1154
1155//------------------------------------------------------------------------------
1158inline void
1160{
1161 this->Append(FromVec3(val));
1162}
1163
1164//------------------------------------------------------------------------------
1167inline void
1169{
1170 this->Append(FromVec4(val));
1171}
1172
1173//------------------------------------------------------------------------------
1176inline void
1178{
1179 this->Append(FromMat4(val));
1180}
1181#endif
1182
1183
1184//------------------------------------------------------------------------------
1187constexpr uint
1188String::Hash(const char* c, std::size_t s)
1189{
1190 uint hash = 0;
1191 std::size_t i;
1192 for (i = 0; i < s; i++)
1193 {
1194 hash += c[i];
1195 hash += hash << 10;
1196 hash ^= hash >> 6;
1197 }
1198 hash += hash << 3;
1199 hash ^= hash >> 11;
1200 hash += hash << 15;
1201 return hash;
1202}
1203
1205
1206} // namespace Util
1207
1208
1209//------------------------------------------------------------------------------
1213Util::String operator ""_str(const char* c, std::size_t s);
1214
1215//------------------------------------------------------------------------------
1219constexpr uint
1220operator ""_hash(const char* c, std::size_t s)
1221{
1222 return Util::String::Hash(c, s);
1223}
1224
1225//------------------------------------------------------------------------------
1226
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
Half precision (16 bit) float implementation.
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:1204
Definition scalar.h:58
Definition scalar.h:67
Definition scalar.h:76
A 4x4 single point precision float matrix.
Definition mat4.h:47
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:39
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:985
void SetInt(int val)
set as int value
Definition string.cc:1384
Math::mat4 AsMat4() const
return contents as mat4
Definition string.cc:705
Util::Blob AsBlob() const
return contents as blob
Definition string.cc:1210
static bool IsAlpha(char c)
test if provided character is an alphabet character (A..Z, a..z)
Definition string.cc:1082
static String FromUByte(ubyte i)
construct a string from a ubyte
Definition string.h:852
void SetShort(short val)
set as short value
Definition string.cc:1366
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:1584
String ExtractToLastSlash() const
extract path until last slash
Definition string.h:775
static String FromUInt(uint i)
construct a string from a uint
Definition string.h:896
void FirstCharToUpper()
convert first char of string to upper case
Definition string.cc:941
static String FromFloat2(const Math::float2 &v)
construct a string from float2
Definition string.h:1007
void Clear()
clear the string
Definition string.h:664
void SetTransform44(const Math::transform44 &v)
set as transform44 value
Definition string.cc:1556
~String()
destructor
Definition string.h:467
static const char * StrChr(const char *str, int c)
find character in string
Definition string.cc:1138
void AppendVec4(const Math::vec4 &v)
append vec4 value
Definition string.h:1168
SizeT Length() const
return length of string
Definition string.h:655
@ LocalStringSize
Definition string.h:427
size_t length() const
Definition string.h:390
void AppendChar(char val)
append character
Definition string.h:1095
bool IsValidBool() const
return true if the content is a valid bool
Definition string.cc:994
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:962
static String FromByte(byte i)
construct a string from a byte
Definition string.h:841
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:1131
void AppendByte(byte val)
append byte value
Definition string.h:1113
static String FromQuat(const Math::quat &q)
construct a string from quat
Definition string.h:1040
void ConvertBackslashes()
convert backslashes to slashes
Definition string.h:733
void SetVec2(const Math::vec2 &v)
set as vec2 value
Definition string.cc:1477
int strLen
Definition String.cs:11
static String FromDouble(double f)
construct a string from a double
Definition string.h:951
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:682
void StripFileExtension()
remove file extension
Definition string.cc:801
void SetBool(bool val)
set as bool value
Definition string.cc:1447
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:1140
static String FromTransform44(const Math::transform44 &m)
construct a string from transform44
Definition string.h:1062
void SetDouble(double val)
set as double value
Definition string.cc:1438
void AppendVec2(const Math::vec2 &v)
append vec2 value
Definition string.h:1150
bool AsBool() const
return contents as bool
Definition string.cc:1051
void SetLongLong(long long val)
set as long long value
Definition string.cc:1420
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:1073
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:1522
char operator[](IndexT i) const
read-only index operator
Definition string.h:633
void Fill(SizeT length, unsigned char character)
set string length and fill all characters with arg
Definition string.cc:1463
bool IsValidInt() const
return true if the content is a valid integer
Definition string.h:813
static String FromInt(int i)
construct a string from an int
Definition string.h:885
static String FromFloat(float f)
construct a string from a float
Definition string.h:940
static String FromVec4(const Math::vec4 &v)
construct a string from vec4
Definition string.h:996
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:1042
String()
constructor
Definition string.h:439
void ChangeAssignPrefix(const Util::String &newPref)
change assign prefix
Definition string.cc:1175
void ReplaceIllegalFilenameChars(char replacement)
replace illegal filename characters
Definition string.h:832
void Delete()
delete contents
Definition string.h:451
Util::String AsBase64() const
return contents as base64 string
Definition string.cc:1244
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:1651
bool CheckFileExtension(const String &ext) const
check file extension
Definition string.h:742
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:753
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:1261
void SetMat4(const Math::mat4 &v)
set as mat4 value
Definition string.cc:1540
bool IsValidFloat() const
return true if the content is a valid float
Definition string.h:823
void SetSizeT(size_t val)
set as long value
Definition string.cc:1411
Math::float3 AsFloat3() const
return contents as vec3
Definition string.cc:1677
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:1280
Math::vec2 AsVec2() const
return contents as vec2
Definition string.cc:1622
static String FromFloat3(const Math::float3 &v)
construct a string from float2
Definition string.h:1018
void ChangeFileExtension(const Util::String &newExt)
change file extension
Definition string.cc:1165
static bool IsUpper(char c)
test if provided character is an upper-case character
Definition string.cc:1109
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:615
Math::float4 AsFloat4() const
return contents as vec4
Definition string.cc:1690
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:1122
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:1188
static int StrCmp(const char *str0, const char *str1)
lowlevel string compare wrapper function
Definition string.cc:1118
char * GetLastSlash() const
get pointer to last directory separator
Definition string.cc:981
SizeT heapBufferSize
Definition string.h:432
static String From(const T &t)
convert from "anything"
void operator=(const String &rhs)
assignment operator
Definition string.h:565
void SetLong(long val)
set as long value
Definition string.cc:1402
static String FromLongLong(long long i)
construct a string from a long long
Definition string.h:929
void SetByte(byte val)
set as byte value
Definition string.cc:1348
Math::float2 AsFloat2() const
return contents as vec2
Definition string.cc:1664
static String FromMat4(const Math::mat4 &m)
construct a string from mat4
Definition string.h:1051
int AsInt() const
return contents as integer
Definition string.cc:1018
void SetVec3(const Math::vec3 &v)
set as vec3 value
Definition string.cc:1486
void SetUInt(uint val)
set as uint value
Definition string.cc:1393
static String FromBlob(const Util::Blob &b)
create from blob
Definition string.cc:1185
static String FromShort(short i)
construct a string from a short
Definition string.h:863
void AppendVec3(const Math::vec3 &v)
append vec3 value
Definition string.h:1159
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:874
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:1495
void AppendMat4(const Math::mat4 &v)
append mat4 value
Definition string.h:1177
const char * AsCharPtr() const
return contents as character pointer
Definition string.h:540
void AppendInt(int val)
append int value
Definition string.h:1104
static String FromVec2(const Math::vec2 &v)
construct a string from vec2
Definition string.h:974
void Realloc(SizeT newSize)
(re-)allocate the string buffer (copies old content)
Definition string.cc:1303
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:1429
static int StrLen(const char *str)
lowlevel string length function
Definition string.cc:1128
char * heapBuffer
Definition string.h:429
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:1148
void SetFloat2(const Math::float2 &v)
set as vec2 value
Definition string.cc:1504
bool IsValidTransform44() const
return true if content is a valid transform44
Definition string.cc:1608
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:1596
const char * Get() const
*** OBSOLETE *** only Nebula2 compatibility
Definition string.h:556
static bool IsLower(char c)
test if provided character is a lower case character
Definition string.cc:1100
bool IsEmpty() const
return true if string object is empty
Definition string.h:673
String GetFileExtension() const
get filename extension without dot
Definition string.cc:964
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:907
char localBuffer[LocalStringSize]
Definition string.h:430
void operator+=(const String &rhs)
+= operator
Definition string.h:624
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:1531
const char * c_str() const
helpers to interface with libraries that expect std::string like apis
Definition string.h:388
static String FromSize(size_t i)
construct a string from a size_t
Definition string.h:918
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:693
void SubstituteChar(char c, char subst)
substitute every occurance of a character with another character
Definition string.h:715
static String Hex(INTEGER i)
construct a hex string from an int
Definition string.h:1075
void SetUByte(ubyte val)
set as ubyte value
Definition string.cc:1357
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:1030
void SetUShort(ushort val)
set as ushort value
Definition string.cc:1375
static String FromFloat4(const Math::float4 &v)
construct a string from float2
Definition string.h:1029
Math::vec3 AsVec3() const
return contents as vec3
Definition string.cc:1635
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:796
bool IsValid() const
generic valid checker
bool empty() const
Definition string.h:392
SizeT strLen
Definition string.h:431
void Reserve(SizeT newSize)
reserve internal buffer size to prevent heap allocs
Definition string.cc:1336
bool ContainsCharFromSet(const String &charSet) const
returns true if string contains any character from set
Definition string.cc:952
void SetFloat3(const Math::float3 &v)
set as vec3 value
Definition string.cc:1513
static bool IsAlNum(char c)
test if provided character is an alpha-numeric character (A..Z,a..z,0..9)
Definition string.cc:1091
bool IsValidVec2() const
return true if the content is a valid vec2
Definition string.cc:1572
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