aboutsummaryrefslogtreecommitdiff
path: root/src/common/Utilities/Util.h
diff options
context:
space:
mode:
authorTreeston <treeston.mmoc@gmail.com>2020-08-28 00:11:16 +0200
committerShauren <shauren.trinity@gmail.com>2022-02-04 00:27:14 +0100
commit9f97fdd31a3b9a06b6acfa1101d105e43687e824 (patch)
tree027f81c18e7733fa3554cf1dd704a0900d254725 /src/common/Utilities/Util.h
parent6e45c371c4098942e0085a71577a07b17725ee93 (diff)
Core/Common: Tokenizer -> Trinity::Tokenize (PR: #25327)
(cherry picked from commit 534a2388b7c662c8796aabb1ec8cb424879799b6)
Diffstat (limited to 'src/common/Utilities/Util.h')
-rw-r--r--src/common/Utilities/Util.h34
1 files changed, 9 insertions, 25 deletions
diff --git a/src/common/Utilities/Util.h b/src/common/Utilities/Util.h
index 28d0285d74d..8708405882e 100644
--- a/src/common/Utilities/Util.h
+++ b/src/common/Utilities/Util.h
@@ -37,35 +37,19 @@ enum class TimeFormat : uint8
Numeric // 1:2:3:4
};
-class TC_COMMON_API Tokenizer
+namespace Trinity
{
-public:
- typedef std::vector<char const*> StorageType;
-
- typedef StorageType::size_type size_type;
-
- typedef StorageType::const_iterator const_iterator;
- typedef StorageType::reference reference;
- typedef StorageType::const_reference const_reference;
-
-public:
- Tokenizer(std::string_view src, char const sep, uint32 vectorReserve = 0, bool keepEmptyStrings = true);
- ~Tokenizer() { delete[] m_str; }
+ TC_COMMON_API std::vector<std::string_view> Tokenize(std::string_view str, char sep, bool keepEmpty);
- const_iterator begin() const { return m_storage.begin(); }
- const_iterator end() const { return m_storage.end(); }
+ /* this would return string_view into temporary otherwise */
+ std::vector<std::string_view> Tokenize(std::string&&, char, bool) = delete;
+ std::vector<std::string_view> Tokenize(std::string const&&, char, bool) = delete;
- size_type size() const { return m_storage.size(); }
-
- reference operator [] (size_type i) { return m_storage[i]; }
- const_reference operator [] (size_type i) const { return m_storage[i]; }
-
-private:
- char* m_str;
- StorageType m_storage;
-};
+ /* the delete overload means we need to make this explicit */
+ inline std::vector<std::string_view> Tokenize(char const* str, char sep, bool keepEmpty) { return Tokenize(std::string_view(str ? str : ""), sep, keepEmpty); }
+}
-TC_COMMON_API int64 MoneyStringToMoney(std::string const& moneyString);
+TC_COMMON_API Optional<int64> MoneyStringToMoney(std::string const& moneyString);
TC_COMMON_API struct tm* localtime_r(time_t const* time, struct tm *result);
TC_COMMON_API time_t LocalTimeToUTCTime(time_t time);