diff --git a/base/base_tests/string_utils_test.cpp b/base/base_tests/string_utils_test.cpp index 9d416c287b..7612468777 100644 --- a/base/base_tests/string_utils_test.cpp +++ b/base/base_tests/string_utils_test.cpp @@ -3,10 +3,13 @@ #include "base/string_utils.hpp" #include "base/logging.hpp" -#include "std/iomanip.hpp" -#include "std/fstream.hpp" #include "std/bind.hpp" +#include "std/fstream.hpp" +#include "std/iomanip.hpp" +#include "std/map.hpp" +#include "std/type_traits.hpp" #include "std/unordered_map.hpp" +#include "std/vector.hpp" /// internal function in base @@ -206,17 +209,17 @@ UNIT_TEST(to_uint) s = "-2"; TEST(!strings::to_uint(s, i), ()); - + s = "0"; TEST(strings::to_uint(s, i), ()); TEST_EQUAL(0, i, ()); - + s = "123456789123456789123456789"; TEST(!strings::to_uint(s, i), ()); - + s = "labuda"; TEST(!strings::to_uint(s, i), ()); - + s = "AF"; TEST(strings::to_uint(s, i, 16), ()); TEST_EQUAL(175, i, ()); @@ -449,6 +452,18 @@ UNIT_TEST(SimpleTokenizer) } } +UNIT_TEST(Tokenize) +{ + { + initializer_list expected{"acb", "def", "ghi"}; + TEST_EQUAL(strings::Tokenize("acb def ghi", " " /* delims */), vector(expected), ()); + TEST_EQUAL(strings::Tokenize("acb def ghi", " " /* delims */), set(expected), ()); + } + { + static_assert(is_same, decltype(strings::Tokenize("", ""))>::value); + } +} + UNIT_TEST(LastUniChar) { TEST_EQUAL(strings::LastUniChar(""), 0, ()); diff --git a/base/stl_add.hpp b/base/stl_add.hpp index 7a1331358c..8ccfdffa53 100644 --- a/base/stl_add.hpp +++ b/base/stl_add.hpp @@ -32,7 +32,7 @@ public: } void operator() (typename ContainerT::value_type const & t) const { - m_Container.insert(t); + m_Container.insert(end(m_Container), t); } }; diff --git a/base/string_utils.hpp b/base/string_utils.hpp index 561ec20fe1..8d7c37e8a6 100644 --- a/base/string_utils.hpp +++ b/base/string_utils.hpp @@ -1,6 +1,7 @@ #pragma once #include "base/buffer_vector.hpp" +#include "base/stl_add.hpp" #include "std/algorithm.hpp" #include "std/cstdint.hpp" @@ -306,6 +307,14 @@ void Tokenize(string const & str, char const * delims, TFunctor && f) } } +template