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 String StripSubpath(const String& subpath) const;
389 void ReplaceIllegalFilenameChars(char replacement);
390
392 inline const char* c_str() const { return this->AsCharPtr(); }
394 inline size_t length() const { return this->Length(); }
396 inline bool empty() const { return this->IsEmpty(); }
398 inline const char* data() const { return this->AsCharPtr(); }
399
401 static bool IsDigit(char c);
403 static bool IsAlpha(char c);
405 static bool IsAlNum(char c);
407 static bool IsLower(char c);
409 static bool IsUpper(char c);
410
412 static int StrCmp(const char* str0, const char* str1);
414 static int StrLen(const char* str);
416 static const char* StrChr(const char* str, int c);
417
420
421private:
423 void Delete();
425 char* GetLastSlash() const;
427 void Alloc(SizeT size);
429 void Realloc(SizeT newSize);
430
431 enum
432 {
434 };
439};
440
441//------------------------------------------------------------------------------
444inline
446 heapBuffer(nullptr),
447 strLen(0),
449{
450 this->localBuffer[0] = 0;
451}
452
453//------------------------------------------------------------------------------
456inline void
458{
459 if (this->heapBuffer)
460 {
462 this->heapBuffer = nullptr;
463 }
464 this->localBuffer[0] = 0;
465 this->strLen = 0;
466 this->heapBufferSize = 0;
467}
468
469//------------------------------------------------------------------------------
472inline
474{
475 this->Delete();
476}
477
478//------------------------------------------------------------------------------
481inline
482String::String(const char* str) :
483 heapBuffer(0),
484 strLen(0),
486{
487 this->localBuffer[0] = 0;
488 this->SetCharPtr(str);
489}
490
491//------------------------------------------------------------------------------
494inline
495String::String(const char* str, size_t len) :
496 heapBuffer(0),
497 strLen(0),
499{
500 this->localBuffer[0] = 0;
501 this->Set(str, (SizeT)len);
502}
503
504
505//------------------------------------------------------------------------------
508inline
510 heapBuffer(0),
511 strLen(0),
513{
514 this->localBuffer[0] = 0;
515 this->SetCharPtr(rhs.AsCharPtr());
516}
517
518//------------------------------------------------------------------------------
521inline
522String::String(String&& rhs) noexcept:
523 heapBuffer(rhs.heapBuffer),
524 strLen(rhs.strLen),
525 heapBufferSize(rhs.heapBufferSize)
526{
527 if (rhs.heapBuffer)
528 {
529 rhs.heapBuffer = nullptr;
530 this->localBuffer[0] = 0;
531 }
532 else
533 {
534 if (this->strLen > 0)
535 {
536 Memory::Copy(rhs.localBuffer, this->localBuffer, this->strLen);
537 }
538 this->localBuffer[this->strLen] = 0;
539 }
540}
541
542//------------------------------------------------------------------------------
545inline const char*
547{
548 if (this->heapBuffer)
549 {
550 return this->heapBuffer;
551 }
552 else
553 {
554 return this->localBuffer;
555 }
556}
557
558//------------------------------------------------------------------------------
561inline const char*
563{
564 return this->AsCharPtr();
565}
566
567//------------------------------------------------------------------------------
570inline void
572{
573 if (&rhs != this)
574 {
575 this->SetCharPtr(rhs.AsCharPtr());
576 }
577}
578
579//------------------------------------------------------------------------------
582inline void
584{
585 if (&rhs != this)
586 {
587 this->Delete();
588 this->strLen = rhs.strLen;
589 rhs.strLen = 0;
590 if (rhs.heapBuffer)
591 {
592 this->heapBuffer = rhs.heapBuffer;
593 this->heapBufferSize = rhs.heapBufferSize;
594 rhs.heapBuffer = nullptr;
595 rhs.heapBufferSize = 0;
596 }
597 else
598 {
599 if (this->strLen > 0)
600 {
601 Memory::Copy(rhs.localBuffer, this->localBuffer, this->strLen);
602 }
603 this->localBuffer[this->strLen] = 0;
604 }
605 }
606}
607
608//------------------------------------------------------------------------------
611inline void
612String::operator=(const char* cStr)
613{
614 this->SetCharPtr(cStr);
615}
616
617//------------------------------------------------------------------------------
620inline void
622{
623 this->AppendRange(str.AsCharPtr(), str.strLen);
624}
625
626//------------------------------------------------------------------------------
629inline void
631{
632 this->Append(rhs);
633}
634
635//------------------------------------------------------------------------------
638inline char
640{
641 n_assert(i <= this->strLen);
642 return this->AsCharPtr()[i];
643}
644
645//------------------------------------------------------------------------------
650inline char&
652{
653 n_assert(i <= this->strLen);
654 return (char&)(this->AsCharPtr())[i];
655}
656
657//------------------------------------------------------------------------------
660inline SizeT
662{
663 return this->strLen;
664}
665
666//------------------------------------------------------------------------------
669inline void
671{
672 this->Delete();
673}
674
675//------------------------------------------------------------------------------
678inline bool
680{
681 return (0 == this->strLen);
682}
683
684//------------------------------------------------------------------------------
687inline bool
689{
690 return (0 != this->strLen);
691}
692
693//------------------------------------------------------------------------------
698inline uint32_t
700{
701 const char* ptr = this->AsCharPtr();
702 return Hash(ptr, this->strLen);
703}
704
705//------------------------------------------------------------------------------
708static inline String
709operator+(const String& s0, const String& s1)
710{
711 String newString = s0;
712 newString.Append(s1);
713 return newString;
714}
715
716//------------------------------------------------------------------------------
720inline void
721String::SubstituteChar(char c, char subst)
722{
723 char* ptr = const_cast<char*>(this->AsCharPtr());
724 IndexT i;
725 for (i = 0; i <= this->strLen; i++)
726 {
727 if (ptr[i] == c)
728 {
729 ptr[i] = subst;
730 }
731 }
732}
733
734//------------------------------------------------------------------------------
738inline void
740{
741 this->SubstituteChar('\\', '/');
742}
743
744//------------------------------------------------------------------------------
747inline bool
749{
750 return (this->GetFileExtension() == ext);
751}
752
753//------------------------------------------------------------------------------
758inline String
760{
761 String pathString;
762 const char* lastSlash = this->GetLastSlash();
763 if (lastSlash)
764 {
765 pathString = &(lastSlash[1]);
766 }
767 else
768 {
769 pathString = *this;
770 }
771 return pathString;
772}
773
774//------------------------------------------------------------------------------
780inline String
782{
783 String pathString(*this);
784 char* lastSlash = pathString.GetLastSlash();
785 if (lastSlash)
786 {
787 lastSlash[1] = 0;
788 }
789 else
790 {
791 pathString = "";
792 }
793 return pathString;
794}
795
796//------------------------------------------------------------------------------
799inline String
800String::StripSubpath(const String& subpath) const
801{
802 String copy = *this;
803 copy.ConvertBackslashes();
804 IndexT it = 0;
805 while (it < copy.strLen && it < subpath.strLen)
806 {
807 if (subpath[it] != copy[it])
808 break;
809 it++;
810 }
811 while (copy[it] == '/')
812 it++;
813 return copy.ExtractToEnd(it);
814}
815
816//------------------------------------------------------------------------------
821inline bool
823{
824 IndexT i;
825 for (i = 0; i < this->strLen; i++)
826 {
827 if (InvalidIndex == charSet.FindCharIndex((*this)[i], 0))
828 {
829 return false;
830 }
831 }
832 return true;
833}
834
835//------------------------------------------------------------------------------
838inline bool
840{
841 return this->CheckValidCharSet(" \t-+01234567890");
842}
843
844//------------------------------------------------------------------------------
848inline bool
850{
851 return this->CheckValidCharSet(" \t-+.e1234567890");
852}
853
854//------------------------------------------------------------------------------
857inline void
859{
860 this->ReplaceChars("\\/:*?\"<>|", replacement);
861}
862
863//------------------------------------------------------------------------------
866inline String
868{
869 String str;
870 str.SetByte(i);
871 return str;
872}
873
874//------------------------------------------------------------------------------
877inline String
879{
880 String str;
881 str.SetUByte(i);
882 return str;
883}
884
885//------------------------------------------------------------------------------
888inline String
890{
891 String str;
892 str.SetShort(i);
893 return str;
894}
895
896//------------------------------------------------------------------------------
899inline String
901{
902 String str;
903 str.SetUShort(i);
904 return str;
905}
906
907//------------------------------------------------------------------------------
910inline String
912{
913 String str;
914 str.SetInt(i);
915 return str;
916}
917
918//------------------------------------------------------------------------------
921inline String
923{
924 String str;
925 str.SetUInt(i);
926 return str;
927}
928
929//------------------------------------------------------------------------------
932inline String
934{
935 String str;
936 str.SetLong(i);
937 return str;
938}
939
940//------------------------------------------------------------------------------
943inline String
945{
946 String str;
947 str.SetSizeT(i);
948 return str;
949}
950
951//------------------------------------------------------------------------------
954inline Util::String
956{
957 String str;
958 str.SetLongLong(i);
959 return str;
960}
961
962//------------------------------------------------------------------------------
965inline String
967{
968 String str;
969 str.SetFloat(f);
970 return str;
971}
972
973//------------------------------------------------------------------------------
976inline String
978{
979 String str;
980 str.SetDouble(i);
981 return str;
982}
983
984//------------------------------------------------------------------------------
987inline String
989{
990 String str;
991 str.SetBool(b);
992 return str;
993}
994
995#if !__OSX__
996//------------------------------------------------------------------------------
999inline String
1001{
1002 String str;
1003 str.SetVec2(v);
1004 return str;
1005}
1006
1007//------------------------------------------------------------------------------
1010inline String
1012{
1013 String str;
1014 str.SetVec3(v);
1015 return str;
1016}
1017
1018//------------------------------------------------------------------------------
1021inline String
1023{
1024 String str;
1025 str.SetVec4(v);
1026 return str;
1027}
1028
1029//------------------------------------------------------------------------------
1032inline String
1034{
1035 String str;
1036 str.SetFloat2(v);
1037 return str;
1038}
1039
1040//------------------------------------------------------------------------------
1043inline String
1045{
1046 String str;
1047 str.SetFloat3(v);
1048 return str;
1049}
1050
1051//------------------------------------------------------------------------------
1054inline String
1056{
1057 String str;
1058 str.SetFloat4(v);
1059 return str;
1060}
1061
1062//------------------------------------------------------------------------------
1065inline String
1067{
1068 String str;
1069 str.SetQuaternion(q);
1070 return str;
1071}
1072
1073//------------------------------------------------------------------------------
1076inline String
1078{
1079 String str;
1080 str.SetMat4(m);
1081 return str;
1082}
1083
1084//------------------------------------------------------------------------------
1087inline String
1089{
1090 String str;
1091 str.SetTransform44(t);
1092 return str;
1093}
1094#endif
1095
1096//------------------------------------------------------------------------------
1099template<typename INTEGER>
1100inline String
1101String::Hex(INTEGER i)
1102{
1103 constexpr SizeT hexLength = sizeof(INTEGER) << 1;
1104 static Util::String digits = "0123456789ABCDEF";
1105
1106 String str("0x");
1107 str.Reserve(hexLength + 2);
1108
1109 for (SizeT n = 0, j = (hexLength - 1) * 4; n < hexLength; ++n, j -= 4)
1110 {
1111 str.AppendChar(digits[(i >> j) & 0x0f]);
1112 }
1113
1114 return str;
1115}
1116
1117//------------------------------------------------------------------------------
1120inline void
1122{
1123 this->AppendRange(&val, 1);
1124}
1125
1126//------------------------------------------------------------------------------
1129inline void
1131{
1132 this->Append(FromInt(val));
1133}
1134
1135//------------------------------------------------------------------------------
1138inline void
1140{
1141 this->Append(FromByte(val));
1142}
1143
1144//------------------------------------------------------------------------------
1147inline void
1149{
1150 this->Append(FromUByte(val));
1151}
1152
1153//------------------------------------------------------------------------------
1156inline void
1158{
1159 this->Append(FromFloat(val));
1160}
1161
1162//------------------------------------------------------------------------------
1165inline void
1167{
1168 this->Append(FromBool(val));
1169}
1170
1171#if !__OSX__
1172//------------------------------------------------------------------------------
1175inline void
1177{
1178 this->Append(FromVec2(val));
1179}
1180
1181//------------------------------------------------------------------------------
1184inline void
1186{
1187 this->Append(FromVec3(val));
1188}
1189
1190//------------------------------------------------------------------------------
1193inline void
1195{
1196 this->Append(FromVec4(val));
1197}
1198
1199//------------------------------------------------------------------------------
1202inline void
1204{
1205 this->Append(FromMat4(val));
1206}
1207#endif
1208
1209
1210//------------------------------------------------------------------------------
1213constexpr uint
1214String::Hash(const char* c, std::size_t s)
1215{
1216 uint hash = 0;
1217 std::size_t i;
1218 for (i = 0; i < s; i++)
1219 {
1220 hash += c[i];
1221 hash += hash << 10;
1222 hash ^= hash >> 6;
1223 }
1224 hash += hash << 3;
1225 hash ^= hash >> 11;
1226 hash += hash << 15;
1227 return hash;
1228}
1229
1231
1232} // namespace Util
1233
1234
1235//------------------------------------------------------------------------------
1239Util::String operator ""_str(const char* c, std::size_t s);
1240
1241//------------------------------------------------------------------------------
1245constexpr uint
1246operator ""_hash(const char* c, std::size_t s)
1247{
1248 return Util::String::Hash(c, s);
1249}
1250
1251//------------------------------------------------------------------------------
1252
A 4x4 matrix which is described by translation, rotation and scale.
Definition transform44.h:20
The Util::Blob class encapsulates a chunk of raw memory into a C++ object which can be copied,...
Definition blob.h:22
A collection of key/value pairs with quick value retrieval by key at roughly O(log n).
Definition dictionary.h:34
#define n_assert(exp)
Definition debug.h:50
Different curves.
Definition angularpfeedbackloop.h:17
half operator+(half one, half two)
Definition half.h:105
void Copy(const void *from, void *to, size_t numBytes)
Copy a chunk of memory (note the argument order is different from memcpy()!
Definition osxmemory.cc:213
void Free(HeapType heapType, void *ptr)
Free a block of memory.
Definition osxmemory.cc:136
@ StringDataHeap
Definition osxmemoryconfig.h:31
A pinned array is an array which manages its own virtual memory.
Definition String.cs:6
auto Format
Definition string.h:1230
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:1377
static String FromBase64(const String &)
create from base64
Definition string.cc:1272
static String FromFloat(float f)
construct a string from a float
Definition string.h:966
void Clear()
clear the string
Definition string.h:670
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:889
void TrimRight(const String &charSet)
delete characters from charset at right side of string
Definition string.cc:440
Util::Blob AsBlob() const
return contents as blob
Definition string.cc:1221
static String FromVec3(const Math::vec3 &v)
construct a string from vec3
Definition string.h:1011
~String()
destructor
Definition string.h:473
void SetFloat3(const Math::float3 &v)
set as vec3 value
Definition string.cc:1524
static const char * StrChr(const char *str, int c)
find character in string
Definition string.cc:1149
static String FromVec4(const Math::vec4 &v)
construct a string from vec4
Definition string.h:1022
void SetSizeT(size_t val)
set as long value
Definition string.cc:1422
static String FromVec2(const Math::vec2 &v)
construct a string from vec2
Definition string.h:1000
static String FromUInt(uint i)
construct a string from a uint
Definition string.h:922
void ChangeFileExtension(const Util::String &newExt)
change file extension
Definition string.cc:1176
void AppendChar(char val)
append character
Definition string.h:1121
static String Concatenate(const Array< String > &strArray, const String &whiteSpace)
concatenate array of strings into new string
Definition string.cc:732
void Trim(const String &charSet)
trim characters from charset at both sides of string
Definition string.cc:483
static Dictionary< String, String > ParseKeyValuePairs(const String &str)
parse key/value pair string ("key0=value0 key1=value1")
Definition string.cc:1159
friend bool operator!=(const String &a, const String &b)
inequality operator
Definition string.cc:858
void SetBool(bool val)
set as bool value
Definition string.cc:1458
void Alloc(SizeT size)
allocate the string buffer (discards old content)
Definition string.cc:1291
static bool IsAlNum(char c)
test if provided character is an alpha-numeric character (A..Z,a..z,0..9)
Definition string.cc:1102
void SetUShort(ushort val)
set as ushort value
Definition string.cc:1386
void SetLongLong(long long val)
set as long long value
Definition string.cc:1431
const char * Get() const
*** OBSOLETE *** only Nebula2 compatibility
Definition string.h:562
static String FromLongLong(long long i)
construct a string from a long long
Definition string.h:955
bool AsBool() const
return contents as bool
Definition string.cc:1062
void ReplaceIllegalFilenameChars(char replacement)
replace illegal filename characters
Definition string.h:858
void SubstituteString(const String &str, const String &substStr)
substitute every occurance of a string with another string
Definition string.cc:494
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:885
static String FromSize(size_t i)
construct a string from a size_t
Definition string.h:944
void Realloc(SizeT newSize)
(re-)allocate the string buffer (copies old content)
Definition string.cc:1314
void AppendVec4(const Math::vec4 &v)
append vec4 value
Definition string.h:1194
static int StrCmp(const char *str0, const char *str1)
lowlevel string compare wrapper function
Definition string.cc:1129
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:992
static String FromBlob(const Util::Blob &b)
create from blob
Definition string.cc:1196
friend bool operator==(const String &a, const String &b)
equality operator
Definition string.cc:820
void SetInt(int val)
set as int value
Definition string.cc:1395
void CamelCaseToWords()
insert spaces before each capital letter in the string.
Definition string.cc:941
Math::vec2 AsVec2() const
return contents as vec2
Definition string.cc:1633
String StripSubpath(const String &subpath) const
strip subpath
Definition string.h:800
static bool IsUpper(char c)
test if provided character is an upper-case character
Definition string.cc:1120
void Reserve(SizeT newSize)
reserve internal buffer size to prevent heap allocs
Definition string.cc:1347
long long AsLongLong() const
return contents as long long
Definition string.cc:1041
String GetFileExtension() const
get filename extension without dot
Definition string.cc:975
String ExtractRange(IndexT fromIndex, SizeT numChars) const
extract substring
Definition string.cc:294
void Delete()
delete contents
Definition string.h:457
void SetVec3(const Math::vec3 &v)
set as vec3 value
Definition string.cc:1497
void StripAssignPrefix()
remove assign prefix (for example tex:)
Definition string.cc:806
void SetLong(long val)
set as long value
Definition string.cc:1413
int heapBufferSize
Definition String.cs:12
void Capitalize()
convert first char of string to upper case
Definition string.cc:931
Math::float4 AsFloat4() const
return contents as vec4
Definition string.cc:1701
const char * AsCharPtr() const
return contents as character pointer
Definition string.h:546
static bool MatchPattern(const String &str, const String &pattern)
pattern matching
Definition string.cc:597
Math::mat4 AsMat4() const
return contents as mat4
Definition string.cc:695
static bool IsAlpha(char c)
test if provided character is an alphabet character (A..Z, a..z)
Definition string.cc:1093
static bool IsLower(char c)
test if provided character is a lower case character
Definition string.cc:1111
int AsInt() const
return contents as integer
Definition string.cc:1029
bool IsValidTransform44() const
return true if content is a valid transform44
Definition string.cc:1619
void SubstituteChar(char c, char subst)
substitute every occurance of a character with another character
Definition string.h:721
void TrimLeft(const String &charSet)
delete characters from charset at left side of string
Definition string.cc:398
void SetVec4(const Math::vec4 &v)
set as vec4 value
Definition string.cc:1506
static String From(const T &t)
convert from "anything"
char localBuffer[LocalStringSize]
Definition string.h:436
void Append(const T &t)
generic append
void AppendBool(bool val)
append bool value
Definition string.h:1166
static String FromQuat(const Math::quat &q)
construct a string from quat
Definition string.h:1066
int strLen
Definition String.cs:11
static String FromLong(long i)
construct a string from a long
Definition string.h:933
void ReplaceChars(const String &charSet, char replacement)
replace any char set character within a string with the replacement character
Definition string.cc:672
friend bool operator<(const String &a, const String &b)
less-then operator
Definition string.cc:867
bool IsValidVec2() const
return true if the content is a valid vec2
Definition string.cc:1583
void AppendUByte(ubyte val)
append unsigned byte value
Definition string.h:1148
void operator+=(const String &rhs)
+= operator
Definition string.h:630
void ConvertBackslashes()
convert backslashes to slashes
Definition string.h:739
void SetUByte(ubyte val)
set as ubyte value
Definition string.cc:1368
static String FromInt(int i)
construct a string from an int
Definition string.h:911
bool ContainsCharFromSet(const String &charSet) const
returns true if string contains any character from set
Definition string.cc:963
static String FromUShort(ushort i)
construct a string from a ushort
Definition string.h:900
bool IsValidVec4() const
return true if the content is a valid vec4
Definition string.cc:1595
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:1488
bool IsValidBool() const
return true if the content is a valid bool
Definition string.cc:1005
Math::float2 AsFloat2() const
return contents as vec2
Definition string.cc:1675
bool IsValidInt() const
return true if the content is a valid integer
Definition string.h:839
String ExtractDirName() const
extract the part before the last directory separator
Definition string.cc:570
uint32_t HashCode() const
return a 32-bit hash code for the string
Definition string.h:699
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:1533
String ExtractFileName() const
extract the part after the last directory separator
Definition string.h:759
static String FromFloat2(const Math::float2 &v)
construct a string from float2
Definition string.h:1033
bool IsValid() const
return true if string object is not empty
Definition string.h:688
static String FromDouble(double f)
construct a string from a double
Definition string.h:977
void SetFloat(float val)
set as float value
Definition string.cc:1440
static String FromByte(byte i)
construct a string from a byte
Definition string.h:867
static int StrLen(const char *str)
lowlevel string length function
Definition string.cc:1139
size_t length() const
Definition string.h:394
bool CopyToBuffer(char *buf, SizeT bufSize) const
copy to char buffer (return false if buffer is too small)
Definition string.cc:38
void operator=(const String &rhs)
assignment operator
Definition string.h:571
void ToLower()
convert string to lower case
Definition string.cc:903
void SetDouble(double val)
set as double value
Definition string.cc:1449
void Append(const String &str)
append string
Definition string.h:621
void SetUInt(uint val)
set as uint value
Definition string.cc:1404
static String FromFloat4(const Math::float4 &v)
construct a string from float2
Definition string.h:1055
@ LocalStringSize
Definition string.h:433
bool IsValidMat4() const
return true if content is a valid mat4
Definition string.cc:1607
static String FromBool(bool b)
construct a string from a bool
Definition string.h:988
char operator[](IndexT i) const
read-only index operator
Definition string.h:639
bool CheckFileExtension(const String &ext) const
check file extension
Definition string.h:748
void SetQuaternion(const Math::quat &v)
set as quaternion
Definition string.cc:1542
void SetByte(byte val)
set as byte value
Definition string.cc:1359
bool IsValid() const
generic valid checker
friend bool operator>(const String &a, const String &b)
greater-then operator
Definition string.cc:876
void SetFloat2(const Math::float2 &v)
set as vec2 value
Definition string.cc:1515
float AsFloat() const
return contents as float
Definition string.cc:1053
static String FromTransform44(const Math::transform44 &m)
construct a string from transform44
Definition string.h:1088
bool IsValidFloat() const
return true if the content is a valid float
Definition string.h:849
SizeT Length() const
return length of string
Definition string.h:661
const char * c_str() const
helpers to interface with libraries that expect std::string like apis
Definition string.h:392
void TerminateAtIndex(IndexT index)
terminate string at given index
Definition string.cc:778
T As() const
convert to "anything"
void AppendByte(byte val)
append byte value
Definition string.h:1139
static bool IsDigit(char c)
test if provided character is a digit (0..9)
Definition string.cc:1084
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:1646
Math::transform44 AsTransform44() const
return contents as transform44
Definition string.cc:712
String()
constructor
Definition string.h:445
void ChangeAssignPrefix(const Util::String &newPref)
change assign prefix
Definition string.cc:1186
void Fill(SizeT length, unsigned char character)
set string length and fill all characters with arg
Definition string.cc:1474
bool CheckValidCharSet(const String &charSet) const
return true if string only contains characters from charSet argument
Definition string.h:822
String ExtractLastDirName() const
extract the last directory of the path
Definition string.cc:530
Util::String AsBase64() const
return contents as base64 string
Definition string.cc:1255
const char * data() const
Definition string.h:398
void SetMat4(const Math::mat4 &v)
set as mat4 value
Definition string.cc:1551
bool empty() const
Definition string.h:396
bool BeginsWithString(const String &s) const
returns true if string begins with string
Definition string.cc:379
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:1688
static String FromFloat3(const Math::float3 &v)
construct a string from float2
Definition string.h:1044
char * heapBuffer
Definition string.h:435
void AppendMat4(const Math::mat4 &v)
append mat4 value
Definition string.h:1203
static constexpr uint Hash(const char *c, std::size_t s)
Hash a string.
Definition string.h:1214
static String FromUByte(ubyte i)
construct a string from a ubyte
Definition string.h:878
void SetCharPtr(const char *s)
set content to char ptr
Definition string.cc:753
static String Hex(INTEGER i)
construct a hex string from an int
Definition string.h:1101
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:1176
bool EndsWithString(const String &s) const
returns true if string ends with string
Definition string.cc:388
bool IsEmpty() const
return true if string object is empty
Definition string.h:679
friend bool operator>=(const String &a, const String &b)
greater-then operator
Definition string.cc:894
void AppendFloat(float val)
append float value
Definition string.h:1157
String ExtractToLastSlash() const
extract path until last slash
Definition string.h:781
void StripFileExtension()
remove file extension
Definition string.cc:791
Math::vec4 AsVec4() const
return contents as vec4
Definition string.cc:1662
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:1185
static String FromMat4(const Math::mat4 &m)
construct a string from mat4
Definition string.h:1077
void AppendInt(int val)
append int value
Definition string.h:1130
void ToUpper()
convert string to upper case
Definition string.cc:917
void SetTransform44(const Math::transform44 &v)
set as transform44 value
Definition string.cc:1567
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