diff --git a/include/ehs/Str.h b/include/ehs/Str.h index 3905f81..bd651bb 100644 --- a/include/ehs/Str.h +++ b/include/ehs/Str.h @@ -48,8 +48,11 @@ namespace ehs /// @param [in] str The C-style string. /// @param [in] size The size of the given C-style string. Str(const T* const str, const N size) - : size((size) ? size : Len(str)), data(nullptr) + : size(size), data(nullptr) { + if (!size) + return; + data = new T[this->size + 1]; Util::Copy(data, str, Size(true)); @@ -914,10 +917,10 @@ namespace ehs } /// Splits a string into a Vector with the given separator. - /// @param [in] ide The given string as the separator. + /// @param [in] delimeter The given string as the separator. /// @param [in] max The max amount of times to split the string. /// @returns The resulting string object. - Vector, N> Split(const Str& ide, const N max = 0) const + Vector, N> Split(const Str& delimeter, const N max = 0) const { Vector, N> result(0, 5); @@ -925,9 +928,9 @@ namespace ehs for (N i = 0, c = 0; i < size; ++i) { - if (data[i] == ide[c]) + if (data[i] == delimeter[c]) { - if (++c == ide.Size()) + if (++c == delimeter.Size()) { N r = i - (c - 1) - b; if (!r) @@ -955,17 +958,17 @@ namespace ehs } /// Removes all instances of the ide. - /// @param [in] ide The string to look for. + /// @param [in] delimeter The string to look for. /// @returns The resulting string object. - Str RemoveAll(const Str& ide) const + Str RemoveAll(const Str& delimeter) const { Str result(size); for (N i = 0, b = 0, c = 0; i < size; ++i) { - if (data[i] == ide[c]) + if (data[i] == delimeter[c]) { - if (++c == ide.Size()) + if (++c == delimeter.Size()) c = 0; } else @@ -984,18 +987,18 @@ namespace ehs } /// Replaces all instances of ide with the replacer. - /// @param [in] ide The string to look for. + /// @param [in] delimeter The string to look for. /// @param [in] replacer The string placed. /// @returns The resulting string object. - Str ReplaceAll(const Str& ide, const Str& replacer) const + Str ReplaceAll(const Str& delimeter, const Str& replacer) const { Str result; for (N i = 0, b = 0; i < size; ++i) { - if (data[i] == ide[b]) + if (data[i] == delimeter[b]) { - if (++b == ide.Size()) + if (++b == delimeter.Size()) { result.Push(replacer); b = 0; @@ -1011,20 +1014,20 @@ namespace ehs } /// Finds the first instance of the given string object. - /// @param [in] ide The string to look for. + /// @param [in] delimeter The string to look for. /// @param [out] index The index of the string found. Can be a nullptr. /// @param [in] pattern The search pattern for optimization. /// @param [in] result What index to return where the first instance is found. /// @returns The index where the instance was found with the result varying from the result parameter. - bool Find(const Str &ide, N* const index = nullptr, const SearchPattern pattern = SearchPattern::LEFT_RIGHT, const IndexResult result = IndexResult::BEGINNING) const + bool Find(const Str &delimeter, N* const index = nullptr, const SearchPattern pattern = SearchPattern::LEFT_RIGHT, const IndexResult result = IndexResult::BEGINNING) const { if (pattern == SearchPattern::LEFT_RIGHT) { for (N i = 0, c = 0; i < size; ++i) { - if (data[i] == ide[c]) + if (data[i] == delimeter[c]) { - if (++c == ide.Size()) + if (++c == delimeter.Size()) { if (result == IndexResult::BEGINNING) { @@ -1046,16 +1049,16 @@ namespace ehs } else if (pattern == SearchPattern::RIGHT_LEFT) { - for (N i = size, c = ide.Size(); i > 0; --i) + for (N i = size, c = delimeter.Size(); i > 0; --i) { - if (data[i - 1] == ide[c - 1]) + if (data[i - 1] == delimeter[c - 1]) { if (--c == 0) { if (result == IndexResult::BEGINNING) { if (index) - *index = i - (ide.Size() - 1); + *index = i - (delimeter.Size() - 1); return true; } @@ -1075,18 +1078,18 @@ namespace ehs } /// Checks if the current string contains the given ide. - /// @param [in] ide The given ide to check for. + /// @param [in] delimeter The given ide to check for. /// @param [in] pattern The search pattern to use. /// @returns True if the current string does contain the ide. - bool Contains(const Str& ide, const SearchPattern pattern = SearchPattern::LEFT_RIGHT) const + bool Contains(const Str& delimeter, const SearchPattern pattern = SearchPattern::LEFT_RIGHT) const { if (pattern == SearchPattern::LEFT_RIGHT) { for (N i = 0, c = 0; i < size; ++i) { - if (data[i] == ide[c]) + if (data[i] == delimeter[c]) { - if (++c == ide.Size()) + if (++c == delimeter.Size()) { return true; } @@ -1095,9 +1098,9 @@ namespace ehs } else if (pattern == SearchPattern::RIGHT_LEFT) { - for (N i = size, c = ide.Size(); i > 0; --i) + for (N i = size, c = delimeter.Size(); i > 0; --i) { - if (data[i - 1] == ide[c - 1]) + if (data[i - 1] == delimeter[c - 1]) { if (--c == 0) {