diff --git a/libs/utility/CMakeLists.txt b/libs/utility/CMakeLists.txt index 7b7aaf21..b83a075c 100644 --- a/libs/utility/CMakeLists.txt +++ b/libs/utility/CMakeLists.txt @@ -1 +1 @@ -subdirs( string_ref ) +subdirs( string_view ) diff --git a/libs/utility/string_ref/test/CMakeLists.txt b/libs/utility/string_ref/test/CMakeLists.txt deleted file mode 100644 index c91c4869..00000000 --- a/libs/utility/string_ref/test/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -add_executable( libs_utility_string_ref_test_string_ref string_ref.cpp ) -set_target_properties( libs_utility_string_ref_test_string_ref PROPERTIES OUTPUT_NAME "string_ref" ) -add_test( libs_utility_string_ref_test_string_ref string_ref ) diff --git a/libs/utility/string_ref/CMakeLists.txt b/libs/utility/string_view/CMakeLists.txt similarity index 100% rename from libs/utility/string_ref/CMakeLists.txt rename to libs/utility/string_view/CMakeLists.txt diff --git a/libs/utility/string_view/test/CMakeLists.txt b/libs/utility/string_view/test/CMakeLists.txt new file mode 100644 index 00000000..76b4d14e --- /dev/null +++ b/libs/utility/string_view/test/CMakeLists.txt @@ -0,0 +1,3 @@ +add_executable( libs_utility_string_view_test_string_view string_view.cpp ) +set_target_properties( libs_utility_string_view_test_string_view PROPERTIES OUTPUT_NAME "string_view" ) +add_test( libs_utility_string_view_test_string_view string_view ) diff --git a/libs/utility/string_ref/test/string_ref.cpp b/libs/utility/string_view/test/string_view.cpp similarity index 72% rename from libs/utility/string_ref/test/string_ref.cpp rename to libs/utility/string_view/test/string_view.cpp index b94ad4ea..40ac93a5 100644 --- a/libs/utility/string_ref/test/string_ref.cpp +++ b/libs/utility/string_view/test/string_view.cpp @@ -5,24 +5,24 @@ Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ -#ifndef SPROUT_LIBS_UTILITY_STRING_REF_TEST_STRING_REF_CPP -#define SPROUT_LIBS_UTILITY_STRING_REF_TEST_STRING_REF_CPP +#ifndef SPROUT_LIBS_UTILITY_STRING_VIEW_TEST_STRING_VIEW_CPP +#define SPROUT_LIBS_UTILITY_STRING_VIEW_TEST_STRING_VIEW_CPP #include #include -#include +#include #include #include #include namespace testspr { - static void string_ref_test() { + static void string_view_test() { using namespace sprout; { SPROUT_STATIC_CONSTEXPR char cstr[] = "foobar1234"; SPROUT_STATIC_CONSTEXPR auto s = sprout::to_string("hogehoge"); - SPROUT_STATIC_CONSTEXPR auto str1 = sprout::string_ref(cstr); - SPROUT_STATIC_CONSTEXPR auto str2 = sprout::string_ref(s); + SPROUT_STATIC_CONSTEXPR auto str1 = sprout::string_view(cstr); + SPROUT_STATIC_CONSTEXPR auto str2 = sprout::string_view(s); // begin TESTSPR_BOTH_ASSERT(cstr[0] == *str1.begin()); @@ -53,7 +53,7 @@ namespace testspr { // empty TESTSPR_BOTH_ASSERT(!str1.empty()); - TESTSPR_BOTH_ASSERT((sprout::string_ref().empty())); + TESTSPR_BOTH_ASSERT((sprout::string_view().empty())); // max_size TESTSPR_BOTH_ASSERT(str1.max_size() == 10); @@ -78,16 +78,16 @@ namespace testspr { // swap { - auto s1 = sprout::string_ref("abc"); - auto s2 = sprout::string_ref("ABC"); + auto s1 = sprout::string_view("abc"); + auto s2 = sprout::string_view("ABC"); s1.swap(s2); TESTSPR_ASSERT(s1[0] == 'A'); } // operator= { - auto s = sprout::string_ref("abc"); - s = sprout::string_ref("ABC"); + auto s = sprout::string_view("abc"); + s = sprout::string_view("ABC"); TESTSPR_ASSERT(s.size() == 3); TESTSPR_ASSERT(s[0] == 'A'); } @@ -106,7 +106,7 @@ namespace testspr { // find TESTSPR_BOTH_ASSERT(str1.find(str2) == npos); - TESTSPR_BOTH_ASSERT(str1.find(sprout::string_ref("bar")) == 3); + TESTSPR_BOTH_ASSERT(str1.find(sprout::string_view("bar")) == 3); TESTSPR_BOTH_ASSERT(str1.find(str2.c_str()) == npos); TESTSPR_BOTH_ASSERT(str1.find("bar") == 3); TESTSPR_BOTH_ASSERT(str1.find(str2.c_str(), 0, 3) == npos); @@ -115,7 +115,7 @@ namespace testspr { // rfind TESTSPR_BOTH_ASSERT(str1.rfind(str2) == npos); - TESTSPR_BOTH_ASSERT(str1.rfind(sprout::string_ref("bar")) == 3); + TESTSPR_BOTH_ASSERT(str1.rfind(sprout::string_view("bar")) == 3); TESTSPR_BOTH_ASSERT(str1.rfind(str2.c_str()) == npos); TESTSPR_BOTH_ASSERT(str1.rfind("bar") == 3); TESTSPR_BOTH_ASSERT(str1.rfind(str2.c_str(), npos, 3) == npos); @@ -123,8 +123,8 @@ namespace testspr { TESTSPR_BOTH_ASSERT(str1.rfind('b') == 3); // find_first_of - TESTSPR_BOTH_ASSERT(str1.find_first_of(sprout::string_ref("vwxyz")) == npos); - TESTSPR_BOTH_ASSERT(str1.find_first_of(sprout::string_ref("rab")) == 3); + TESTSPR_BOTH_ASSERT(str1.find_first_of(sprout::string_view("vwxyz")) == npos); + TESTSPR_BOTH_ASSERT(str1.find_first_of(sprout::string_view("rab")) == 3); TESTSPR_BOTH_ASSERT(str1.find_first_of("vwxyz") == npos); TESTSPR_BOTH_ASSERT(str1.find_first_of("rab") == 3); TESTSPR_BOTH_ASSERT(str1.find_first_of("vwxyz", 0, 3) == npos); @@ -132,8 +132,8 @@ namespace testspr { TESTSPR_BOTH_ASSERT(str1.find_first_of('b') == 3); // find_last_of - TESTSPR_BOTH_ASSERT(str1.find_last_of(sprout::string_ref("vwxyz")) == npos); - TESTSPR_BOTH_ASSERT(str1.find_last_of(sprout::string_ref("rab")) == 5); + TESTSPR_BOTH_ASSERT(str1.find_last_of(sprout::string_view("vwxyz")) == npos); + TESTSPR_BOTH_ASSERT(str1.find_last_of(sprout::string_view("rab")) == 5); TESTSPR_BOTH_ASSERT(str1.find_last_of("vwxyz") == npos); TESTSPR_BOTH_ASSERT(str1.find_last_of("rab") == 5); TESTSPR_BOTH_ASSERT(str1.find_last_of("vwxyz", npos, 3) == npos); @@ -142,7 +142,7 @@ namespace testspr { // find_first_not_of TESTSPR_BOTH_ASSERT(str1.find_first_not_of(str1) == npos); - TESTSPR_BOTH_ASSERT(str1.find_first_not_of(sprout::string_ref("foo")) == 3); + TESTSPR_BOTH_ASSERT(str1.find_first_not_of(sprout::string_view("foo")) == 3); TESTSPR_BOTH_ASSERT(str1.find_first_not_of(str1.c_str()) == npos); TESTSPR_BOTH_ASSERT(str1.find_first_not_of("foo") == 3); TESTSPR_BOTH_ASSERT(str1.find_first_not_of(str1.c_str(), 0, 10) == npos); @@ -151,7 +151,7 @@ namespace testspr { // find_last_not_of TESTSPR_BOTH_ASSERT(str1.find_last_not_of(str1) == npos); - TESTSPR_BOTH_ASSERT(str1.find_last_not_of(sprout::string_ref("4321")) == 5); + TESTSPR_BOTH_ASSERT(str1.find_last_not_of(sprout::string_view("4321")) == 5); TESTSPR_BOTH_ASSERT(str1.find_last_not_of(str1.c_str()) == npos); TESTSPR_BOTH_ASSERT(str1.find_last_not_of("4321") == 5); TESTSPR_BOTH_ASSERT(str1.find_last_not_of(str1.c_str(), npos, 10) == npos); @@ -174,14 +174,14 @@ namespace testspr { // compare TESTSPR_BOTH_ASSERT(str1.compare(str1) == 0); - TESTSPR_BOTH_ASSERT(str1.compare(sprout::string_ref("zzzz")) < 0); - TESTSPR_BOTH_ASSERT(str2.compare(sprout::string_ref("aaaa")) > 0); - TESTSPR_BOTH_ASSERT(str1.compare(0, 3, sprout::string_ref("foo")) == 0); - TESTSPR_BOTH_ASSERT(str1.compare(0, 3, sprout::string_ref("zzzz")) < 0); - TESTSPR_BOTH_ASSERT(str2.compare(0, 3, sprout::string_ref("aaaa")) > 0); - TESTSPR_BOTH_ASSERT(str1.compare(0, 3, sprout::string_ref("foo"), 0, 3) == 0); - TESTSPR_BOTH_ASSERT(str1.compare(0, 3, sprout::string_ref("zzzz"), 0, 3) < 0); - TESTSPR_BOTH_ASSERT(str2.compare(0, 3, sprout::string_ref("aaaa"), 0, 3) > 0); + TESTSPR_BOTH_ASSERT(str1.compare(sprout::string_view("zzzz")) < 0); + TESTSPR_BOTH_ASSERT(str2.compare(sprout::string_view("aaaa")) > 0); + TESTSPR_BOTH_ASSERT(str1.compare(0, 3, sprout::string_view("foo")) == 0); + TESTSPR_BOTH_ASSERT(str1.compare(0, 3, sprout::string_view("zzzz")) < 0); + TESTSPR_BOTH_ASSERT(str2.compare(0, 3, sprout::string_view("aaaa")) > 0); + TESTSPR_BOTH_ASSERT(str1.compare(0, 3, sprout::string_view("foo"), 0, 3) == 0); + TESTSPR_BOTH_ASSERT(str1.compare(0, 3, sprout::string_view("zzzz"), 0, 3) < 0); + TESTSPR_BOTH_ASSERT(str2.compare(0, 3, sprout::string_view("aaaa"), 0, 3) > 0); TESTSPR_BOTH_ASSERT(str1.compare(str1.c_str()) == 0); TESTSPR_BOTH_ASSERT(str1.compare("zzzz") < 0); TESTSPR_BOTH_ASSERT(str1.compare("aaaa") > 0); @@ -217,9 +217,9 @@ namespace testspr { TESTSPR_ASSERT(os.str() == cstr); } - // is_string_ref - TESTSPR_BOTH_ASSERT(sprout::is_string_ref::value); - TESTSPR_BOTH_ASSERT(!sprout::is_string_ref::value); + // is_string_view + TESTSPR_BOTH_ASSERT(sprout::is_string_view::value); + TESTSPR_BOTH_ASSERT(!sprout::is_string_view::value); // sprout::to_hash, sprout::hash TESTSPR_BOTH_ASSERT(sprout::to_hash(str1) == sprout::hash()(str1)); @@ -229,8 +229,8 @@ namespace testspr { } // namespace testspr #ifndef TESTSPR_CPP_INCLUDE -# define TESTSPR_TEST_FUNCTION testspr::string_ref_test +# define TESTSPR_TEST_FUNCTION testspr::string_view_test # include #endif -#endif // #ifndef SPROUT_LIBS_UTILITY_STRING_REF_TEST_STRING_REF_CPP +#endif // #ifndef SPROUT_LIBS_UTILITY_STRING_VIEW_TEST_STRING_VIEW_CPP diff --git a/sprout/utility.hpp b/sprout/utility.hpp index aff0516b..a38ef397 100644 --- a/sprout/utility.hpp +++ b/sprout/utility.hpp @@ -17,8 +17,8 @@ #include #include #include -#include #include +#include #include #include #include diff --git a/sprout/utility/string_ref.hpp b/sprout/utility/string_ref.hpp index 9c1c34c8..aa0e7009 100644 --- a/sprout/utility/string_ref.hpp +++ b/sprout/utility/string_ref.hpp @@ -9,14 +9,6 @@ #define SPROUT_UTILITY_STRING_REF_HPP #include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #endif // #ifndef SPROUT_UTILITY_STRING_REF_HPP diff --git a/sprout/utility/string_ref/alias.hpp b/sprout/utility/string_ref/alias.hpp deleted file mode 100644 index c2b10878..00000000 --- a/sprout/utility/string_ref/alias.hpp +++ /dev/null @@ -1,29 +0,0 @@ -/*============================================================================= - Copyright (c) 2011-2016 Bolero MURAKAMI - https://github.com/bolero-MURAKAMI/Sprout - - Distributed under the Boost Software License, Version 1.0. (See accompanying - file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -=============================================================================*/ -#ifndef SPROUT_UTILITY_STRING_REF_ALIAS_HPP -#define SPROUT_UTILITY_STRING_REF_ALIAS_HPP - -#include -#include - -namespace sprout { - // - // string_ref - // wstring_ref - // u16string_ref - // u32string_ref - // - typedef sprout::basic_string_ref string_ref; - typedef sprout::basic_string_ref wstring_ref; -#if SPROUT_USE_UNICODE_LITERALS - typedef sprout::basic_string_ref u16string_ref; - typedef sprout::basic_string_ref u32string_ref; -#endif -} // namespace sprout - -#endif // #ifndef SPROUT_UTILITY_STRING_REF_ALIAS_HPP diff --git a/sprout/utility/string_ref/string_view.hpp b/sprout/utility/string_ref/string_view.hpp deleted file mode 100644 index da959c27..00000000 --- a/sprout/utility/string_ref/string_view.hpp +++ /dev/null @@ -1,189 +0,0 @@ -/*============================================================================= - Copyright (c) 2011-2016 Bolero MURAKAMI - https://github.com/bolero-MURAKAMI/Sprout - - Distributed under the Boost Software License, Version 1.0. (See accompanying - file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -=============================================================================*/ -#ifndef SPROUT_UTILITY_STRING_REF_STRING_VIEW_HPP -#define SPROUT_UTILITY_STRING_REF_STRING_VIEW_HPP - -#include -#include -#include -#include - -namespace sprout { - // - // string_view - // wstring_view - // u16string_view - // u32string_view - // - typedef sprout::basic_string_ref string_view; - typedef sprout::basic_string_ref wstring_view; -#if SPROUT_USE_UNICODE_LITERALS - typedef sprout::basic_string_ref u16string_view; - typedef sprout::basic_string_ref u32string_view; -#endif - -#if SPROUT_USE_TEMPLATE_ALIASES - // - // basic_string_view - // - template > - using basic_string_view = sprout::basic_string_ref; -#endif // #if SPROUT_USE_TEMPLATE_ALIASES - - // - // to_string_view - // - template - inline SPROUT_CONSTEXPR sprout::basic_string_ref - to_string_view(sprout::basic_string_ref const& s) { - return sprout::to_string_ref(s); - } - template - inline SPROUT_CONSTEXPR sprout::basic_string_ref - to_string_view(sprout::basic_string const& s) { - return sprout::to_string_ref(s); - } - template - inline SPROUT_NON_CONSTEXPR sprout::basic_string_ref - to_string_view(std::basic_string const& s) { - return sprout::to_string_ref(s); - } - template - inline SPROUT_CONSTEXPR sprout::basic_string_ref - to_string_view(T const* str) { - return sprout::to_string_ref(str); - } - template - inline SPROUT_CONSTEXPR sprout::basic_string_ref - to_string_view(T const* str, std::size_t len) { - return sprout::to_string_ref(str, len); - } - - // - // is_basic_string_view - // -#if SPROUT_USE_TEMPLATE_ALIASES - template - using is_basic_string_view = sprout::is_basic_string_ref; -#else // #if SPROUT_USE_TEMPLATE_ALIASES - template - struct is_basic_string_view - : public sprout::is_basic_string_ref - {}; -#endif // #if SPROUT_USE_TEMPLATE_ALIASES - - // - // is_string_view_of - // -#if SPROUT_USE_TEMPLATE_ALIASES - template - using is_string_view_of = sprout::is_string_ref_of; -#else // #if SPROUT_USE_TEMPLATE_ALIASES - template - struct is_string_view_of - : public sprout::is_string_ref_of - {}; -#endif // #if SPROUT_USE_TEMPLATE_ALIASES - - // - // is_string_view - // -#if SPROUT_USE_TEMPLATE_ALIASES - template - using is_string_view = sprout::is_string_ref; -#else // #if SPROUT_USE_TEMPLATE_ALIASES - template - struct is_string_view - : public sprout::is_string_ref - {}; -#endif // #if SPROUT_USE_TEMPLATE_ALIASES - // - // is_wstring_view - // -#if SPROUT_USE_TEMPLATE_ALIASES - template - using is_wstring_view = sprout::is_wstring_ref; -#else // #if SPROUT_USE_TEMPLATE_ALIASES - template - struct is_wstring_view - : public sprout::is_wstring_ref - {}; -#endif // #if SPROUT_USE_TEMPLATE_ALIASES - -#if SPROUT_USE_UNICODE_LITERALS - // - // is_u16string_view - // -#if SPROUT_USE_TEMPLATE_ALIASES - template - using is_u16string_view = sprout::is_u16string_ref; -#else // #if SPROUT_USE_TEMPLATE_ALIASES - template - struct is_u16string_view - : public sprout::is_u16string_ref - {}; -#endif // #if SPROUT_USE_TEMPLATE_ALIASES - // - // is_u32string_view - // -#if SPROUT_USE_TEMPLATE_ALIASES - template - using is_u32string_view = sprout::is_u32string_ref; -#else // #if SPROUT_USE_TEMPLATE_ALIASES - template - struct is_u32string_view - : public sprout::is_u32string_ref - {}; -#endif // #if SPROUT_USE_TEMPLATE_ALIASES -#endif - -#if SPROUT_USE_VARIABLE_TEMPLATES - template - SPROUT_STATIC_CONSTEXPR bool is_basic_string_view_v = sprout::is_basic_string_view::value; - template - SPROUT_STATIC_CONSTEXPR bool is_string_view_of_v = sprout::is_string_view_of::value; - template - SPROUT_STATIC_CONSTEXPR bool is_string_view_v = sprout::is_string_view::value; - template - SPROUT_STATIC_CONSTEXPR bool is_wstring_view_v = sprout::is_wstring_view::value; -#if SPROUT_USE_UNICODE_LITERALS - template - SPROUT_STATIC_CONSTEXPR bool is_u16string_view_v = sprout::is_u16string_view::value; - template - SPROUT_STATIC_CONSTEXPR bool is_u32string_view_v = sprout::is_u32string_view::value; -#endif -#endif // #if SPROUT_USE_VARIABLE_TEMPLATES - - namespace udl { - // - // _sv - // - inline SPROUT_CONSTEXPR sprout::basic_string_ref - operator"" _sv(char const* s, std::size_t size) { - return sprout::basic_string_ref(s, size); - } - inline SPROUT_CONSTEXPR sprout::basic_string_ref - operator"" _sv(wchar_t const* s, std::size_t size) { - return sprout::basic_string_ref(s, size); - } -#if SPROUT_USE_UNICODE_LITERALS - inline SPROUT_CONSTEXPR sprout::basic_string_ref - operator"" _sv(char16_t const* s, std::size_t size) { - return sprout::basic_string_ref(s, size); - } - inline SPROUT_CONSTEXPR sprout::basic_string_ref - operator"" _sv(char32_t const* s, std::size_t size) { - return sprout::basic_string_ref(s, size); - } -#endif - } // namespace udl - - using sprout::udl::operator"" _sv; -} // namespace sprout - -#endif // #ifndef SPROUT_UTILITY_STRING_REF_STRING_VIEW_HPP diff --git a/sprout/utility/string_ref/type_traits.hpp b/sprout/utility/string_ref/type_traits.hpp deleted file mode 100644 index dab432d3..00000000 --- a/sprout/utility/string_ref/type_traits.hpp +++ /dev/null @@ -1,105 +0,0 @@ -/*============================================================================= - Copyright (c) 2011-2016 Bolero MURAKAMI - https://github.com/bolero-MURAKAMI/Sprout - - Distributed under the Boost Software License, Version 1.0. (See accompanying - file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -=============================================================================*/ -#ifndef SPROUT_UTILITY_STRING_REF_TYPE_TRAITS_HPP -#define SPROUT_UTILITY_STRING_REF_TYPE_TRAITS_HPP - -#include -#include -#include - -namespace sprout { - // - // is_basic_string_ref - // - template - struct is_basic_string_ref - : public sprout::false_type - {}; - template - struct is_basic_string_ref - : public sprout::is_basic_string_ref - {}; - template - struct is_basic_string_ref - : public sprout::is_basic_string_ref - {}; - template - struct is_basic_string_ref > - : public sprout::true_type - {}; - - // - // is_string_ref_of - // - template - struct is_string_ref_of - : public sprout::false_type - {}; - template - struct is_string_ref_of - : public sprout::is_string_ref_of - {}; - template - struct is_string_ref_of - : public sprout::is_string_ref_of - {}; - template - struct is_string_ref_of, Elem> - : public sprout::true_type - {}; - - // - // is_string_ref - // - template - struct is_string_ref - : public sprout::is_string_ref_of - {}; - // - // is_wstring_ref - // - template - struct is_wstring_ref - : public sprout::is_string_ref_of - {}; -#if SPROUT_USE_UNICODE_LITERALS - // - // is_u16string_ref - // - template - struct is_u16string_ref - : public sprout::is_string_ref_of - {}; - // - // is_u32string_ref - // - template - struct is_u32string_ref - : public sprout::is_string_ref_of - {}; -#endif - -#if SPROUT_USE_VARIABLE_TEMPLATES - template - SPROUT_STATIC_CONSTEXPR bool is_basic_string_ref_v = sprout::is_basic_string_ref::value; - template - SPROUT_STATIC_CONSTEXPR bool is_string_ref_of_v = sprout::is_string_ref_of::value; - template - SPROUT_STATIC_CONSTEXPR bool is_string_ref_v = sprout::is_string_ref::value; - template - SPROUT_STATIC_CONSTEXPR bool is_wstring_ref_v = sprout::is_wstring_ref::value; -#if SPROUT_USE_UNICODE_LITERALS - template - SPROUT_STATIC_CONSTEXPR bool is_u16string_ref_v = sprout::is_u16string_ref::value; - template - SPROUT_STATIC_CONSTEXPR bool is_u32string_ref_v = sprout::is_u32string_ref::value; -#endif -#endif // #if SPROUT_USE_VARIABLE_TEMPLATES -} // namespace sprout - -#endif // #ifndef SPROUT_UTILITY_STRING_REF_TYPE_TRAITS_HPP diff --git a/sprout/utility/string_ref/udl.hpp b/sprout/utility/string_ref/udl.hpp deleted file mode 100644 index 2c464473..00000000 --- a/sprout/utility/string_ref/udl.hpp +++ /dev/null @@ -1,48 +0,0 @@ -/*============================================================================= - Copyright (c) 2011-2016 Bolero MURAKAMI - https://github.com/bolero-MURAKAMI/Sprout - - Distributed under the Boost Software License, Version 1.0. (See accompanying - file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -=============================================================================*/ -#ifndef SPROUT_UTILITY_STRING_REF_UDL_HPP -#define SPROUT_UTILITY_STRING_REF_UDL_HPP - -#include -#include - -#if SPROUT_USE_USER_DEFINED_LITERALS - -#include - -namespace sprout { - namespace udl { - // - // _sr - // - inline SPROUT_CONSTEXPR sprout::basic_string_ref - operator"" _sr(char const* s, std::size_t size) { - return sprout::basic_string_ref(s, size); - } - inline SPROUT_CONSTEXPR sprout::basic_string_ref - operator"" _sr(wchar_t const* s, std::size_t size) { - return sprout::basic_string_ref(s, size); - } -#if SPROUT_USE_UNICODE_LITERALS - inline SPROUT_CONSTEXPR sprout::basic_string_ref - operator"" _sr(char16_t const* s, std::size_t size) { - return sprout::basic_string_ref(s, size); - } - inline SPROUT_CONSTEXPR sprout::basic_string_ref - operator"" _sr(char32_t const* s, std::size_t size) { - return sprout::basic_string_ref(s, size); - } -#endif - } // namespace udl - - using sprout::udl::operator"" _sr; -} // namespace sprout - -#endif // #if SPROUT_USE_USER_DEFINED_LITERALS - -#endif // #ifndef SPROUT_UTILITY_STRING_REF_UDL_HPP diff --git a/sprout/utility/string_view.hpp b/sprout/utility/string_view.hpp index 8437e1e4..c772d84d 100644 --- a/sprout/utility/string_view.hpp +++ b/sprout/utility/string_view.hpp @@ -9,6 +9,14 @@ #define SPROUT_UTILITY_STRING_VIEW_HPP #include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #endif // #ifndef SPROUT_UTILITY_STRING_VIEW_HPP diff --git a/sprout/utility/string_view/alias.hpp b/sprout/utility/string_view/alias.hpp new file mode 100644 index 00000000..2cd26928 --- /dev/null +++ b/sprout/utility/string_view/alias.hpp @@ -0,0 +1,29 @@ +/*============================================================================= + Copyright (c) 2011-2016 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_UTILITY_STRING_VIEW_ALIAS_HPP +#define SPROUT_UTILITY_STRING_VIEW_ALIAS_HPP + +#include +#include + +namespace sprout { + // + // string_view + // wstring_view + // u16string_view + // u32string_view + // + typedef sprout::basic_string_view string_view; + typedef sprout::basic_string_view wstring_view; +#if SPROUT_USE_UNICODE_LITERALS + typedef sprout::basic_string_view u16string_view; + typedef sprout::basic_string_view u32string_view; +#endif +} // namespace sprout + +#endif // #ifndef SPROUT_UTILITY_STRING_VIEW_ALIAS_HPP diff --git a/sprout/utility/string_ref/comparison.hpp b/sprout/utility/string_view/comparison.hpp similarity index 57% rename from sprout/utility/string_ref/comparison.hpp rename to sprout/utility/string_view/comparison.hpp index 177c74e8..48e7393e 100644 --- a/sprout/utility/string_ref/comparison.hpp +++ b/sprout/utility/string_view/comparison.hpp @@ -5,8 +5,8 @@ Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ -#ifndef SPROUT_UTILITY_STRING_REF_COMPARISON_HPP -#define SPROUT_UTILITY_STRING_REF_COMPARISON_HPP +#ifndef SPROUT_UTILITY_STRING_VIEW_COMPARISON_HPP +#define SPROUT_UTILITY_STRING_VIEW_COMPARISON_HPP #include #include @@ -23,94 +23,94 @@ namespace sprout { // template inline SPROUT_CONSTEXPR bool - operator==(sprout::basic_string_ref const& lhs, sprout::basic_string_ref const& rhs) { + operator==(sprout::basic_string_view const& lhs, sprout::basic_string_view const& rhs) { return lhs.compare(rhs) == 0; } template inline SPROUT_CONSTEXPR bool - operator==(sprout::basic_string_ref const& lhs, T const* rhs) { + operator==(sprout::basic_string_view const& lhs, T const* rhs) { return lhs.compare(rhs) == 0; } template inline SPROUT_CONSTEXPR bool - operator==(T const* lhs, sprout::basic_string_ref const& rhs) { + operator==(T const* lhs, sprout::basic_string_view const& rhs) { return 0 == rhs.compare(lhs); } template inline SPROUT_CONSTEXPR bool - operator!=(sprout::basic_string_ref const& lhs, sprout::basic_string_ref const& rhs) { + operator!=(sprout::basic_string_view const& lhs, sprout::basic_string_view const& rhs) { return !(lhs == rhs); } template inline SPROUT_CONSTEXPR bool - operator!=(sprout::basic_string_ref const& lhs, T const* rhs) { + operator!=(sprout::basic_string_view const& lhs, T const* rhs) { return !(lhs == rhs); } template inline SPROUT_CONSTEXPR bool - operator!=(T const* lhs, sprout::basic_string_ref const& rhs) { + operator!=(T const* lhs, sprout::basic_string_view const& rhs) { return !(lhs == rhs); } template inline SPROUT_CONSTEXPR bool - operator<(sprout::basic_string_ref const& lhs, sprout::basic_string_ref const& rhs) { + operator<(sprout::basic_string_view const& lhs, sprout::basic_string_view const& rhs) { return lhs.compare(rhs) < 0; } template inline SPROUT_CONSTEXPR bool - operator<(sprout::basic_string_ref const& lhs, T const* rhs) { + operator<(sprout::basic_string_view const& lhs, T const* rhs) { return lhs.compare(rhs) < 0; } template inline SPROUT_CONSTEXPR bool - operator<(T const* lhs, sprout::basic_string_ref const& rhs) { + operator<(T const* lhs, sprout::basic_string_view const& rhs) { return 0 < rhs.compare(lhs); } template inline SPROUT_CONSTEXPR bool - operator>(sprout::basic_string_ref const& lhs, sprout::basic_string_ref const& rhs) { + operator>(sprout::basic_string_view const& lhs, sprout::basic_string_view const& rhs) { return rhs < lhs; } template inline SPROUT_CONSTEXPR bool - operator>(sprout::basic_string_ref const& lhs, T const* rhs) { + operator>(sprout::basic_string_view const& lhs, T const* rhs) { return rhs < lhs; } template inline SPROUT_CONSTEXPR bool - operator>(T const* lhs, sprout::basic_string_ref const& rhs) { + operator>(T const* lhs, sprout::basic_string_view const& rhs) { return rhs < lhs; } template inline SPROUT_CONSTEXPR bool - operator<=(sprout::basic_string_ref const& lhs, sprout::basic_string_ref const& rhs) { + operator<=(sprout::basic_string_view const& lhs, sprout::basic_string_view const& rhs) { return !(rhs < lhs); } template inline SPROUT_CONSTEXPR bool - operator<=(sprout::basic_string_ref const& lhs, T const* rhs) { + operator<=(sprout::basic_string_view const& lhs, T const* rhs) { return !(rhs < lhs); } template inline SPROUT_CONSTEXPR bool - operator<=(T const* lhs, sprout::basic_string_ref const& rhs) { + operator<=(T const* lhs, sprout::basic_string_view const& rhs) { return !(rhs < lhs); } template inline SPROUT_CONSTEXPR bool - operator>=(sprout::basic_string_ref const& lhs, sprout::basic_string_ref const& rhs) { + operator>=(sprout::basic_string_view const& lhs, sprout::basic_string_view const& rhs) { return !(lhs < rhs); } template inline SPROUT_CONSTEXPR bool - operator>=(sprout::basic_string_ref const& lhs, T const* rhs) { + operator>=(sprout::basic_string_view const& lhs, T const* rhs) { return !(lhs < rhs); } template inline SPROUT_CONSTEXPR bool - operator>=(T const* lhs, sprout::basic_string_ref const& rhs) { + operator>=(T const* lhs, sprout::basic_string_view const& rhs) { return !(lhs < rhs); } } // namespace sprout -#endif // #ifndef SPROUT_UTILITY_STRING_REF_COMPARISON_HPP +#endif // #ifndef SPROUT_UTILITY_STRING_VIEW_COMPARISON_HPP diff --git a/sprout/utility/string_ref/conversion.hpp b/sprout/utility/string_view/conversion.hpp similarity index 65% rename from sprout/utility/string_ref/conversion.hpp rename to sprout/utility/string_view/conversion.hpp index bd69174f..7d4741f6 100644 --- a/sprout/utility/string_ref/conversion.hpp +++ b/sprout/utility/string_view/conversion.hpp @@ -5,10 +5,10 @@ Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ -#ifndef SPROUT_UTILITY_STRING_REF_CONVERSION_HPP -#define SPROUT_UTILITY_STRING_REF_CONVERSION_HPP +#ifndef SPROUT_UTILITY_STRING_VIEW_CONVERSION_HPP +#define SPROUT_UTILITY_STRING_VIEW_CONVERSION_HPP #include -#include +#include -#endif // #ifndef SPROUT_UTILITY_STRING_REF_CONVERSION_HPP +#endif // #ifndef SPROUT_UTILITY_STRING_VIEW_CONVERSION_HPP diff --git a/sprout/utility/string_ref/from_string.hpp b/sprout/utility/string_view/from_string.hpp similarity index 59% rename from sprout/utility/string_ref/from_string.hpp rename to sprout/utility/string_view/from_string.hpp index 1071b722..571716d7 100644 --- a/sprout/utility/string_ref/from_string.hpp +++ b/sprout/utility/string_view/from_string.hpp @@ -5,11 +5,11 @@ Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ -#ifndef SPROUT_UTILITY_STRING_REF_FROM_STRING_HPP -#define SPROUT_UTILITY_STRING_REF_FROM_STRING_HPP +#ifndef SPROUT_UTILITY_STRING_VIEW_FROM_STRING_HPP +#define SPROUT_UTILITY_STRING_VIEW_FROM_STRING_HPP #include -#include -#include +#include +#include -#endif // #ifndef SPROUT_UTILITY_STRING_REF_FROM_STRING_HPP +#endif // #ifndef SPROUT_UTILITY_STRING_VIEW_FROM_STRING_HPP diff --git a/sprout/utility/string_ref/hash.hpp b/sprout/utility/string_view/hash.hpp similarity index 70% rename from sprout/utility/string_ref/hash.hpp rename to sprout/utility/string_view/hash.hpp index 06312dc0..bd94f131 100644 --- a/sprout/utility/string_ref/hash.hpp +++ b/sprout/utility/string_view/hash.hpp @@ -5,13 +5,13 @@ Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ -#ifndef SPROUT_UTILITY_STRING_REF_HASH_HPP -#define SPROUT_UTILITY_STRING_REF_HASH_HPP +#ifndef SPROUT_UTILITY_STRING_VIEW_HASH_HPP +#define SPROUT_UTILITY_STRING_VIEW_HASH_HPP #include #include #include -#include +#include #include namespace sprout { @@ -20,7 +20,7 @@ namespace sprout { // template inline SPROUT_CONSTEXPR std::size_t - hash_value(sprout::basic_string_ref const& v) { + hash_value(sprout::basic_string_view const& v) { return sprout::hash_range(v); } } // namespace sprout @@ -34,12 +34,12 @@ namespace std { // hash // template - struct hash > - : public sprout::hash > + struct hash > + : public sprout::hash > {}; #if defined(__clang__) # pragma clang diagnostic pop #endif } // namespace std -#endif // #ifndef SPROUT_UTILITY_STRING_REF_HASH_HPP +#endif // #ifndef SPROUT_UTILITY_STRING_VIEW_HASH_HPP diff --git a/sprout/utility/string_ref/io.hpp b/sprout/utility/string_view/io.hpp similarity index 89% rename from sprout/utility/string_ref/io.hpp rename to sprout/utility/string_view/io.hpp index 5a1479f1..faec4f6b 100644 --- a/sprout/utility/string_ref/io.hpp +++ b/sprout/utility/string_view/io.hpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include namespace sprout { // @@ -21,7 +21,7 @@ namespace sprout { // template inline SPROUT_NON_CONSTEXPR std::basic_ostream& - operator<<(std::basic_ostream& lhs, sprout::basic_string_ref const& rhs) { + operator<<(std::basic_ostream& lhs, sprout::basic_string_view const& rhs) { sprout::copy(rhs.begin(), rhs.end(), std::ostreambuf_iterator(lhs)); return lhs; } diff --git a/sprout/utility/string_view/string_ref.hpp b/sprout/utility/string_view/string_ref.hpp new file mode 100644 index 00000000..f6d7c96f --- /dev/null +++ b/sprout/utility/string_view/string_ref.hpp @@ -0,0 +1,189 @@ +/*============================================================================= + Copyright (c) 2011-2016 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_UTILITY_STRING_VIEW_STRING_REF_HPP +#define SPROUT_UTILITY_STRING_VIEW_STRING_REF_HPP + +#include +#include +#include +#include + +namespace sprout { + // + // string_ref + // wstring_ref + // u16string_ref + // u32string_ref + // + typedef sprout::basic_string_view string_ref; + typedef sprout::basic_string_view wstring_ref; +#if SPROUT_USE_UNICODE_LITERALS + typedef sprout::basic_string_view u16string_ref; + typedef sprout::basic_string_view u32string_ref; +#endif + +#if SPROUT_USE_TEMPLATE_ALIASES + // + // basic_string_ref + // + template > + using basic_string_ref = sprout::basic_string_view; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES + + // + // to_string_ref + // + template + inline SPROUT_CONSTEXPR sprout::basic_string_view + to_string_ref(sprout::basic_string_view const& s) { + return sprout::to_string_view(s); + } + template + inline SPROUT_CONSTEXPR sprout::basic_string_view + to_string_ref(sprout::basic_string const& s) { + return sprout::to_string_view(s); + } + template + inline SPROUT_NON_CONSTEXPR sprout::basic_string_view + to_string_ref(std::basic_string const& s) { + return sprout::to_string_view(s); + } + template + inline SPROUT_CONSTEXPR sprout::basic_string_view + to_string_ref(T const* str) { + return sprout::to_string_view(str); + } + template + inline SPROUT_CONSTEXPR sprout::basic_string_view + to_string_ref(T const* str, std::size_t len) { + return sprout::to_string_view(str, len); + } + + // + // is_basic_string_ref + // +#if SPROUT_USE_TEMPLATE_ALIASES + template + using is_basic_string_ref = sprout::is_basic_string_view; +#else // #if SPROUT_USE_TEMPLATE_ALIASES + template + struct is_basic_string_ref + : public sprout::is_basic_string_view + {}; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES + + // + // is_string_ref_of + // +#if SPROUT_USE_TEMPLATE_ALIASES + template + using is_string_ref_of = sprout::is_string_view_of; +#else // #if SPROUT_USE_TEMPLATE_ALIASES + template + struct is_string_ref_of + : public sprout::is_string_view_of + {}; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES + + // + // is_string_ref + // +#if SPROUT_USE_TEMPLATE_ALIASES + template + using is_string_ref = sprout::is_string_view; +#else // #if SPROUT_USE_TEMPLATE_ALIASES + template + struct is_string_ref + : public sprout::is_string_view + {}; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES + // + // is_wstring_ref + // +#if SPROUT_USE_TEMPLATE_ALIASES + template + using is_wstring_ref = sprout::is_wstring_view; +#else // #if SPROUT_USE_TEMPLATE_ALIASES + template + struct is_wstring_ref + : public sprout::is_wstring_view + {}; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES + +#if SPROUT_USE_UNICODE_LITERALS + // + // is_u16string_ref + // +#if SPROUT_USE_TEMPLATE_ALIASES + template + using is_u16string_ref = sprout::is_u16string_view; +#else // #if SPROUT_USE_TEMPLATE_ALIASES + template + struct is_u16string_ref + : public sprout::is_u16string_view + {}; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES + // + // is_u32string_ref + // +#if SPROUT_USE_TEMPLATE_ALIASES + template + using is_u32string_ref = sprout::is_u32string_view; +#else // #if SPROUT_USE_TEMPLATE_ALIASES + template + struct is_u32string_ref + : public sprout::is_u32string_view + {}; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES +#endif + +#if SPROUT_USE_VARIABLE_TEMPLATES + template + SPROUT_STATIC_CONSTEXPR bool is_basic_string_ref_v = sprout::is_basic_string_view::value; + template + SPROUT_STATIC_CONSTEXPR bool is_string_ref_of_v = sprout::is_string_view_of::value; + template + SPROUT_STATIC_CONSTEXPR bool is_string_ref_v = sprout::is_string_view::value; + template + SPROUT_STATIC_CONSTEXPR bool is_wstring_ref_v = sprout::is_wstring_view::value; +#if SPROUT_USE_UNICODE_LITERALS + template + SPROUT_STATIC_CONSTEXPR bool is_u16string_ref_v = sprout::is_u16string_view::value; + template + SPROUT_STATIC_CONSTEXPR bool is_u32string_ref_v = sprout::is_u32string_view::value; +#endif +#endif // #if SPROUT_USE_VARIABLE_TEMPLATES + + namespace udl { + // + // _sr + // + inline SPROUT_CONSTEXPR sprout::basic_string_view + operator"" _sr(char const* s, std::size_t size) { + return sprout::basic_string_view(s, size); + } + inline SPROUT_CONSTEXPR sprout::basic_string_view + operator"" _sr(wchar_t const* s, std::size_t size) { + return sprout::basic_string_view(s, size); + } +#if SPROUT_USE_UNICODE_LITERALS + inline SPROUT_CONSTEXPR sprout::basic_string_view + operator"" _sr(char16_t const* s, std::size_t size) { + return sprout::basic_string_view(s, size); + } + inline SPROUT_CONSTEXPR sprout::basic_string_view + operator"" _sr(char32_t const* s, std::size_t size) { + return sprout::basic_string_view(s, size); + } +#endif + } // namespace udl + + using sprout::udl::operator"" _sr; +} // namespace sprout + +#endif // #ifndef SPROUT_UTILITY_STRING_VIEW_STRING_REF_HPP diff --git a/sprout/utility/string_ref/string_to_float.hpp b/sprout/utility/string_view/string_to_float.hpp similarity index 72% rename from sprout/utility/string_ref/string_to_float.hpp rename to sprout/utility/string_view/string_to_float.hpp index bf4f6c15..8945d4a2 100644 --- a/sprout/utility/string_ref/string_to_float.hpp +++ b/sprout/utility/string_view/string_to_float.hpp @@ -5,13 +5,13 @@ Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ -#ifndef SPROUT_UTILITY_STRING_REF_STRING_TO_FLOAT_HPP -#define SPROUT_UTILITY_STRING_REF_STRING_TO_FLOAT_HPP +#ifndef SPROUT_UTILITY_STRING_VIEW_STRING_TO_FLOAT_HPP +#define SPROUT_UTILITY_STRING_VIEW_STRING_TO_FLOAT_HPP #include #include #include -#include +#include #include #include @@ -20,7 +20,7 @@ namespace sprout { template< typename FloatType, typename Elem, typename Traits > - inline FloatType string_to_float_dynamic(sprout::basic_string_ref const& str, std::size_t* idx) { + inline FloatType string_to_float_dynamic(sprout::basic_string_view const& str, std::size_t* idx) { Elem* endptr = nullptr; FloatType result = sprout::detail::str_to_float(str.c_str(), &endptr); *idx = endptr - str.c_str(); @@ -36,7 +36,7 @@ namespace sprout { typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR FloatType - string_to_float(sprout::basic_string_ref const& str, std::size_t* idx) { + string_to_float(sprout::basic_string_view const& str, std::size_t* idx) { return !idx ? sprout::detail::str_to_float(str.begin()) : sprout::detail::string_to_float_dynamic(str, idx) ; @@ -46,7 +46,7 @@ namespace sprout { typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR FloatType - string_to_float(sprout::basic_string_ref const& str) { + string_to_float(sprout::basic_string_view const& str) { return sprout::detail::str_to_float(str.begin()); } @@ -55,12 +55,12 @@ namespace sprout { // template inline SPROUT_CONSTEXPR float - stof(sprout::basic_string_ref const& str, std::size_t* idx) { + stof(sprout::basic_string_view const& str, std::size_t* idx) { return sprout::string_to_float(str, idx); } template inline SPROUT_CONSTEXPR float - stof(sprout::basic_string_ref const& str) { + stof(sprout::basic_string_view const& str) { return sprout::string_to_float(str); } @@ -69,12 +69,12 @@ namespace sprout { // template inline SPROUT_CONSTEXPR double - stod(sprout::basic_string_ref const& str, std::size_t* idx) { + stod(sprout::basic_string_view const& str, std::size_t* idx) { return sprout::string_to_float(str, idx); } template inline SPROUT_CONSTEXPR double - stod(sprout::basic_string_ref const& str) { + stod(sprout::basic_string_view const& str) { return sprout::string_to_float(str); } @@ -83,12 +83,12 @@ namespace sprout { // template inline SPROUT_CONSTEXPR long double - stold(sprout::basic_string_ref const& str, std::size_t* idx) { + stold(sprout::basic_string_view const& str, std::size_t* idx) { return sprout::string_to_float(str, idx); } template inline SPROUT_CONSTEXPR long double - stold(sprout::basic_string_ref const& str) { + stold(sprout::basic_string_view const& str) { return sprout::string_to_float(str); } @@ -100,7 +100,7 @@ namespace sprout { typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR FloatType - from_string(sprout::basic_string_ref const& str, std::size_t* idx) { + from_string(sprout::basic_string_view const& str, std::size_t* idx) { return sprout::string_to_float(str, idx); } template< @@ -108,9 +108,9 @@ namespace sprout { typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR FloatType - from_string(sprout::basic_string_ref const& str) { + from_string(sprout::basic_string_view const& str) { return sprout::string_to_float(str); } } // namespace sprout -#endif // #ifndef SPROUT_UTILITY_STRING_REF_STRING_TO_FLOAT_HPP +#endif // #ifndef SPROUT_UTILITY_STRING_VIEW_STRING_TO_FLOAT_HPP diff --git a/sprout/utility/string_ref/string_to_int.hpp b/sprout/utility/string_view/string_to_int.hpp similarity index 69% rename from sprout/utility/string_ref/string_to_int.hpp rename to sprout/utility/string_view/string_to_int.hpp index a2429bab..ef4fad6c 100644 --- a/sprout/utility/string_ref/string_to_int.hpp +++ b/sprout/utility/string_view/string_to_int.hpp @@ -5,14 +5,14 @@ Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ -#ifndef SPROUT_UTILITY_STRING_REF_STRING_TO_INT_HPP -#define SPROUT_UTILITY_STRING_REF_STRING_TO_INT_HPP +#ifndef SPROUT_UTILITY_STRING_VIEW_STRING_TO_INT_HPP +#define SPROUT_UTILITY_STRING_VIEW_STRING_TO_INT_HPP #include #include #include #include -#include +#include #include #include @@ -20,7 +20,7 @@ namespace sprout { namespace detail { template inline IntType - string_to_int_dynamic(sprout::basic_string_ref const& str, std::size_t* idx, int base = 10) { + string_to_int_dynamic(sprout::basic_string_view const& str, std::size_t* idx, int base = 10) { Elem* endptr = nullptr; IntType result = sprout::detail::str_to_int(str.c_str(), &endptr, base); *idx = endptr - str.c_str(); @@ -36,7 +36,7 @@ namespace sprout { typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR IntType - string_to_int(sprout::basic_string_ref const& str, std::size_t* idx, int base = 10) { + string_to_int(sprout::basic_string_view const& str, std::size_t* idx, int base = 10) { return !idx ? sprout::detail::str_to_int(str.begin(), base) : sprout::detail::string_to_int_dynamic(str, idx, base) ; @@ -46,7 +46,7 @@ namespace sprout { typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR IntType - string_to_int(sprout::basic_string_ref const& str, int base = 10) { + string_to_int(sprout::basic_string_view const& str, int base = 10) { return sprout::detail::str_to_int(str.begin(), base); } @@ -55,12 +55,12 @@ namespace sprout { // template inline SPROUT_CONSTEXPR int - stoi(sprout::basic_string_ref const& str, std::size_t* idx, int base = 10) { + stoi(sprout::basic_string_view const& str, std::size_t* idx, int base = 10) { return sprout::string_to_int(str, idx, base); } template inline SPROUT_CONSTEXPR int - stoi(sprout::basic_string_ref const& str, int base = 10) { + stoi(sprout::basic_string_view const& str, int base = 10) { return sprout::string_to_int(str, base); } @@ -69,12 +69,12 @@ namespace sprout { // template inline SPROUT_CONSTEXPR long - stol(sprout::basic_string_ref const& str, std::size_t* idx, int base = 10) { + stol(sprout::basic_string_view const& str, std::size_t* idx, int base = 10) { return sprout::string_to_int(str, idx, base); } template inline SPROUT_CONSTEXPR long - stol(sprout::basic_string_ref const& str, int base = 10) { + stol(sprout::basic_string_view const& str, int base = 10) { return sprout::string_to_int(str, base); } @@ -83,12 +83,12 @@ namespace sprout { // template inline SPROUT_CONSTEXPR unsigned long - stoul(sprout::basic_string_ref const& str, std::size_t* idx, int base = 10) { + stoul(sprout::basic_string_view const& str, std::size_t* idx, int base = 10) { return sprout::string_to_int(str, idx, base); } template inline SPROUT_CONSTEXPR unsigned long - stoul(sprout::basic_string_ref const& str, int base = 10) { + stoul(sprout::basic_string_view const& str, int base = 10) { return sprout::string_to_int(str, base); } @@ -97,12 +97,12 @@ namespace sprout { // template inline SPROUT_CONSTEXPR long long - stoll(sprout::basic_string_ref const& str, std::size_t* idx, int base = 10) { + stoll(sprout::basic_string_view const& str, std::size_t* idx, int base = 10) { return sprout::string_to_int(str, idx, base); } template inline SPROUT_CONSTEXPR long long - stoll(sprout::basic_string_ref const& str, int base = 10) { + stoll(sprout::basic_string_view const& str, int base = 10) { return sprout::string_to_int(str, base); } @@ -111,12 +111,12 @@ namespace sprout { // template inline SPROUT_CONSTEXPR unsigned long long - stoull(sprout::basic_string_ref const& str, std::size_t* idx, int base = 10) { + stoull(sprout::basic_string_view const& str, std::size_t* idx, int base = 10) { return sprout::string_to_int(str, idx, base); } template inline SPROUT_CONSTEXPR unsigned long long - stoull(sprout::basic_string_ref const& str, int base = 10) { + stoull(sprout::basic_string_view const& str, int base = 10) { return sprout::string_to_int(str, base); } @@ -125,12 +125,12 @@ namespace sprout { // template inline SPROUT_CONSTEXPR std::intmax_t - stoimax(sprout::basic_string_ref const& str, std::size_t* idx, int base = 10) { + stoimax(sprout::basic_string_view const& str, std::size_t* idx, int base = 10) { return sprout::string_to_int(str, idx, base); } template inline SPROUT_CONSTEXPR std::intmax_t - stoimax(sprout::basic_string_ref const& str, int base = 10) { + stoimax(sprout::basic_string_view const& str, int base = 10) { return sprout::string_to_int(str, base); } @@ -139,12 +139,12 @@ namespace sprout { // template inline SPROUT_CONSTEXPR std::uintmax_t - stoumax(sprout::basic_string_ref const& str, std::size_t* idx, int base = 10) { + stoumax(sprout::basic_string_view const& str, std::size_t* idx, int base = 10) { return sprout::string_to_int(str, idx, base); } template inline SPROUT_CONSTEXPR std::uintmax_t - stoumax(sprout::basic_string_ref const& str, int base = 10) { + stoumax(sprout::basic_string_view const& str, int base = 10) { return sprout::string_to_int(str, base); } @@ -156,7 +156,7 @@ namespace sprout { typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR IntType - from_string(sprout::basic_string_ref const& str, std::size_t* idx) { + from_string(sprout::basic_string_view const& str, std::size_t* idx) { return sprout::string_to_int(str, idx, 0); } template< @@ -164,9 +164,9 @@ namespace sprout { typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR IntType - from_string(sprout::basic_string_ref const& str) { + from_string(sprout::basic_string_view const& str) { return sprout::string_to_int(str, 0); } } // namespace sprout -#endif // #ifndef SPROUT_UTILITY_STRING_REF_STRING_TO_INT_HPP +#endif // #ifndef SPROUT_UTILITY_STRING_VIEW_STRING_TO_INT_HPP diff --git a/sprout/utility/string_ref/string_ref.hpp b/sprout/utility/string_view/string_view.hpp similarity index 68% rename from sprout/utility/string_ref/string_ref.hpp rename to sprout/utility/string_view/string_view.hpp index 84daf12a..35f73825 100644 --- a/sprout/utility/string_ref/string_ref.hpp +++ b/sprout/utility/string_view/string_view.hpp @@ -5,8 +5,8 @@ Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ -#ifndef SPROUT_UTILITY_STRING_REF_STRING_REF_HPP -#define SPROUT_UTILITY_STRING_REF_STRING_REF_HPP +#ifndef SPROUT_UTILITY_STRING_VIEW_STRING_VIEW_HPP +#define SPROUT_UTILITY_STRING_VIEW_STRING_VIEW_HPP #include #include @@ -29,15 +29,15 @@ namespace sprout { // - // basic_string_ref + // basic_string_view // template > - class basic_string_ref { + class basic_string_view { public: typedef T value_type; #if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION - typedef sprout::index_iterator iterator; - typedef sprout::index_iterator const_iterator; + typedef sprout::index_iterator iterator; + typedef sprout::index_iterator const_iterator; #else typedef T const* iterator; typedef T const* const_iterator; @@ -54,23 +54,23 @@ namespace sprout { #if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION private: template - class is_string_ref_iterator + class is_string_view_iterator : public sprout::bool_constant< - std::is_same >::value - || std::is_same >::value + std::is_same >::value + || std::is_same >::value > {}; template - class is_string_ref_iterator - : public is_string_ref_iterator + class is_string_view_iterator + : public is_string_view_iterator {}; template - class is_string_ref_iterator - : public is_string_ref_iterator + class is_string_view_iterator + : public is_string_view_iterator {}; template - class is_string_ref_iterator - : public is_string_ref_iterator + class is_string_view_iterator + : public is_string_view_iterator {}; #endif public: @@ -81,27 +81,27 @@ namespace sprout { private: public: // construct/copy/destroy: - SPROUT_CONSTEXPR basic_string_ref() + SPROUT_CONSTEXPR basic_string_view() : ptr_(0), len_(0) {} - basic_string_ref(basic_string_ref const& rhs) = default; - SPROUT_CXX14_CONSTEXPR basic_string_ref& operator=(basic_string_ref const& rhs) { - basic_string_ref temp(rhs); + basic_string_view(basic_string_view const& rhs) = default; + SPROUT_CXX14_CONSTEXPR basic_string_view& operator=(basic_string_view const& rhs) { + basic_string_view temp(rhs); temp.swap(*this); return *this; } - SPROUT_CONSTEXPR basic_string_ref(const_pointer str) + SPROUT_CONSTEXPR basic_string_view(const_pointer str) : ptr_(str), len_(traits_type::length(str)) {} template - SPROUT_CONSTEXPR basic_string_ref(sprout::basic_string const& str) + SPROUT_CONSTEXPR basic_string_view(sprout::basic_string const& str) : ptr_(str.data()), len_(str.size()) {} template - SPROUT_NON_CONSTEXPR basic_string_ref(std::basic_string const& str) + SPROUT_NON_CONSTEXPR basic_string_view(std::basic_string const& str) : ptr_(str.data()), len_(str.size()) {} - SPROUT_CONSTEXPR basic_string_ref(const_pointer str, size_type len) + SPROUT_CONSTEXPR basic_string_view(const_pointer str, size_type len) : ptr_(str), len_(len) {} // iterators: @@ -204,7 +204,7 @@ namespace sprout { SPROUT_CONSTEXPR const_reference at(size_type i) const { return i < size() ? ptr_[i] - : (throw std::out_of_range("basic_string_ref<>: index out of range"), ptr_[i]) + : (throw std::out_of_range("basic_string_view<>: index out of range"), ptr_[i]) ; } SPROUT_CONSTEXPR const_reference @@ -217,7 +217,7 @@ namespace sprout { } // modifiers: SPROUT_CXX14_CONSTEXPR void - swap(basic_string_ref& other) + swap(basic_string_view& other) SPROUT_NOEXCEPT { sprout::swap(ptr_, other.ptr_); @@ -231,10 +231,10 @@ namespace sprout { ptr_ += n; len_ -= n; } - SPROUT_CONSTEXPR basic_string_ref + SPROUT_CONSTEXPR basic_string_view remove_prefix(size_type n) const { - return n > size() ? basic_string_ref(ptr_ + size(), 0) - : basic_string_ref(ptr_ + n, size() - n) + return n > size() ? basic_string_view(ptr_ + size(), 0) + : basic_string_view(ptr_ + n, size() - n) ; } SPROUT_CXX14_CONSTEXPR void @@ -244,10 +244,10 @@ namespace sprout { } len_ -= n; } - SPROUT_CONSTEXPR basic_string_ref + SPROUT_CONSTEXPR basic_string_view remove_suffix(size_type n) const { - return n > size() ? basic_string_ref(ptr_, 0) - : basic_string_ref(ptr_, size() - n) + return n > size() ? basic_string_view(ptr_, 0) + : basic_string_view(ptr_, size() - n) ; } // string operations: @@ -261,12 +261,12 @@ namespace sprout { } SPROUT_CONSTEXPR size_type - find(basic_string_ref const& str, size_type pos = 0) const SPROUT_NOEXCEPT { - return sprout::string_detail::find_impl(begin(), size(), str.begin(), pos, str.size()); + find(basic_string_view const& str, size_type pos = 0) const SPROUT_NOEXCEPT { + return sprout::string_detail::find_impl(begin(), size(), str.begin(), pos, str.size()); } SPROUT_CONSTEXPR size_type find(value_type const* s, size_type pos, size_type n) const { - return sprout::string_detail::find_impl(begin(), size(), s, pos, n); + return sprout::string_detail::find_impl(begin(), size(), s, pos, n); } SPROUT_CONSTEXPR size_type find(value_type const* s, size_type pos = 0) const { @@ -274,15 +274,15 @@ namespace sprout { } SPROUT_CONSTEXPR size_type find(value_type c, size_type pos = 0) const { - return sprout::string_detail::find_c_impl(begin(), size(), c, pos); + return sprout::string_detail::find_c_impl(begin(), size(), c, pos); } SPROUT_CONSTEXPR size_type - rfind(basic_string_ref const& str, size_type pos = npos) const SPROUT_NOEXCEPT { - return sprout::string_detail::rfind_impl(begin(), size(), str.begin(), pos, str.size()); + rfind(basic_string_view const& str, size_type pos = npos) const SPROUT_NOEXCEPT { + return sprout::string_detail::rfind_impl(begin(), size(), str.begin(), pos, str.size()); } SPROUT_CONSTEXPR size_type rfind(value_type const* s, size_type pos, size_type n) const { - return sprout::string_detail::rfind_impl(begin(), size(), s, pos, n); + return sprout::string_detail::rfind_impl(begin(), size(), s, pos, n); } SPROUT_CONSTEXPR size_type rfind(value_type const* s, size_type pos = npos) const { @@ -290,15 +290,15 @@ namespace sprout { } SPROUT_CONSTEXPR size_type rfind(value_type c, size_type pos = npos) const { - return sprout::string_detail::rfind_c_impl(begin(), size(), c, pos); + return sprout::string_detail::rfind_c_impl(begin(), size(), c, pos); } SPROUT_CONSTEXPR size_type - find_first_of(basic_string_ref const& str, size_type pos = 0) const SPROUT_NOEXCEPT { - return sprout::string_detail::find_first_of_impl(begin(), size(), str.begin(), pos, str.size()); + find_first_of(basic_string_view const& str, size_type pos = 0) const SPROUT_NOEXCEPT { + return sprout::string_detail::find_first_of_impl(begin(), size(), str.begin(), pos, str.size()); } SPROUT_CONSTEXPR size_type find_first_of(value_type const* s, size_type pos, size_type n) const { - return sprout::string_detail::find_first_of_impl(begin(), size(), s, pos, n); + return sprout::string_detail::find_first_of_impl(begin(), size(), s, pos, n); } SPROUT_CONSTEXPR size_type find_first_of(value_type const* s, size_type pos = 0) const { @@ -309,12 +309,12 @@ namespace sprout { return find(c, pos); } SPROUT_CONSTEXPR size_type - find_last_of(basic_string_ref const& str, size_type pos = npos) const SPROUT_NOEXCEPT { - return sprout::string_detail::find_last_of_impl(begin(), size(), str.begin(), pos, str.size()); + find_last_of(basic_string_view const& str, size_type pos = npos) const SPROUT_NOEXCEPT { + return sprout::string_detail::find_last_of_impl(begin(), size(), str.begin(), pos, str.size()); } SPROUT_CONSTEXPR size_type find_last_of(value_type const* s, size_type pos, size_type n) const { - return sprout::string_detail::find_last_of_impl(begin(), size(), s, pos, n); + return sprout::string_detail::find_last_of_impl(begin(), size(), s, pos, n); } SPROUT_CONSTEXPR size_type find_last_of(value_type const* s, size_type pos = npos) const { @@ -325,12 +325,12 @@ namespace sprout { return rfind(c, pos); } SPROUT_CONSTEXPR size_type - find_first_not_of(basic_string_ref const& str, size_type pos = 0) const SPROUT_NOEXCEPT { - return sprout::string_detail::find_first_not_of_impl(begin(), size(), str.begin(), pos, str.size()); + find_first_not_of(basic_string_view const& str, size_type pos = 0) const SPROUT_NOEXCEPT { + return sprout::string_detail::find_first_not_of_impl(begin(), size(), str.begin(), pos, str.size()); } SPROUT_CONSTEXPR size_type find_first_not_of(value_type const* s, size_type pos, size_type n) const { - return sprout::string_detail::find_first_not_of_impl(begin(), size(), s, pos, n); + return sprout::string_detail::find_first_not_of_impl(begin(), size(), s, pos, n); } SPROUT_CONSTEXPR size_type find_first_not_of(value_type const* s, size_type pos = 0) const { @@ -338,15 +338,15 @@ namespace sprout { } SPROUT_CONSTEXPR size_type find_first_not_of(value_type c, size_type pos = 0) const { - return sprout::string_detail::find_first_not_of_c_impl(begin(), size(), c, pos); + return sprout::string_detail::find_first_not_of_c_impl(begin(), size(), c, pos); } SPROUT_CONSTEXPR size_type - find_last_not_of(basic_string_ref const& str, size_type pos = npos) const SPROUT_NOEXCEPT { - return sprout::string_detail::find_last_not_of_impl(begin(), size(), str.begin(), pos, str.size()); + find_last_not_of(basic_string_view const& str, size_type pos = npos) const SPROUT_NOEXCEPT { + return sprout::string_detail::find_last_not_of_impl(begin(), size(), str.begin(), pos, str.size()); } SPROUT_CONSTEXPR size_type find_last_not_of(value_type const* s, size_type pos, size_type n) const { - return sprout::string_detail::find_last_not_of_impl(begin(), size(), s, pos, n); + return sprout::string_detail::find_last_not_of_impl(begin(), size(), s, pos, n); } SPROUT_CONSTEXPR size_type find_last_not_of(value_type const* s, size_type pos = npos) const { @@ -354,7 +354,7 @@ namespace sprout { } SPROUT_CONSTEXPR size_type find_last_not_of(value_type c, size_type pos = npos) const { - return sprout::string_detail::find_last_not_of_c_impl(begin(), size(), c, pos); + return sprout::string_detail::find_last_not_of_c_impl(begin(), size(), c, pos); } SPROUT_CXX14_CONSTEXPR size_type copy(value_type* s, size_type n, size_type pos = 0) const { @@ -363,16 +363,16 @@ namespace sprout { traits_type::copy(s, begin() + pos, llen); return llen; } - SPROUT_CONSTEXPR basic_string_ref + SPROUT_CONSTEXPR basic_string_view substr(size_type pos = 0, size_type n = npos) const { return !(size() < pos) ? n == npos ? substr(pos, size() - pos) - : basic_string_ref(c_str() + pos, n) - : throw std::out_of_range("basic_string_ref<>: index out of range") + : basic_string_view(c_str() + pos, n) + : throw std::out_of_range("basic_string_view<>: index out of range") ; } SPROUT_CONSTEXPR int - compare(basic_string_ref const& str) const { + compare(basic_string_view const& str) const { return compare(0, size(), str.begin(), str.size()); } SPROUT_CONSTEXPR int @@ -380,7 +380,7 @@ namespace sprout { return compare(0, size(), s, traits_type::length(s)); } SPROUT_CONSTEXPR int - compare(size_type pos1, size_type n1, basic_string_ref const& str) const { + compare(size_type pos1, size_type n1, basic_string_view const& str) const { return compare(pos1, n1, str, 0, npos); } SPROUT_CONSTEXPR int @@ -388,17 +388,17 @@ namespace sprout { return compare(pos1, n1, s, traits_type::length(s)); } SPROUT_CONSTEXPR int - compare(size_type pos1, size_type n1, basic_string_ref const& str, size_type pos2, size_type n2) const { + compare(size_type pos1, size_type n1, basic_string_view const& str, size_type pos2, size_type n2) const { return !(str.size() < pos2) ? compare(pos1, n1, str.begin() + pos2, NS_SSCRISK_CEL_OR_SPROUT::min(n2, str.size() - pos2)) - : throw std::out_of_range("basic_string_ref<>: index out of range") + : throw std::out_of_range("basic_string_view<>: index out of range") ; } SPROUT_CONSTEXPR int compare(size_type pos1, size_type n1, value_type const* s, size_type n2) const { return !(size() < pos1) - ? sprout::string_detail::compare_impl(begin(), pos1, NS_SSCRISK_CEL_OR_SPROUT::min(n1, size() - pos1), s, n2) - : throw std::out_of_range("basic_string_ref<>: index out of range") + ? sprout::string_detail::compare_impl(begin(), pos1, NS_SSCRISK_CEL_OR_SPROUT::min(n1, size() - pos1), s, n2) + : throw std::out_of_range("basic_string_view<>: index out of range") ; } SPROUT_CONSTEXPR bool @@ -406,7 +406,7 @@ namespace sprout { return !empty() && traits_type::eq(c, front()); } SPROUT_CONSTEXPR bool - starts_with(basic_string_ref const& str) const { + starts_with(basic_string_view const& str) const { return size() >= str.size() && traits_type::compare(begin(), str.begin(), str.size()) == 0; } SPROUT_CONSTEXPR bool @@ -414,7 +414,7 @@ namespace sprout { return !empty() && traits_type::eq(c, back()); } SPROUT_CONSTEXPR bool - ends_with(basic_string_ref const& str) const { + ends_with(basic_string_view const& str) const { return size() >= str.size() && traits_type::compare(begin() + size() - str.size(), str.begin(), str.size()) == 0; } template @@ -438,7 +438,7 @@ namespace sprout { // others: SPROUT_CXX14_CONSTEXPR void rangecheck(size_type i) const { - return i >= size() ? throw std::out_of_range("basic_string_ref<>: index out of range") + return i >= size() ? throw std::out_of_range("basic_string_view<>: index out of range") : (void)0 ; } @@ -446,15 +446,15 @@ namespace sprout { #if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION template SPROUT_CONSTEXPR typename std::enable_if< - is_string_ref_iterator::value, + is_string_view_iterator::value, size_type >::type find(ConstIterator s, size_type pos, size_type n) const { - return sprout::string_detail::find_impl(begin(), size(), s, pos, n); + return sprout::string_detail::find_impl(begin(), size(), s, pos, n); } template SPROUT_CONSTEXPR typename std::enable_if< - is_string_ref_iterator::value, + is_string_view_iterator::value, size_type >::type find(ConstIterator s, size_type pos = 0) const { @@ -462,15 +462,15 @@ namespace sprout { } template SPROUT_CONSTEXPR typename std::enable_if< - is_string_ref_iterator::value, + is_string_view_iterator::value, size_type >::type rfind(ConstIterator s, size_type pos, size_type n) const { - return sprout::string_detail::rfind_impl(begin(), size(), s, pos, n); + return sprout::string_detail::rfind_impl(begin(), size(), s, pos, n); } template SPROUT_CONSTEXPR typename std::enable_if< - is_string_ref_iterator::value, + is_string_view_iterator::value, size_type >::type rfind(ConstIterator s, size_type pos = npos) const { @@ -478,15 +478,15 @@ namespace sprout { } template SPROUT_CONSTEXPR typename std::enable_if< - is_string_ref_iterator::value, + is_string_view_iterator::value, size_type >::type find_first_of(ConstIterator s, size_type pos, size_type n) const { - return sprout::string_detail::find_first_of_impl(begin(), size(), s, pos, n); + return sprout::string_detail::find_first_of_impl(begin(), size(), s, pos, n); } template SPROUT_CONSTEXPR typename std::enable_if< - is_string_ref_iterator::value, + is_string_view_iterator::value, size_type >::type find_first_of(ConstIterator s, size_type pos = 0) const { @@ -494,15 +494,15 @@ namespace sprout { } template SPROUT_CONSTEXPR typename std::enable_if< - is_string_ref_iterator::value, + is_string_view_iterator::value, size_type >::type find_last_of(ConstIterator s, size_type pos, size_type n) const { - return sprout::string_detail::find_last_of_impl(begin(), size(), s, pos, n); + return sprout::string_detail::find_last_of_impl(begin(), size(), s, pos, n); } template SPROUT_CONSTEXPR typename std::enable_if< - is_string_ref_iterator::value, + is_string_view_iterator::value, size_type >::type find_last_of(ConstIterator s, size_type pos = 0) const { @@ -510,39 +510,39 @@ namespace sprout { } template SPROUT_CONSTEXPR typename std::enable_if< - is_string_ref_iterator::value, + is_string_view_iterator::value, size_type >::type find_first_not_of(ConstIterator s, size_type pos, size_type n) const { - return sprout::string_detail::find_first_not_of_impl(begin(), size(), s, pos, n); + return sprout::string_detail::find_first_not_of_impl(begin(), size(), s, pos, n); } template SPROUT_CONSTEXPR typename std::enable_if< - is_string_ref_iterator::value, + is_string_view_iterator::value, size_type >::type find_first_not_of(ConstIterator s, size_type pos = 0) const { - return sprout::string_detail::find_first_not_of_impl(s, pos, traits_type::length(s)); + return sprout::string_detail::find_first_not_of_impl(s, pos, traits_type::length(s)); } template SPROUT_CONSTEXPR typename std::enable_if< - is_string_ref_iterator::value, + is_string_view_iterator::value, size_type >::type find_last_not_of(ConstIterator s, size_type pos, size_type n) const { - return sprout::string_detail::find_last_not_of_impl(begin(), size(), s, pos, n); + return sprout::string_detail::find_last_not_of_impl(begin(), size(), s, pos, n); } template SPROUT_CONSTEXPR typename std::enable_if< - is_string_ref_iterator::value, + is_string_view_iterator::value, size_type >::type find_last_not_of(ConstIterator s, size_type pos = npos) const { - return sprout::string_detail::find_last_not_of_impl(s, pos, traits_type::length(s)); + return sprout::string_detail::find_last_not_of_impl(s, pos, traits_type::length(s)); } template SPROUT_CONSTEXPR typename std::enable_if< - is_string_ref_iterator::value, + is_string_view_iterator::value, int >::type compare(ConstIterator s) const { @@ -550,7 +550,7 @@ namespace sprout { } template SPROUT_CONSTEXPR typename std::enable_if< - is_string_ref_iterator::value, + is_string_view_iterator::value, int >::type compare(size_type pos1, size_type n1, ConstIterator s) const { @@ -558,59 +558,59 @@ namespace sprout { } template SPROUT_CONSTEXPR typename std::enable_if< - is_string_ref_iterator::value, + is_string_view_iterator::value, int >::type compare(size_type pos1, size_type n1, ConstIterator s, size_type n2) const { return !(size() < pos1) - ? sprout::string_detail::compare_impl(begin(), pos1, NS_SSCRISK_CEL_OR_SPROUT::min(n1, size() - pos1), s, n2) - : throw std::out_of_range("basic_string_ref<>: index out of range") + ? sprout::string_detail::compare_impl(begin(), pos1, NS_SSCRISK_CEL_OR_SPROUT::min(n1, size() - pos1), s, n2) + : throw std::out_of_range("basic_string_view<>: index out of range") ; } #endif }; template - SPROUT_CONSTEXPR_OR_CONST typename sprout::basic_string_ref::size_type sprout::basic_string_ref::npos; + SPROUT_CONSTEXPR_OR_CONST typename sprout::basic_string_view::size_type sprout::basic_string_view::npos; // // swap // template inline SPROUT_CXX14_CONSTEXPR void - swap(sprout::basic_string_ref& lhs, sprout::basic_string_ref& rhs) + swap(sprout::basic_string_view& lhs, sprout::basic_string_view& rhs) SPROUT_NOEXCEPT_IF_EXPR(lhs.swap(rhs)) { lhs.swap(rhs); } // - // to_string_ref + // to_string_view // template - inline SPROUT_CONSTEXPR sprout::basic_string_ref - to_string_ref(sprout::basic_string_ref const& s) { + inline SPROUT_CONSTEXPR sprout::basic_string_view + to_string_view(sprout::basic_string_view const& s) { return s; } template - inline SPROUT_CONSTEXPR sprout::basic_string_ref - to_string_ref(sprout::basic_string const& s) { - return sprout::basic_string_ref(s); + inline SPROUT_CONSTEXPR sprout::basic_string_view + to_string_view(sprout::basic_string const& s) { + return sprout::basic_string_view(s); } template - inline SPROUT_NON_CONSTEXPR sprout::basic_string_ref - to_string_ref(std::basic_string const& s) { - return sprout::basic_string_ref(s); + inline SPROUT_NON_CONSTEXPR sprout::basic_string_view + to_string_view(std::basic_string const& s) { + return sprout::basic_string_view(s); } template - inline SPROUT_CONSTEXPR sprout::basic_string_ref - to_string_ref(T const* str) { - return sprout::basic_string_ref(str); + inline SPROUT_CONSTEXPR sprout::basic_string_view + to_string_view(T const* str) { + return sprout::basic_string_view(str); } template - inline SPROUT_CONSTEXPR sprout::basic_string_ref - to_string_ref(T const* str, std::size_t len) { - return sprout::basic_string_ref(str, len); + inline SPROUT_CONSTEXPR sprout::basic_string_view + to_string_view(T const* str, std::size_t len) { + return sprout::basic_string_view(str, len); } } // namespace sprout -#endif // #ifndef SPROUT_UTILITY_STRING_REF_STRING_REF_HPP +#endif // #ifndef SPROUT_UTILITY_STRING_VIEW_STRING_VIEW_HPP diff --git a/sprout/utility/string_view/type_traits.hpp b/sprout/utility/string_view/type_traits.hpp new file mode 100644 index 00000000..632adf8d --- /dev/null +++ b/sprout/utility/string_view/type_traits.hpp @@ -0,0 +1,105 @@ +/*============================================================================= + Copyright (c) 2011-2016 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_UTILITY_STRING_VIEW_TYPE_TRAITS_HPP +#define SPROUT_UTILITY_STRING_VIEW_TYPE_TRAITS_HPP + +#include +#include +#include + +namespace sprout { + // + // is_basic_string_view + // + template + struct is_basic_string_view + : public sprout::false_type + {}; + template + struct is_basic_string_view + : public sprout::is_basic_string_view + {}; + template + struct is_basic_string_view + : public sprout::is_basic_string_view + {}; + template + struct is_basic_string_view > + : public sprout::true_type + {}; + + // + // is_string_view_of + // + template + struct is_string_view_of + : public sprout::false_type + {}; + template + struct is_string_view_of + : public sprout::is_string_view_of + {}; + template + struct is_string_view_of + : public sprout::is_string_view_of + {}; + template + struct is_string_view_of, Elem> + : public sprout::true_type + {}; + + // + // is_string_view + // + template + struct is_string_view + : public sprout::is_string_view_of + {}; + // + // is_wstring_view + // + template + struct is_wstring_view + : public sprout::is_string_view_of + {}; +#if SPROUT_USE_UNICODE_LITERALS + // + // is_u16string_view + // + template + struct is_u16string_view + : public sprout::is_string_view_of + {}; + // + // is_u32string_view + // + template + struct is_u32string_view + : public sprout::is_string_view_of + {}; +#endif + +#if SPROUT_USE_VARIABLE_TEMPLATES + template + SPROUT_STATIC_CONSTEXPR bool is_basic_string_view_v = sprout::is_basic_string_view::value; + template + SPROUT_STATIC_CONSTEXPR bool is_string_view_of_v = sprout::is_string_view_of::value; + template + SPROUT_STATIC_CONSTEXPR bool is_string_view_v = sprout::is_string_view::value; + template + SPROUT_STATIC_CONSTEXPR bool is_wstring_view_v = sprout::is_wstring_view::value; +#if SPROUT_USE_UNICODE_LITERALS + template + SPROUT_STATIC_CONSTEXPR bool is_u16string_view_v = sprout::is_u16string_view::value; + template + SPROUT_STATIC_CONSTEXPR bool is_u32string_view_v = sprout::is_u32string_view::value; +#endif +#endif // #if SPROUT_USE_VARIABLE_TEMPLATES +} // namespace sprout + +#endif // #ifndef SPROUT_UTILITY_STRING_VIEW_TYPE_TRAITS_HPP diff --git a/sprout/utility/string_view/udl.hpp b/sprout/utility/string_view/udl.hpp new file mode 100644 index 00000000..900c8a9b --- /dev/null +++ b/sprout/utility/string_view/udl.hpp @@ -0,0 +1,48 @@ +/*============================================================================= + Copyright (c) 2011-2016 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_UTILITY_STRING_VIEW_UDL_HPP +#define SPROUT_UTILITY_STRING_VIEW_UDL_HPP + +#include +#include + +#if SPROUT_USE_USER_DEFINED_LITERALS + +#include + +namespace sprout { + namespace udl { + // + // _sv + // + inline SPROUT_CONSTEXPR sprout::basic_string_view + operator"" _sv(char const* s, std::size_t size) { + return sprout::basic_string_view(s, size); + } + inline SPROUT_CONSTEXPR sprout::basic_string_view + operator"" _sv(wchar_t const* s, std::size_t size) { + return sprout::basic_string_view(s, size); + } +#if SPROUT_USE_UNICODE_LITERALS + inline SPROUT_CONSTEXPR sprout::basic_string_view + operator"" _sv(char16_t const* s, std::size_t size) { + return sprout::basic_string_view(s, size); + } + inline SPROUT_CONSTEXPR sprout::basic_string_view + operator"" _sv(char32_t const* s, std::size_t size) { + return sprout::basic_string_view(s, size); + } +#endif + } // namespace udl + + using sprout::udl::operator"" _sv; +} // namespace sprout + +#endif // #if SPROUT_USE_USER_DEFINED_LITERALS + +#endif // #ifndef SPROUT_UTILITY_STRING_VIEW_UDL_HPP diff --git a/testspr/sprout.cpp b/testspr/sprout.cpp index 5e59425d..40dce65e 100644 --- a/testspr/sprout.cpp +++ b/testspr/sprout.cpp @@ -21,7 +21,7 @@ #include "../libs/variant/test/variant.cpp" #include "../libs/algorithm/test/algorithm.cpp" #include "../libs/random/test/random.cpp" -#include "../libs/utility/string_ref/test/string_ref.cpp" +#include "../libs/utility/string_view/test/string_view.cpp" #include "../libs/cstring/test/cstring.cpp" #include "../libs/net/test/endian.cpp" @@ -39,7 +39,7 @@ namespace testspr { testspr::variant_test(); testspr::algorithm_test(); testspr::random_test(); - testspr::string_ref_test(); + testspr::string_view_test(); testspr::cstring_test(); testspr::endian_test(); }