27 template<
typename T = Char_8,
typename N = UInt_64>
43 : size(0), data(nullptr)
50 Str(
const T*
const str,
const N size)
51 : size(size), data(nullptr)
56 data =
new T[this->size + 1];
65 Str(
const T*
const str)
66 : size(
Len(str)), data(nullptr)
68 data =
new T[size + 1];
78 : size(size), data(new T[size + 1])
85 : size(str.size), data(str.data)
94 : size(str.size), data(new T[size + 1])
127 data =
new T[size + 1];
143 data =
new T[size + 1];
157 N inputSize =
Len(str);
159 T* result =
new T[size + inputSize + 1];
165 Util::Copy(&result[size], str, inputSize *
sizeof(T));
167 result[size + inputSize] = 0;
179 T* result =
new T[size + str.size + 1];
187 result[size + str.size] = 0;
258 #ifdef EHS_OS_WINDOWS
311 Util::Copy(&result.data[size], str, inSize *
sizeof(T));
313 result.data[size + inSize] = 0;
329 result.data[size + str.size] = 0;
398 #ifdef EHS_OS_WINDOWS
445 if (size !=
Len(str))
456 if (size !=
Len(str))
467 if (size != str.size)
478 if (size !=
Len(str))
489 if (size != str.size)
508 T* result =
new T[newSize + 1];
513 Util::Copy(result, data, newSize *
sizeof(T));
526 N
Size(
bool inBytes =
false)
const
529 return sizeof(T) * size;
539 T* result =
new T[size + 1];
553 if (dstOffset + src.size > size)
565 void Copy(
const N dstOffset,
const T*
const src)
567 N srcSize =
Len(src);
569 if (dstOffset + srcSize > size)
575 Util::Copy(&data[dstOffset], src, srcSize *
sizeof(T));
582 void Copy(
const N dstOffset,
const T*
const src,
const N srcSize)
584 if (dstOffset + srcSize > size)
590 Util::Copy(&data[dstOffset], src, srcSize *
sizeof(T));
601 N newSize = size + value.size;
603 T* result =
new T[newSize + 1];
609 Util::Copy(&result[index + value.size], &data[index], size - index);
621 void Insert(
const N index,
const T value)
624 if (index > size - 1)
625 newSize = size + ((index + 1) - size);
629 T* result =
new T[newSize + 1];
631 for (N i = 0; i < index; ++i)
634 result[index] = value;
636 for (N i = index; i < size; ++i)
637 result[i + 1] = data[i];
652 if (!size || start >= size || end > size || end <= start)
655 Str popped(&data[start], end - start);
657 N newSize = size - popped.size;
658 T* result =
new T[newSize + 1];
662 Util::Copy(&result[start], &data[end], (size - end) *
sizeof(T));
680 if (!size || index >= size)
683 popped = data[index];
685 N newSize = size - 1;
686 T* result =
new T[newSize];
688 for (N i = 0; i < index; ++i)
691 for (N i = index + 1; i < size; ++i)
692 result[i - 1] = data[i];
705 T* result =
new T[size + value.size + 1];
709 result[size + value.
Size()] = 0;
720 void Push(
const T*
const value,
const N size)
722 T* result =
new T[this->size + size + 1];
724 Util::Copy(&result[this->size], value, size *
sizeof(T));
726 result[this->size + size] = 0;
736 void Push(
const T*
const value)
738 N inSize =
Len(value);
740 T* result =
new T[size + inSize + 1];
742 Util::Copy(&result[size], value, inSize *
sizeof(T));
744 result[size + inSize] = 0;
756 T* result =
new T[size + 2];
760 result[size] = value;
761 result[size + 1] = 0;
773 T* result =
new T[size--];
775 T value = data[size];
805 for (N i = 0; i < size; ++i)
806 if (data[i] > 64 && data[i] < 91)
816 for (N i = 0; i < size; ++i)
817 if (data[i] > 64 && data[i] < 91)
818 result[i] = data[i] + 32;
828 for (N i = 0; i < size; ++i)
829 if (data[i] > 96 && data[i] < 123)
839 for (N i = 0; i < size; ++i)
840 if (data[i] > 96 && data[i] < 123)
841 result[i] = data[i] - 32;
851 if (size <= 1 || !data)
854 T* r =
new T[size + 1];
856 for (N i = 0; i < size; ++i)
857 r[i] = data[size - 1 - i];
870 if (size <= 1 || !data)
875 for (N i = 0; i < size; ++i)
876 r[i] = data[size - 1 - i];
887 if (index >= this->size)
896 if (size > this->size)
929 for (N i = 0, c = 0; i < size; ++i)
931 if (data[i] == delimeter[c])
933 if (++c == delimeter.
Size())
935 N r = i - (c - 1) - b;
944 if (max && result.
Size() == max)
967 for (N i = 0, b = 0, c = 0; i < size; ++i)
969 if (data[i] == delimeter[c])
971 if (++c == delimeter.
Size())
977 for (N d = c; d < 0; --d)
978 result[b++] = data[i - d];
980 result[b++] = data[i];
997 for (N i = 0, b = 0; i < size; ++i)
999 if (data[i] == delimeter[b])
1001 if (++b == delimeter.
Size())
1003 result.
Push(replacer);
1009 result.
Push(data[i]);
1026 for (N i = 0, c = 0; i < size; ++i)
1028 if (data[i] == delimeter[c])
1030 if (++c == delimeter.
Size())
1035 *index = i - (c - 1);
1052 for (N i = size, c = delimeter.
Size(); i > 0; --i)
1054 if (data[i - 1] == delimeter[c - 1])
1061 *index = i - (delimeter.
Size() - 1);
1088 for (N i = 0, c = 0; i < size; ++i)
1090 if (data[i] == delimeter[c])
1092 if (++c == delimeter.
Size())
1101 for (N i = size, c = delimeter.
Size(); i > 0; --i)
1103 if (data[i - 1] == delimeter[c - 1])
1119 T *quoteStart =
nullptr;
1120 T *spaceStart =
nullptr;
1122 for (T *i = data; i <= data + size; ++i)
1124 if (*i ==
'\"' && !spaceStart)
1128 args.
Push(
Str(quoteStart, i - quoteStart));
1129 quoteStart =
nullptr;
1133 if (i + 1 < &data[size - 1])
1139 else if (*i ==
' ' && !quoteStart)
1143 args.
Push(
Str(spaceStart, i - spaceStart));
1148 if (i + 1 < &data[size - 1])
1157 args.
Push(
Str(quoteStart, &data[size - 1] - (quoteStart - 1)));
1158 else if (spaceStart)
1159 args.
Push(
Str(spaceStart, &data[size - 1] - (spaceStart - 1)));
1171 if ((data[0] <
'0' || data[0] >
'9') && data[0] !=
'-' && data[0] !=
'.')
1174 for (N i = 1; i < size; ++i)
1175 if ((data[i] <
'0' || data[i] >
'9') && data[i] !=
'.')
1185 template<
typename I =
int>
1188 static const T hex[] =
"0123456789ABCDEF";
1190 Str result(
sizeof(I) * 2);
1192 for (
UInt_8 i = 0; i <
sizeof(I); ++i)
1194 result[i * 2] = hex[((
Byte*)&num)[i] / 16];
1195 result[i * 2 + 1] = hex[((
Byte*)&num)[i] % 16];
1205 template<
typename I =
int>
1211 if (in[offset] == 45)
1216 else if (in[offset] == 43)
1219 if (in[offset] == 48 && (in[offset + 1] == 88 || in[offset + 1] == 120))
1224 for (N i = offset; i < in.
Size(); ++i)
1228 if (in[i] > 47 && in[i] < 58)
1230 else if (in[i] > 64 && in[i] < 71)
1232 else if (in[i] > 96 && in[i] < 103)
1242 return neg ? -acc : acc;
1248 template<
typename I =
int>
1254 if (data[offset] == 45)
1259 else if (data[offset] == 43)
1262 if (data[offset] == 48 && (data[offset + 1] == 88 || data[offset + 1] == 120))
1267 for (N i = offset; i < size; ++i)
1271 if (data[i] > 47 && data[i] < 58)
1272 value = data[i] - 48;
1273 else if (data[i] > 64 && data[i] < 71)
1274 value = data[i] - 55;
1275 else if (data[i] > 96 && data[i] < 103)
1276 value = data[i] - 87;
1285 return neg ? -acc : acc;
1292 template<
typename I = N>
1300 for (N i = data[0] ==
'-' ? 1 : 0; i < size; ++i)
1301 r = r * 10 + data[i] -
'0';
1318 Find(ide, &decPoint);
1320 float result = 0.0f;
1321 float fraction = 0.0f;
1324 for (N i = 0; i < decPoint; ++i)
1325 result = result * 10.0f + data[i] -
'0';
1327 for (N i = decPoint + 1; i < size; ++i)
1329 fraction = fraction * 10.0f + data[i] -
'0';
1333 result += fraction / scale;
1347 Find(ide, &decPoint);
1349 double result = 0.0f;
1350 double fraction = 0.0f;
1351 double scale = 1.0f;
1353 for (N i = 0; i < decPoint; ++i)
1354 result = result * 10.0f + data[i] -
'0';
1356 for (N i = decPoint + 1; i < size; ++i)
1358 fraction = fraction * 10.0f + data[i] -
'0';
1362 result += fraction / scale;
1376 Find(ide, &decPoint);
1378 long double result = 0.0f;
1379 long double fraction = 0.0f;
1380 long double scale = 1.0f;
1382 for (N i = 0; i < decPoint; ++i)
1383 result = result * 10.0f + data[i] -
'0';
1385 for (N i = decPoint + 1; i < size; ++i)
1387 fraction = fraction * 10.0f + data[i] -
'0';
1391 result += fraction / scale;
1420 r[i++] = 48 + nonNeg % 10;
1446 UInt_64 nonNeg = num;
1452 r[i++] = 48 + nonNeg % 10;
1485 r[i++] = 48 + nonNeg % 10;
1517 r[i++] = 48 + nonNeg % 10;
1550 r[i++] = 48 + nonNeg % 10;
1582 r[i++] = 48 + nonNeg % 10;
1615 r[i++] = 48 + nonNeg % 10;
1647 r[i++] = 48 + nonNeg % 10;
1656 #ifdef EHS_OS_WINDOWS
1676 r[i++] = 48 + nonNeg % 10;
1682 return r.GetReverse();
1708 r[i++] = 48 + nonNeg % 10;
1717 return r.GetReverse();
1727 SInt_64 whole = (SInt_64)num;
1736 for (UInt_64 i = 0; i < (UInt_64)maxDecimals - 1; ++i)
1739 SInt_64 fraction = (SInt_64)((num - (
float)whole) * (
float)power);
1750 fResult[i++] = 48 + fraction % 10;
1754 while (i < maxDecimals)
1769 SInt_64 whole = (SInt_64)num;
1778 for (UInt_64 i = 0; i < (UInt_64)maxDecimals - 1; ++i)
1781 SInt_64 fraction = (SInt_64)((num - (
double)whole) * (
double)power);
1792 fResult[i++] = 48 + fraction % 10;
1796 while (i < maxDecimals)
1811 SInt_64 whole = (SInt_64)num;
1820 for (UInt_64 i = 0; i < (UInt_64)maxDecimals - 1; ++i)
1823 SInt_64 fraction = (SInt_64)((num - (
long double)whole) * (
long double)power);
1834 fResult[i++] = 48 + fraction % 10;
1838 while (i < maxDecimals)
1859 for (N i = 0; i < str.
Size(
true); ++i)
1860 hash = (hash ^ bytes[i]) * 16777619;
1876 for (N i = 0; i <
Size(
true); ++i)
1877 hash = (hash ^ bytes[i]) * 16777619;
1892 UInt_64 hash = 14695981039346656037ull;
1894 for (N i = 0; i < str.
Size(
true); ++i)
1895 hash = (hash ^ bytes[i]) * 1099511628211;
1909 UInt_64 hash = 14695981039346656037ull;
1911 for (N i = 0; i <
Size(
true); ++i)
1912 hash = (hash ^ bytes[i]) * 1099511628211;
1920 static N
Len(
const T*
const str)
1935 static bool Cmp(
const T*
const a,
const T*
const b)
1956template<
typename T = ehs::Char_8,
typename N = ehs::UInt_64>
1960 if (second.
Size() != inSize)
1966template<
typename T = ehs::Char_8,
typename N = ehs::UInt_64>
1970 if (second.
Size() != inSize)
1980template<
typename T = ehs::Char_8,
typename N = ehs::UInt_64>
1990 result[inSize + second.
Size()] = 0;
bool operator!=(const T *const first, const ehs::Str< T, N > &second)
Definition Str.h:1967
ehs::Str< T, N > operator+(const T *const first, const ehs::Str< T, N > &second)
Definition Str.h:1981
bool operator==(const T *const first, const ehs::Str< T, N > &second)
Definition Str.h:1957
UInt_64 Hash_64() const
Definition Str.h:1902
bool Contains(const Str< T, N > &delimeter, const SearchPattern pattern=SearchPattern::LEFT_RIGHT) const
Definition Str.h:1084
bool operator==(const T *const str) const
Definition Str.h:454
void Copy(const N dstOffset, const Str< T, N > &src)
Definition Str.h:551
Str< T, N > operator+(const UInt_16 num) const
Definition Str.h:377
static Str< T, N > FromNum(const SInt_64 num)
Definition Str.h:1399
bool Find(const Str< T, N > &delimeter, N *const index=nullptr, const SearchPattern pattern=SearchPattern::LEFT_RIGHT, const IndexResult result=IndexResult::BEGINNING) const
Definition Str.h:1022
Str< T, N > GetUpper() const
Definition Str.h:835
static bool Cmp(const T *const a, const T *const b)
Definition Str.h:1935
bool IsNum() const
Definition Str.h:1166
Vector< Str > ParseArgs() const
Definition Str.h:1116
void ToLower()
Converts all upper-case ASCII characters to lower-case.
Definition Str.h:803
Str & operator=(const Str &str)
Definition Str.h:119
void Insert(const N index, const Str &value)
Definition Str.h:596
bool operator==(T *str) const
Definition Str.h:443
Str< T, N > operator+(const Str< T, N > &str) const
Definition Str.h:321
void Insert(const N index, const T value)
Definition Str.h:621
Str< T, N > & operator+=(const long double num)
Definition Str.h:295
void Push(const T *const value, const N size)
Definition Str.h:720
bool operator!=(const T *const str) const
Definition Str.h:476
static Str< T, N > FromNum(const UInt_64 num)
Definition Str.h:1435
Str< T, N > operator+(const float num) const
Definition Str.h:419
void Push(const T *const value)
Definition Str.h:736
Str(const Str &str)
Definition Str.h:93
Str< T, N > GetLower() const
Definition Str.h:812
static UInt_64 Hash_64(const Str< T, N > &str)
Definition Str.h:1885
Str< T, N > & operator+=(const UInt_16 num)
Definition Str.h:237
Str< T, N > Sub(const N index, const N size=0) const
Definition Str.h:885
Str< T, N > operator+(const SInt_16 num) const
Definition Str.h:369
Str()
Default members initialization.
Definition Str.h:42
Str< T, N > & operator+=(const UInt_32 num)
Definition Str.h:221
static Str< T, N > FromNum(const UInt_8 num)
Definition Str.h:1630
Str< T, N > & operator+=(const SInt_64 num)
Definition Str.h:197
long double ToLDouble() const
Definition Str.h:1370
void ToUpper()
Converts all lower-case ASCII characters to upper-case.
Definition Str.h:826
static Str< T, N > FromNum(const UInt_16 num)
Definition Str.h:1565
bool operator!=(const Str< T, N > &str) const
Definition Str.h:487
void Push(const Str< T, N > &value)
Definition Str.h:703
void Reverse()
Reverses the entire string object.
Definition Str.h:849
static Str< T, N > FromNum(const SInt_32 num)
Definition Str.h:1464
Str< T, N > RemoveAll(const Str< T, N > &delimeter) const
Definition Str.h:963
static Str< T, N > FromNum(const SInt_16 num)
Definition Str.h:1529
bool operator==(const Str< T, N > &str) const
Definition Str.h:465
static Str< T, N > FromNum(const double num, const UInt_8 maxDecimals=5)
Definition Str.h:1767
Str ReplaceAll(const Str &delimeter, const Str &replacer) const
Definition Str.h:993
Str< T, N > & operator+=(const SInt_32 num)
Definition Str.h:213
static I HexToNum(const Str &in)
Definition Str.h:1206
static UInt_64 Len(const Char_32 *const str)
Definition Str.h:1920
I ToDecimal() const
Definition Str.h:1293
Str(Str &&str) noexcept
A move constructor.
Definition Str.h:84
Str< T, N > & operator+=(const double num)
Definition Str.h:287
Str< T, N > & operator+=(const Str< T, N > &str)
Definition Str.h:177
static Str< T, N > FromNum(const SInt_8 num)
Definition Str.h:1594
Str< T, N > operator+(const UInt_8 num) const
Definition Str.h:393
void Push(const T value)
Definition Str.h:754
Str< T, N > & operator+=(const UInt_64 num)
Definition Str.h:205
N Size(bool inBytes=false) const
Definition Str.h:526
Str< T, N > operator+(const SInt_64 num) const
Definition Str.h:337
Str(const T *const str)
Definition Str.h:65
static Str< T, N > FromNum(const long double num, const UInt_8 maxDecimals=5)
Definition Str.h:1809
Str< T, N > operator+(const UInt_64 num) const
Definition Str.h:345
const Byte * ToBytes() const
Definition Str.h:790
I HexToNum() const
Definition Str.h:1249
Str< T, N > operator+(const double num) const
Definition Str.h:427
Str< T, N > operator+(const SInt_8 num) const
Definition Str.h:385
double ToDouble() const
Definition Str.h:1341
Str< T, N > operator+(const SInt_32 num) const
Definition Str.h:353
void Copy(const N dstOffset, const T *const src)
Definition Str.h:565
Str< T, N > & operator+=(const T *const str)
Definition Str.h:155
T Remove(const N index)
Definition Str.h:676
Str< T, N > & operator+=(const SInt_8 num)
Definition Str.h:245
void Resize(const N newSize)
Definition Str.h:503
Str< T, N > operator+(const UInt_32 num) const
Definition Str.h:361
Str(const N size)
Definition Str.h:77
static Str NumToHex(const I num)
Definition Str.h:1186
static UInt_32 Hash_32(const Str< T, N > &str)
Definition Str.h:1850
Str< T, N > GetReverse()
Definition Str.h:868
Str< T, N > & operator+=(const float num)
Definition Str.h:279
Vector< Str< T, N >, N > Split(const Str< T, N > &delimeter, const N max=0) const
Definition Str.h:923
Str & operator=(Str &&str) noexcept
Definition Str.h:101
void ExactSize()
Finds the null terminator in the string and makes it the exact size if greater than.
Definition Str.h:535
UInt_32 Hash_32() const
Definition Str.h:1867
T Pop()
Definition Str.h:771
static Str< T, N > FromNum(const float num, const UInt_8 maxDecimals=5)
Definition Str.h:1725
~Str()
Frees any data created on the heap.
Definition Str.h:36
static Str< T, N > FromNum(const UInt_32 num)
Definition Str.h:1500
float ToFloat() const
Definition Str.h:1312
Str< T, N > operator+(const T *const str) const
Definition Str.h:303
Str< T, N > operator+(const long double num) const
Definition Str.h:435
Str< T, N > & operator=(const T *const str)
Definition Str.h:137
Str< T, N > & operator+=(const SInt_16 num)
Definition Str.h:229
Byte * ToBytes()
Definition Str.h:797
Str Remove(const N start, const N end)
Definition Str.h:650
void Copy(const N dstOffset, const T *const src, const N srcSize)
Definition Str.h:582
Str< T, N > & operator+=(const UInt_8 num)
Definition Str.h:253
Str(const T *const str, const N size)
Definition Str.h:50
static void Copy(void *out, const void *in, UInt_64 size)
Definition Util.cpp:67
static bool Compare(const void *a, const void *b, UInt_64 size)
Definition Util.cpp:9
void Push(const T *const value, const N size)
Definition Vector.h:389
N Size() const
Definition Vector.h:240
IndexResult
Definition Str.h:19
@ BEGINNING
Definition Str.h:20
@ ENDING
Definition Str.h:21
SearchPattern
Definition Str.h:13
@ RIGHT_LEFT
Definition Str.h:15
@ LEFT_RIGHT
Definition Str.h:14
signed int SInt_32
Definition Types.h:50
unsigned int UInt_32
Definition Types.h:49
Str< Char_16, UInt_64 > Str_16
Definition Str.h:1952
unsigned char UInt_8
Definition Types.h:43
Str< Char_8, UInt_64 > Str_8
Definition Str.h:1953
unsigned char Byte
Definition Types.h:39
signed char SInt_8
Definition Types.h:44
unsigned short UInt_16
Definition Types.h:46
Str< Char_32, UInt_64 > Str_32
Definition Str.h:1951
signed short SInt_16
Definition Types.h:47