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) ? size :
Len(str)), data(nullptr)
53 data =
new T[this->size + 1];
62 Str(
const T*
const str)
63 : size(
Len(str)), data(nullptr)
65 data =
new T[size + 1];
75 : size(size), data(new T[size + 1])
82 : size(str.size), data(str.data)
91 : size(str.size), data(new T[size + 1])
124 data =
new T[size + 1];
140 data =
new T[size + 1];
154 N inputSize =
Len(str);
156 T* result =
new T[size + inputSize + 1];
162 Util::Copy(&result[size], str, inputSize *
sizeof(T));
164 result[size + inputSize] = 0;
176 T* result =
new T[size + str.size + 1];
184 result[size + str.size] = 0;
255 #ifdef EHS_OS_WINDOWS
308 Util::Copy(&result.data[size], str, inSize *
sizeof(T));
310 result.data[size + inSize] = 0;
326 result.data[size + str.size] = 0;
395 #ifdef EHS_OS_WINDOWS
407 Str<T, N>
operator+(
const HRESULT num)
const
442 if (size !=
Len(str))
453 if (size !=
Len(str))
464 if (size != str.size)
475 if (size !=
Len(str))
486 if (size != str.size)
505 T* result =
new T[newSize + 1];
510 Util::Copy(result, data, newSize *
sizeof(T));
523 N
Size(
bool inBytes =
false)
const
526 return sizeof(T) * size;
536 T* result =
new T[size + 1];
550 if (dstOffset + src.size > size)
562 void Copy(
const N dstOffset,
const T*
const src)
564 N srcSize =
Len(src);
566 if (dstOffset + srcSize > size)
572 Util::Copy(&data[dstOffset], src, srcSize *
sizeof(T));
579 void Copy(
const N dstOffset,
const T*
const src,
const N srcSize)
581 if (dstOffset + srcSize > size)
587 Util::Copy(&data[dstOffset], src, srcSize *
sizeof(T));
598 N newSize = size + value.size;
600 T* result =
new T[newSize + 1];
606 Util::Copy(&result[index + value.size], &data[index], size - index);
618 void Insert(
const N index,
const T value)
621 if (index > size - 1)
622 newSize = size + ((index + 1) - size);
626 T* result =
new T[newSize + 1];
628 for (N i = 0; i < index; ++i)
631 result[index] = value;
633 for (N i = index; i < size; ++i)
634 result[i + 1] = data[i];
649 if (!size || start >= size || end > size || end <= start)
652 Str popped(&data[start], end - start);
654 N newSize = size - popped.size;
655 T* result =
new T[newSize + 1];
659 Util::Copy(&result[start], &data[end], (size - end) *
sizeof(T));
677 if (!size || index >= size)
680 popped = data[index];
682 N newSize = size - 1;
683 T* result =
new T[newSize];
685 for (N i = 0; i < index; ++i)
688 for (N i = index + 1; i < size; ++i)
689 result[i - 1] = data[i];
702 T* result =
new T[size + value.size + 1];
706 result[size + value.
Size()] = 0;
717 void Push(
const T*
const value,
const N size)
719 T* result =
new T[this->size + size + 1];
721 Util::Copy(&result[this->size], value, size *
sizeof(T));
723 result[this->size + size] = 0;
733 void Push(
const T*
const value)
735 N inSize =
Len(value);
737 T* result =
new T[size + inSize + 1];
739 Util::Copy(&result[size], value, inSize *
sizeof(T));
741 result[size + inSize] = 0;
753 T* result =
new T[size + 2];
757 result[size] = value;
758 result[size + 1] = 0;
770 T* result =
new T[size--];
772 T value = data[size];
802 for (N i = 0; i < size; ++i)
803 if (data[i] > 64 && data[i] < 91)
813 for (N i = 0; i < size; ++i)
814 if (data[i] > 64 && data[i] < 91)
815 result[i] = data[i] + 32;
825 for (N i = 0; i < size; ++i)
826 if (data[i] > 96 && data[i] < 123)
836 for (N i = 0; i < size; ++i)
837 if (data[i] > 96 && data[i] < 123)
838 result[i] = data[i] - 32;
848 if (size <= 1 || !data)
851 T* r =
new T[size + 1];
853 for (N i = 0; i < size; ++i)
854 r[i] = data[size - 1 - i];
867 if (size <= 1 || !data)
872 for (N i = 0; i < size; ++i)
873 r[i] = data[size - 1 - i];
884 if (index >= this->size)
893 if (size > this->size)
926 for (N i = 0, c = 0; i < size; ++i)
928 if (data[i] == ide[c])
930 if (++c == ide.
Size())
932 N r = i - (c - 1) - b;
941 if (max && result.
Size() == max)
964 for (N i = 0, b = 0, c = 0; i < size; ++i)
966 if (data[i] == ide[c])
968 if (++c == ide.
Size())
974 for (N d = c; d < 0; --d)
975 result[b++] = data[i - d];
977 result[b++] = data[i];
994 for (N i = 0, b = 0; i < size; ++i)
996 if (data[i] == ide[b])
998 if (++b == ide.
Size())
1000 result.
Push(replacer);
1006 result.
Push(data[i]);
1023 for (N i = 0, c = 0; i < size; ++i)
1025 if (data[i] == ide[c])
1027 if (++c == ide.
Size())
1032 *index = i - (c - 1);
1049 for (N i = size, c = ide.
Size(); i > 0; --i)
1051 if (data[i - 1] == ide[c - 1])
1058 *index = i - (ide.
Size() - 1);
1085 for (N i = 0, c = 0; i < size; ++i)
1087 if (data[i] == ide[c])
1089 if (++c == ide.
Size())
1098 for (N i = size, c = ide.
Size(); i > 0; --i)
1100 if (data[i - 1] == ide[c - 1])
1120 if ((data[0] <
'0' || data[0] >
'9') && data[0] !=
'-' && data[0] !=
'.')
1123 for (N i = 1; i < size; ++i)
1124 if ((data[i] <
'0' || data[i] >
'9') && data[i] !=
'.')
1134 template<
typename I =
int>
1137 static const T hex[] =
"0123456789ABCDEF";
1139 Str result(
sizeof(I) * 2);
1141 for (
UInt_8 i = 0; i <
sizeof(I); ++i)
1143 result[i * 2] = hex[((
Byte*)&num)[i] / 16];
1144 result[i * 2 + 1] = hex[((
Byte*)&num)[i] % 16];
1154 template<
typename I =
int>
1160 if (in[offset] == 45)
1165 else if (in[offset] == 43)
1168 if (in[offset] == 48 && (in[offset + 1] == 88 || in[offset + 1] == 120))
1173 for (N i = offset; i < in.
Size(); ++i)
1177 if (in[i] > 47 && in[i] < 58)
1179 else if (in[i] > 64 && in[i] < 71)
1181 else if (in[i] > 96 && in[i] < 103)
1191 return neg ? -acc : acc;
1197 template<
typename I =
int>
1203 if (data[offset] == 45)
1208 else if (data[offset] == 43)
1211 if (data[offset] == 48 && (data[offset + 1] == 88 || data[offset + 1] == 120))
1216 for (N i = offset; i < size; ++i)
1220 if (data[i] > 47 && data[i] < 58)
1221 value = data[i] - 48;
1222 else if (data[i] > 64 && data[i] < 71)
1223 value = data[i] - 55;
1224 else if (data[i] > 96 && data[i] < 103)
1225 value = data[i] - 87;
1234 return neg ? -acc : acc;
1241 template<
typename I = N>
1249 for (N i = data[0] ==
'-' ? 1 : 0; i < size; ++i)
1250 r = r * 10 + data[i] -
'0';
1267 Find(ide, &decPoint);
1269 float result = 0.0f;
1270 float fraction = 0.0f;
1273 for (N i = 0; i < decPoint; ++i)
1274 result = result * 10.0f + data[i] -
'0';
1276 for (N i = decPoint + 1; i < size; ++i)
1278 fraction = fraction * 10.0f + data[i] -
'0';
1282 result += fraction / scale;
1296 Find(ide, &decPoint);
1298 double result = 0.0f;
1299 double fraction = 0.0f;
1300 double scale = 1.0f;
1302 for (N i = 0; i < decPoint; ++i)
1303 result = result * 10.0f + data[i] -
'0';
1305 for (N i = decPoint + 1; i < size; ++i)
1307 fraction = fraction * 10.0f + data[i] -
'0';
1311 result += fraction / scale;
1325 Find(ide, &decPoint);
1327 long double result = 0.0f;
1328 long double fraction = 0.0f;
1329 long double scale = 1.0f;
1331 for (N i = 0; i < decPoint; ++i)
1332 result = result * 10.0f + data[i] -
'0';
1334 for (N i = decPoint + 1; i < size; ++i)
1336 fraction = fraction * 10.0f + data[i] -
'0';
1340 result += fraction / scale;
1369 r[i++] = 48 + nonNeg % 10;
1395 UInt_64 nonNeg = num;
1401 r[i++] = 48 + nonNeg % 10;
1434 r[i++] = 48 + nonNeg % 10;
1466 r[i++] = 48 + nonNeg % 10;
1499 r[i++] = 48 + nonNeg % 10;
1531 r[i++] = 48 + nonNeg % 10;
1564 r[i++] = 48 + nonNeg % 10;
1596 r[i++] = 48 + nonNeg % 10;
1605 #ifdef EHS_OS_WINDOWS
1625 r[i++] = 48 + nonNeg % 10;
1631 return r.GetReverse();
1636 static Str<T, N>
FromNum(
const HRESULT num)
1657 r[i++] = 48 + nonNeg % 10;
1666 return r.GetReverse();
1676 SInt_64 whole = (SInt_64)num;
1685 for (UInt_64 i = 0; i < (UInt_64)maxDecimals - 1; ++i)
1688 SInt_64 fraction = (SInt_64)((num - (
float)whole) * (
float)power);
1699 fResult[i++] = 48 + fraction % 10;
1703 while (i < maxDecimals)
1718 SInt_64 whole = (SInt_64)num;
1727 for (UInt_64 i = 0; i < (UInt_64)maxDecimals - 1; ++i)
1730 SInt_64 fraction = (SInt_64)((num - (
double)whole) * (
double)power);
1741 fResult[i++] = 48 + fraction % 10;
1745 while (i < maxDecimals)
1760 SInt_64 whole = (SInt_64)num;
1769 for (UInt_64 i = 0; i < (UInt_64)maxDecimals - 1; ++i)
1772 SInt_64 fraction = (SInt_64)((num - (
long double)whole) * (
long double)power);
1783 fResult[i++] = 48 + fraction % 10;
1787 while (i < maxDecimals)
1808 for (N i = 0; i < str.
Size(
true); ++i)
1809 hash = (hash ^ bytes[i]) * 16777619;
1825 for (N i = 0; i <
Size(
true); ++i)
1826 hash = (hash ^ bytes[i]) * 16777619;
1841 UInt_64 hash = 14695981039346656037ull;
1843 for (N i = 0; i < str.
Size(
true); ++i)
1844 hash = (hash ^ bytes[i]) * 1099511628211;
1858 UInt_64 hash = 14695981039346656037ull;
1860 for (N i = 0; i <
Size(
true); ++i)
1861 hash = (hash ^ bytes[i]) * 1099511628211;
1869 static N
Len(
const T*
const str)
1884 static bool Cmp(
const T*
const a,
const T*
const b)
1905template<
typename T = ehs::Char_8,
typename N = ehs::UInt_64>
1909 if (second.
Size() != inSize)
1915template<
typename T = ehs::Char_8,
typename N = ehs::UInt_64>
1919 if (second.
Size() != inSize)
1929template<
typename T = ehs::Char_8,
typename N = ehs::UInt_64>
1939 result[inSize + second.
Size()] = 0;
bool operator!=(const T *const first, const ehs::Str< T, N > &second)
Definition: Str.h:1916
ehs::Str< T, N > operator+(const T *const first, const ehs::Str< T, N > &second)
Definition: Str.h:1930
bool operator==(const T *const first, const ehs::Str< T, N > &second)
Definition: Str.h:1906
UInt_64 Hash_64() const
Definition: Str.h:1851
bool operator==(const T *const str) const
Definition: Str.h:451
void Copy(const N dstOffset, const Str< T, N > &src)
Definition: Str.h:548
Str< T, N > operator+(const UInt_16 num) const
Definition: Str.h:374
static Str< T, N > FromNum(const SInt_64 num)
Definition: Str.h:1348
Str< T, N > GetUpper() const
Definition: Str.h:832
Vector< Str< T, N >, N > Split(const Str< T, N > &ide, const N max=0) const
Definition: Str.h:920
static bool Cmp(const T *const a, const T *const b)
Definition: Str.h:1884
bool IsNum() const
Definition: Str.h:1115
void ToLower()
Converts all upper-case ASCII characters to lower-case.
Definition: Str.h:800
Str & operator=(const Str &str)
Definition: Str.h:116
void Insert(const N index, const Str &value)
Definition: Str.h:593
bool operator==(T *str) const
Definition: Str.h:440
Str< T, N > operator+(const Str< T, N > &str) const
Definition: Str.h:318
void Insert(const N index, const T value)
Definition: Str.h:618
Str< T, N > & operator+=(const long double num)
Definition: Str.h:292
void Push(const T *const value, const N size)
Definition: Str.h:717
bool operator!=(const T *const str) const
Definition: Str.h:473
static Str< T, N > FromNum(const UInt_64 num)
Definition: Str.h:1384
Str ReplaceAll(const Str &ide, const Str &replacer) const
Definition: Str.h:990
Str< T, N > operator+(const float num) const
Definition: Str.h:416
void Push(const T *const value)
Definition: Str.h:733
Str(const Str &str)
Definition: Str.h:90
Str< T, N > GetLower() const
Definition: Str.h:809
static UInt_64 Hash_64(const Str< T, N > &str)
Definition: Str.h:1834
Str< T, N > & operator+=(const UInt_16 num)
Definition: Str.h:234
Str< T, N > Sub(const N index, const N size=0) const
Definition: Str.h:882
Str< T, N > operator+(const SInt_16 num) const
Definition: Str.h:366
Str()
Default members initialization.
Definition: Str.h:42
Str< T, N > & operator+=(const UInt_32 num)
Definition: Str.h:218
static Str< T, N > FromNum(const UInt_8 num)
Definition: Str.h:1579
Str< T, N > & operator+=(const SInt_64 num)
Definition: Str.h:194
long double ToLDouble() const
Definition: Str.h:1319
void ToUpper()
Converts all lower-case ASCII characters to upper-case.
Definition: Str.h:823
static Str< T, N > FromNum(const UInt_16 num)
Definition: Str.h:1514
bool operator!=(const Str< T, N > &str) const
Definition: Str.h:484
void Push(const Str< T, N > &value)
Definition: Str.h:700
void Reverse()
Reverses the entire string object.
Definition: Str.h:846
static Str< T, N > FromNum(const SInt_32 num)
Definition: Str.h:1413
Str< T, N > RemoveAll(const Str< T, N > &ide) const
Definition: Str.h:960
static Str< T, N > FromNum(const SInt_16 num)
Definition: Str.h:1478
bool operator==(const Str< T, N > &str) const
Definition: Str.h:462
static Str< T, N > FromNum(const double num, const UInt_8 maxDecimals=5)
Definition: Str.h:1716
Str< T, N > & operator+=(const SInt_32 num)
Definition: Str.h:210
static I HexToNum(const Str &in)
Definition: Str.h:1155
static N Len(const T *const str)
Definition: Str.h:1869
I ToDecimal() const
Definition: Str.h:1242
Str(Str &&str) noexcept
A move constructor.
Definition: Str.h:81
Str< T, N > & operator+=(const double num)
Definition: Str.h:284
Str< T, N > & operator+=(const Str< T, N > &str)
Definition: Str.h:174
static Str< T, N > FromNum(const SInt_8 num)
Definition: Str.h:1543
Str< T, N > operator+(const UInt_8 num) const
Definition: Str.h:390
void Push(const T value)
Definition: Str.h:751
Str< T, N > & operator+=(const UInt_64 num)
Definition: Str.h:202
N Size(bool inBytes=false) const
Definition: Str.h:523
Str< T, N > operator+(const SInt_64 num) const
Definition: Str.h:334
Str(const T *const str)
Definition: Str.h:62
static Str< T, N > FromNum(const long double num, const UInt_8 maxDecimals=5)
Definition: Str.h:1758
Str< T, N > operator+(const UInt_64 num) const
Definition: Str.h:342
const Byte * ToBytes() const
Definition: Str.h:787
I HexToNum() const
Definition: Str.h:1198
Str< T, N > operator+(const double num) const
Definition: Str.h:424
Str< T, N > operator+(const SInt_8 num) const
Definition: Str.h:382
double ToDouble() const
Definition: Str.h:1290
Str< T, N > operator+(const SInt_32 num) const
Definition: Str.h:350
void Copy(const N dstOffset, const T *const src)
Definition: Str.h:562
Str< T, N > & operator+=(const T *const str)
Definition: Str.h:152
T Remove(const N index)
Definition: Str.h:673
Str< T, N > & operator+=(const SInt_8 num)
Definition: Str.h:242
void Resize(const N newSize)
Definition: Str.h:500
bool Find(const Str< T, N > &ide, N *const index=nullptr, const SearchPattern pattern=SearchPattern::LEFT_RIGHT, const IndexResult result=IndexResult::BEGINNING) const
Definition: Str.h:1019
Str< T, N > operator+(const UInt_32 num) const
Definition: Str.h:358
Str(const N size)
Definition: Str.h:74
bool Contains(const Str< T, N > &ide, const SearchPattern pattern=SearchPattern::LEFT_RIGHT) const
Definition: Str.h:1081
static Str NumToHex(const I num)
Definition: Str.h:1135
static UInt_32 Hash_32(const Str< T, N > &str)
Definition: Str.h:1799
Str< T, N > GetReverse()
Definition: Str.h:865
Str< T, N > & operator+=(const float num)
Definition: Str.h:276
Str & operator=(Str &&str) noexcept
Definition: Str.h:98
void ExactSize()
Finds the null terminator in the string and makes it the exact size if greater than.
Definition: Str.h:532
UInt_32 Hash_32() const
Definition: Str.h:1816
T Pop()
Definition: Str.h:768
static Str< T, N > FromNum(const float num, const UInt_8 maxDecimals=5)
Definition: Str.h:1674
~Str()
Frees any data created on the heap.
Definition: Str.h:36
static Str< T, N > FromNum(const UInt_32 num)
Definition: Str.h:1449
float ToFloat() const
Definition: Str.h:1261
Str< T, N > operator+(const T *const str) const
Definition: Str.h:300
Str< T, N > operator+(const long double num) const
Definition: Str.h:432
Str< T, N > & operator=(const T *const str)
Definition: Str.h:134
Str< T, N > & operator+=(const SInt_16 num)
Definition: Str.h:226
Byte * ToBytes()
Definition: Str.h:794
Str Remove(const N start, const N end)
Definition: Str.h:647
void Copy(const N dstOffset, const T *const src, const N srcSize)
Definition: Str.h:579
Str< T, N > & operator+=(const UInt_8 num)
Definition: Str.h:250
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:49
static bool Compare(const void *a, const void *b, UInt_64 size)
Definition: Util.cpp:5
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
SearchPattern
Definition: Str.h:13
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:1901
unsigned char UInt_8
Definition: Types.h:43
Str< Char_8, UInt_64 > Str_8
Definition: Str.h:1902
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:1900
signed short SInt_16
Definition: Types.h:47