diff --git a/dCommon/GeneralUtils.cpp b/dCommon/GeneralUtils.cpp index 7cc9278b..83205085 100644 --- a/dCommon/GeneralUtils.cpp +++ b/dCommon/GeneralUtils.cpp @@ -237,57 +237,6 @@ bool GeneralUtils::ReplaceInString(std::string& str, const std::string_view from return true; } -std::vector GeneralUtils::SplitString(const std::wstring_view str, const wchar_t delimiter) { - std::vector vector = std::vector(); - std::wstring current; - - for (const wchar_t c : str) { - if (c == delimiter) { - vector.push_back(current); - current = L""; - } else { - current += c; - } - } - - vector.push_back(std::move(current)); - return vector; -} - -std::vector GeneralUtils::SplitString(const std::u16string_view str, const char16_t delimiter) { - std::vector vector = std::vector(); - std::u16string current; - - for (const char16_t c : str) { - if (c == delimiter) { - vector.push_back(current); - current = u""; - } else { - current += c; - } - } - - vector.push_back(std::move(current)); - return vector; -} - -std::vector GeneralUtils::SplitString(const std::string_view str, const char delimiter) { - std::vector vector = std::vector(); - std::string current = ""; - - for (const char c : str) { - if (c == delimiter) { - vector.push_back(current); - current = ""; - } else { - current += c; - } - } - - vector.push_back(std::move(current)); - return vector; -} - std::u16string GeneralUtils::ReadWString(RakNet::BitStream& inStream) { uint32_t length; inStream.Read(length); diff --git a/dCommon/GeneralUtils.h b/dCommon/GeneralUtils.h index 69c5fc44..498f6cf1 100644 --- a/dCommon/GeneralUtils.h +++ b/dCommon/GeneralUtils.h @@ -130,11 +130,23 @@ namespace GeneralUtils { std::u16string ReadWString(RakNet::BitStream& inStream); - std::vector SplitString(const std::wstring_view str, const wchar_t delimiter); + template + std::vector> SplitString(const StringType& str, const typename StringType::value_type delimiter) { + std::vector> toReturn{}; - std::vector SplitString(const std::u16string_view str, const char16_t delimiter); + toReturn.emplace_back(); + auto itr = toReturn.rbegin(); + for (const auto c : str) { + if (c == delimiter) { + toReturn.emplace_back(); + itr = toReturn.rbegin(); + } else { + (*itr).push_back(c); + } + } - std::vector SplitString(const std::string_view str, const char delimiter); + return toReturn; + } std::vector GetSqlFileNamesFromFolder(const std::string_view folder); diff --git a/dGame/dComponents/InventoryComponent.cpp b/dGame/dComponents/InventoryComponent.cpp index 4cc0a3de..cabf5e3d 100644 --- a/dGame/dComponents/InventoryComponent.cpp +++ b/dGame/dComponents/InventoryComponent.cpp @@ -1777,7 +1777,7 @@ void InventoryComponent::LoadGroupXml(const tinyxml2::XMLElement& groups) { group.groupId = groupId; group.groupName = groupName; - for (const auto& lotStr : GeneralUtils::SplitString(lots, ' ')) { + for (const auto& lotStr : GeneralUtils::SplitString(std::string_view(lots), ' ')) { auto lot = GeneralUtils::TryParse(lotStr); if (lot) group.lots.insert(*lot); }