mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2025-08-03 12:49:50 +00:00
rename string_ref -> string_view (string_ref is deprecated)
This commit is contained in:
parent
276b09f004
commit
b5699163e8
25 changed files with 605 additions and 605 deletions
29
sprout/utility/string_view/alias.hpp
Normal file
29
sprout/utility/string_view/alias.hpp
Normal file
|
@ -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 <sprout/config.hpp>
|
||||
#include <sprout/utility/string_view/string_view.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// string_view
|
||||
// wstring_view
|
||||
// u16string_view
|
||||
// u32string_view
|
||||
//
|
||||
typedef sprout::basic_string_view<char> string_view;
|
||||
typedef sprout::basic_string_view<wchar_t> wstring_view;
|
||||
#if SPROUT_USE_UNICODE_LITERALS
|
||||
typedef sprout::basic_string_view<char16_t> u16string_view;
|
||||
typedef sprout::basic_string_view<char32_t> u32string_view;
|
||||
#endif
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_UTILITY_STRING_VIEW_ALIAS_HPP
|
116
sprout/utility/string_view/comparison.hpp
Normal file
116
sprout/utility/string_view/comparison.hpp
Normal file
|
@ -0,0 +1,116 @@
|
|||
/*=============================================================================
|
||||
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_COMPARISON_HPP
|
||||
#define SPROUT_UTILITY_STRING_VIEW_COMPARISON_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/workaround/std/cstddef.hpp>
|
||||
#include <sprout/string/string.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// operator==
|
||||
// operator!=
|
||||
// operator<
|
||||
// operator>
|
||||
// operator<=
|
||||
// operator>=
|
||||
//
|
||||
template<typename T, typename Traits>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
operator==(sprout::basic_string_view<T, Traits> const& lhs, sprout::basic_string_view<T, Traits> const& rhs) {
|
||||
return lhs.compare(rhs) == 0;
|
||||
}
|
||||
template<typename T, typename Traits>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
operator==(sprout::basic_string_view<T, Traits> const& lhs, T const* rhs) {
|
||||
return lhs.compare(rhs) == 0;
|
||||
}
|
||||
template<typename T, typename Traits>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
operator==(T const* lhs, sprout::basic_string_view<T, Traits> const& rhs) {
|
||||
return 0 == rhs.compare(lhs);
|
||||
}
|
||||
template<typename T, typename Traits>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
operator!=(sprout::basic_string_view<T, Traits> const& lhs, sprout::basic_string_view<T, Traits> const& rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
template<typename T, typename Traits>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
operator!=(sprout::basic_string_view<T, Traits> const& lhs, T const* rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
template<typename T, typename Traits>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
operator!=(T const* lhs, sprout::basic_string_view<T, Traits> const& rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
template<typename T, typename Traits>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
operator<(sprout::basic_string_view<T, Traits> const& lhs, sprout::basic_string_view<T, Traits> const& rhs) {
|
||||
return lhs.compare(rhs) < 0;
|
||||
}
|
||||
template<typename T, typename Traits>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
operator<(sprout::basic_string_view<T, Traits> const& lhs, T const* rhs) {
|
||||
return lhs.compare(rhs) < 0;
|
||||
}
|
||||
template<typename T, typename Traits>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
operator<(T const* lhs, sprout::basic_string_view<T, Traits> const& rhs) {
|
||||
return 0 < rhs.compare(lhs);
|
||||
}
|
||||
template<typename T, typename Traits>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
operator>(sprout::basic_string_view<T, Traits> const& lhs, sprout::basic_string_view<T, Traits> const& rhs) {
|
||||
return rhs < lhs;
|
||||
}
|
||||
template<typename T, typename Traits>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
operator>(sprout::basic_string_view<T, Traits> const& lhs, T const* rhs) {
|
||||
return rhs < lhs;
|
||||
}
|
||||
template<typename T, typename Traits>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
operator>(T const* lhs, sprout::basic_string_view<T, Traits> const& rhs) {
|
||||
return rhs < lhs;
|
||||
}
|
||||
template<typename T, typename Traits>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
operator<=(sprout::basic_string_view<T, Traits> const& lhs, sprout::basic_string_view<T, Traits> const& rhs) {
|
||||
return !(rhs < lhs);
|
||||
}
|
||||
template<typename T, typename Traits>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
operator<=(sprout::basic_string_view<T, Traits> const& lhs, T const* rhs) {
|
||||
return !(rhs < lhs);
|
||||
}
|
||||
template<typename T, typename Traits>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
operator<=(T const* lhs, sprout::basic_string_view<T, Traits> const& rhs) {
|
||||
return !(rhs < lhs);
|
||||
}
|
||||
template<typename T, typename Traits>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
operator>=(sprout::basic_string_view<T, Traits> const& lhs, sprout::basic_string_view<T, Traits> const& rhs) {
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
template<typename T, typename Traits>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
operator>=(sprout::basic_string_view<T, Traits> const& lhs, T const* rhs) {
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
template<typename T, typename Traits>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
operator>=(T const* lhs, sprout::basic_string_view<T, Traits> const& rhs) {
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_UTILITY_STRING_VIEW_COMPARISON_HPP
|
14
sprout/utility/string_view/conversion.hpp
Normal file
14
sprout/utility/string_view/conversion.hpp
Normal file
|
@ -0,0 +1,14 @@
|
|||
/*=============================================================================
|
||||
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_CONVERSION_HPP
|
||||
#define SPROUT_UTILITY_STRING_VIEW_CONVERSION_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/utility/string_view/from_string.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_UTILITY_STRING_VIEW_CONVERSION_HPP
|
15
sprout/utility/string_view/from_string.hpp
Normal file
15
sprout/utility/string_view/from_string.hpp
Normal file
|
@ -0,0 +1,15 @@
|
|||
/*=============================================================================
|
||||
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_FROM_STRING_HPP
|
||||
#define SPROUT_UTILITY_STRING_VIEW_FROM_STRING_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/utility/string_view/string_to_int.hpp>
|
||||
#include <sprout/utility/string_view/string_to_float.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_UTILITY_STRING_VIEW_FROM_STRING_HPP
|
45
sprout/utility/string_view/hash.hpp
Normal file
45
sprout/utility/string_view/hash.hpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*=============================================================================
|
||||
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_HASH_HPP
|
||||
#define SPROUT_UTILITY_STRING_VIEW_HASH_HPP
|
||||
|
||||
#include <functional>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/workaround/std/cstddef.hpp>
|
||||
#include <sprout/utility/string_view/string_view.hpp>
|
||||
#include <sprout/functional/hash.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// hash_value
|
||||
//
|
||||
template<typename T, typename Traits>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_value(sprout::basic_string_view<T, Traits> const& v) {
|
||||
return sprout::hash_range(v);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
namespace std {
|
||||
#if defined(__clang__)
|
||||
# pragma clang diagnostic push
|
||||
# pragma clang diagnostic ignored "-Wmismatched-tags"
|
||||
#endif
|
||||
//
|
||||
// hash
|
||||
//
|
||||
template<typename T, typename Traits>
|
||||
struct hash<sprout::basic_string_view<T, Traits> >
|
||||
: public sprout::hash<sprout::basic_string_view<T, Traits> >
|
||||
{};
|
||||
#if defined(__clang__)
|
||||
# pragma clang diagnostic pop
|
||||
#endif
|
||||
} // namespace std
|
||||
|
||||
#endif // #ifndef SPROUT_UTILITY_STRING_VIEW_HASH_HPP
|
30
sprout/utility/string_view/io.hpp
Normal file
30
sprout/utility/string_view/io.hpp
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*=============================================================================
|
||||
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_IO_HPP
|
||||
#define SPROUT_UTILITY_STRING_IO_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/algorithm/cxx14/copy.hpp>
|
||||
#include <sprout/utility/string_view/string_view.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// operator<<
|
||||
//
|
||||
template<typename T, typename Traits, typename StreamTraits>
|
||||
inline SPROUT_NON_CONSTEXPR std::basic_ostream<T, StreamTraits>&
|
||||
operator<<(std::basic_ostream<T, StreamTraits>& lhs, sprout::basic_string_view<T, Traits> const& rhs) {
|
||||
sprout::copy(rhs.begin(), rhs.end(), std::ostreambuf_iterator<T, StreamTraits>(lhs));
|
||||
return lhs;
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_UTILITY_STRING_IO_HPP
|
189
sprout/utility/string_view/string_ref.hpp
Normal file
189
sprout/utility/string_view/string_ref.hpp
Normal file
|
@ -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 <sprout/config.hpp>
|
||||
#include <sprout/string/char_traits.hpp>
|
||||
#include <sprout/utility/string_view/string_view.hpp>
|
||||
#include <sprout/utility/string_view/type_traits.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// string_ref
|
||||
// wstring_ref
|
||||
// u16string_ref
|
||||
// u32string_ref
|
||||
//
|
||||
typedef sprout::basic_string_view<char> string_ref;
|
||||
typedef sprout::basic_string_view<wchar_t> wstring_ref;
|
||||
#if SPROUT_USE_UNICODE_LITERALS
|
||||
typedef sprout::basic_string_view<char16_t> u16string_ref;
|
||||
typedef sprout::basic_string_view<char32_t> u32string_ref;
|
||||
#endif
|
||||
|
||||
#if SPROUT_USE_TEMPLATE_ALIASES
|
||||
//
|
||||
// basic_string_ref
|
||||
//
|
||||
template<typename T, typename Traits = sprout::char_traits<T> >
|
||||
using basic_string_ref = sprout::basic_string_view<T, Traits>;
|
||||
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
|
||||
|
||||
//
|
||||
// to_string_ref
|
||||
//
|
||||
template<typename T, typename Traits>
|
||||
inline SPROUT_CONSTEXPR sprout::basic_string_view<T, Traits>
|
||||
to_string_ref(sprout::basic_string_view<T, Traits> const& s) {
|
||||
return sprout::to_string_view(s);
|
||||
}
|
||||
template<typename T, std::size_t N, typename Traits>
|
||||
inline SPROUT_CONSTEXPR sprout::basic_string_view<T, Traits>
|
||||
to_string_ref(sprout::basic_string<T, N, Traits> const& s) {
|
||||
return sprout::to_string_view(s);
|
||||
}
|
||||
template<typename T, typename Traits>
|
||||
inline SPROUT_NON_CONSTEXPR sprout::basic_string_view<T, Traits>
|
||||
to_string_ref(std::basic_string<T, Traits> const& s) {
|
||||
return sprout::to_string_view(s);
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR sprout::basic_string_view<T>
|
||||
to_string_ref(T const* str) {
|
||||
return sprout::to_string_view(str);
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR sprout::basic_string_view<T>
|
||||
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<typename T>
|
||||
using is_basic_string_ref = sprout::is_basic_string_view<T>;
|
||||
#else // #if SPROUT_USE_TEMPLATE_ALIASES
|
||||
template<typename T>
|
||||
struct is_basic_string_ref
|
||||
: public sprout::is_basic_string_view<T>
|
||||
{};
|
||||
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
|
||||
|
||||
//
|
||||
// is_string_ref_of
|
||||
//
|
||||
#if SPROUT_USE_TEMPLATE_ALIASES
|
||||
template<typename T, typename Elem>
|
||||
using is_string_ref_of = sprout::is_string_view_of<T, Elem>;
|
||||
#else // #if SPROUT_USE_TEMPLATE_ALIASES
|
||||
template<typename T, typename Elem>
|
||||
struct is_string_ref_of
|
||||
: public sprout::is_string_view_of<T, Elem>
|
||||
{};
|
||||
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
|
||||
|
||||
//
|
||||
// is_string_ref
|
||||
//
|
||||
#if SPROUT_USE_TEMPLATE_ALIASES
|
||||
template<typename T>
|
||||
using is_string_ref = sprout::is_string_view<T>;
|
||||
#else // #if SPROUT_USE_TEMPLATE_ALIASES
|
||||
template<typename T, typename Elem>
|
||||
struct is_string_ref
|
||||
: public sprout::is_string_view<T>
|
||||
{};
|
||||
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
|
||||
//
|
||||
// is_wstring_ref
|
||||
//
|
||||
#if SPROUT_USE_TEMPLATE_ALIASES
|
||||
template<typename T>
|
||||
using is_wstring_ref = sprout::is_wstring_view<T>;
|
||||
#else // #if SPROUT_USE_TEMPLATE_ALIASES
|
||||
template<typename T, typename Elem>
|
||||
struct is_wstring_ref
|
||||
: public sprout::is_wstring_view<T>
|
||||
{};
|
||||
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
|
||||
|
||||
#if SPROUT_USE_UNICODE_LITERALS
|
||||
//
|
||||
// is_u16string_ref
|
||||
//
|
||||
#if SPROUT_USE_TEMPLATE_ALIASES
|
||||
template<typename T>
|
||||
using is_u16string_ref = sprout::is_u16string_view<T>;
|
||||
#else // #if SPROUT_USE_TEMPLATE_ALIASES
|
||||
template<typename T, typename Elem>
|
||||
struct is_u16string_ref
|
||||
: public sprout::is_u16string_view<T>
|
||||
{};
|
||||
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
|
||||
//
|
||||
// is_u32string_ref
|
||||
//
|
||||
#if SPROUT_USE_TEMPLATE_ALIASES
|
||||
template<typename T>
|
||||
using is_u32string_ref = sprout::is_u32string_view<T>;
|
||||
#else // #if SPROUT_USE_TEMPLATE_ALIASES
|
||||
template<typename T, typename Elem>
|
||||
struct is_u32string_ref
|
||||
: public sprout::is_u32string_view<T>
|
||||
{};
|
||||
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
|
||||
#endif
|
||||
|
||||
#if SPROUT_USE_VARIABLE_TEMPLATES
|
||||
template<typename T>
|
||||
SPROUT_STATIC_CONSTEXPR bool is_basic_string_ref_v = sprout::is_basic_string_view<T>::value;
|
||||
template<typename T, typename Elem>
|
||||
SPROUT_STATIC_CONSTEXPR bool is_string_ref_of_v = sprout::is_string_view_of<T, Elem>::value;
|
||||
template<typename T>
|
||||
SPROUT_STATIC_CONSTEXPR bool is_string_ref_v = sprout::is_string_view<T>::value;
|
||||
template<typename T>
|
||||
SPROUT_STATIC_CONSTEXPR bool is_wstring_ref_v = sprout::is_wstring_view<T>::value;
|
||||
#if SPROUT_USE_UNICODE_LITERALS
|
||||
template<typename T>
|
||||
SPROUT_STATIC_CONSTEXPR bool is_u16string_ref_v = sprout::is_u16string_view<T>::value;
|
||||
template<typename T>
|
||||
SPROUT_STATIC_CONSTEXPR bool is_u32string_ref_v = sprout::is_u32string_view<T>::value;
|
||||
#endif
|
||||
#endif // #if SPROUT_USE_VARIABLE_TEMPLATES
|
||||
|
||||
namespace udl {
|
||||
//
|
||||
// _sr
|
||||
//
|
||||
inline SPROUT_CONSTEXPR sprout::basic_string_view<char>
|
||||
operator"" _sr(char const* s, std::size_t size) {
|
||||
return sprout::basic_string_view<char>(s, size);
|
||||
}
|
||||
inline SPROUT_CONSTEXPR sprout::basic_string_view<wchar_t>
|
||||
operator"" _sr(wchar_t const* s, std::size_t size) {
|
||||
return sprout::basic_string_view<wchar_t>(s, size);
|
||||
}
|
||||
#if SPROUT_USE_UNICODE_LITERALS
|
||||
inline SPROUT_CONSTEXPR sprout::basic_string_view<char16_t>
|
||||
operator"" _sr(char16_t const* s, std::size_t size) {
|
||||
return sprout::basic_string_view<char16_t>(s, size);
|
||||
}
|
||||
inline SPROUT_CONSTEXPR sprout::basic_string_view<char32_t>
|
||||
operator"" _sr(char32_t const* s, std::size_t size) {
|
||||
return sprout::basic_string_view<char32_t>(s, size);
|
||||
}
|
||||
#endif
|
||||
} // namespace udl
|
||||
|
||||
using sprout::udl::operator"" _sr;
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_UTILITY_STRING_VIEW_STRING_REF_HPP
|
116
sprout/utility/string_view/string_to_float.hpp
Normal file
116
sprout/utility/string_view/string_to_float.hpp
Normal file
|
@ -0,0 +1,116 @@
|
|||
/*=============================================================================
|
||||
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_TO_FLOAT_HPP
|
||||
#define SPROUT_UTILITY_STRING_VIEW_STRING_TO_FLOAT_HPP
|
||||
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/utility/string_view/string_view.hpp>
|
||||
#include <sprout/cstdlib/str_to_float.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
template<
|
||||
typename FloatType, typename Elem, typename Traits
|
||||
>
|
||||
inline FloatType string_to_float_dynamic(sprout::basic_string_view<Elem, Traits> const& str, std::size_t* idx) {
|
||||
Elem* endptr = nullptr;
|
||||
FloatType result = sprout::detail::str_to_float<FloatType>(str.c_str(), &endptr);
|
||||
*idx = endptr - str.c_str();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// string_to_float
|
||||
//
|
||||
template<
|
||||
typename FloatType, typename Elem, typename Traits,
|
||||
typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR FloatType
|
||||
string_to_float(sprout::basic_string_view<Elem, Traits> const& str, std::size_t* idx) {
|
||||
return !idx ? sprout::detail::str_to_float<FloatType>(str.begin())
|
||||
: sprout::detail::string_to_float_dynamic<FloatType>(str, idx)
|
||||
;
|
||||
}
|
||||
template<
|
||||
typename FloatType, typename Elem, typename Traits,
|
||||
typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR FloatType
|
||||
string_to_float(sprout::basic_string_view<Elem, Traits> const& str) {
|
||||
return sprout::detail::str_to_float<FloatType>(str.begin());
|
||||
}
|
||||
|
||||
//
|
||||
// stof
|
||||
//
|
||||
template<typename Elem, typename Traits>
|
||||
inline SPROUT_CONSTEXPR float
|
||||
stof(sprout::basic_string_view<Elem, Traits> const& str, std::size_t* idx) {
|
||||
return sprout::string_to_float<float>(str, idx);
|
||||
}
|
||||
template<typename Elem, typename Traits>
|
||||
inline SPROUT_CONSTEXPR float
|
||||
stof(sprout::basic_string_view<Elem, Traits> const& str) {
|
||||
return sprout::string_to_float<float>(str);
|
||||
}
|
||||
|
||||
//
|
||||
// stod
|
||||
//
|
||||
template<typename Elem, typename Traits>
|
||||
inline SPROUT_CONSTEXPR double
|
||||
stod(sprout::basic_string_view<Elem, Traits> const& str, std::size_t* idx) {
|
||||
return sprout::string_to_float<double>(str, idx);
|
||||
}
|
||||
template<typename Elem, typename Traits>
|
||||
inline SPROUT_CONSTEXPR double
|
||||
stod(sprout::basic_string_view<Elem, Traits> const& str) {
|
||||
return sprout::string_to_float<double>(str);
|
||||
}
|
||||
|
||||
//
|
||||
// stold
|
||||
//
|
||||
template<typename Elem, typename Traits>
|
||||
inline SPROUT_CONSTEXPR long double
|
||||
stold(sprout::basic_string_view<Elem, Traits> const& str, std::size_t* idx) {
|
||||
return sprout::string_to_float<long double>(str, idx);
|
||||
}
|
||||
template<typename Elem, typename Traits>
|
||||
inline SPROUT_CONSTEXPR long double
|
||||
stold(sprout::basic_string_view<Elem, Traits> const& str) {
|
||||
return sprout::string_to_float<long double>(str);
|
||||
}
|
||||
|
||||
//
|
||||
// from_string
|
||||
//
|
||||
template<
|
||||
typename FloatType, typename Elem, typename Traits,
|
||||
typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR FloatType
|
||||
from_string(sprout::basic_string_view<Elem, Traits> const& str, std::size_t* idx) {
|
||||
return sprout::string_to_float<FloatType>(str, idx);
|
||||
}
|
||||
template<
|
||||
typename FloatType, typename Elem, typename Traits,
|
||||
typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR FloatType
|
||||
from_string(sprout::basic_string_view<Elem, Traits> const& str) {
|
||||
return sprout::string_to_float<FloatType>(str);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_UTILITY_STRING_VIEW_STRING_TO_FLOAT_HPP
|
172
sprout/utility/string_view/string_to_int.hpp
Normal file
172
sprout/utility/string_view/string_to_int.hpp
Normal file
|
@ -0,0 +1,172 @@
|
|||
/*=============================================================================
|
||||
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_TO_INT_HPP
|
||||
#define SPROUT_UTILITY_STRING_VIEW_STRING_TO_INT_HPP
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/utility/string_view/string_view.hpp>
|
||||
#include <sprout/cstdlib/str_to_int.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
template<typename IntType, typename Elem, typename Traits>
|
||||
inline IntType
|
||||
string_to_int_dynamic(sprout::basic_string_view<Elem, Traits> const& str, std::size_t* idx, int base = 10) {
|
||||
Elem* endptr = nullptr;
|
||||
IntType result = sprout::detail::str_to_int<IntType>(str.c_str(), &endptr, base);
|
||||
*idx = endptr - str.c_str();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// string_to_int
|
||||
//
|
||||
template<
|
||||
typename IntType, typename Elem, typename Traits,
|
||||
typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR IntType
|
||||
string_to_int(sprout::basic_string_view<Elem, Traits> const& str, std::size_t* idx, int base = 10) {
|
||||
return !idx ? sprout::detail::str_to_int<IntType>(str.begin(), base)
|
||||
: sprout::detail::string_to_int_dynamic<IntType>(str, idx, base)
|
||||
;
|
||||
}
|
||||
template<
|
||||
typename IntType, typename Elem, typename Traits,
|
||||
typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR IntType
|
||||
string_to_int(sprout::basic_string_view<Elem, Traits> const& str, int base = 10) {
|
||||
return sprout::detail::str_to_int<IntType>(str.begin(), base);
|
||||
}
|
||||
|
||||
//
|
||||
// stoi
|
||||
//
|
||||
template<typename Elem, typename Traits>
|
||||
inline SPROUT_CONSTEXPR int
|
||||
stoi(sprout::basic_string_view<Elem, Traits> const& str, std::size_t* idx, int base = 10) {
|
||||
return sprout::string_to_int<int>(str, idx, base);
|
||||
}
|
||||
template<typename Elem, typename Traits>
|
||||
inline SPROUT_CONSTEXPR int
|
||||
stoi(sprout::basic_string_view<Elem, Traits> const& str, int base = 10) {
|
||||
return sprout::string_to_int<int>(str, base);
|
||||
}
|
||||
|
||||
//
|
||||
// stol
|
||||
//
|
||||
template<typename Elem, typename Traits>
|
||||
inline SPROUT_CONSTEXPR long
|
||||
stol(sprout::basic_string_view<Elem, Traits> const& str, std::size_t* idx, int base = 10) {
|
||||
return sprout::string_to_int<long>(str, idx, base);
|
||||
}
|
||||
template<typename Elem, typename Traits>
|
||||
inline SPROUT_CONSTEXPR long
|
||||
stol(sprout::basic_string_view<Elem, Traits> const& str, int base = 10) {
|
||||
return sprout::string_to_int<long>(str, base);
|
||||
}
|
||||
|
||||
//
|
||||
// stoul
|
||||
//
|
||||
template<typename Elem, typename Traits>
|
||||
inline SPROUT_CONSTEXPR unsigned long
|
||||
stoul(sprout::basic_string_view<Elem, Traits> const& str, std::size_t* idx, int base = 10) {
|
||||
return sprout::string_to_int<unsigned long>(str, idx, base);
|
||||
}
|
||||
template<typename Elem, typename Traits>
|
||||
inline SPROUT_CONSTEXPR unsigned long
|
||||
stoul(sprout::basic_string_view<Elem, Traits> const& str, int base = 10) {
|
||||
return sprout::string_to_int<unsigned long>(str, base);
|
||||
}
|
||||
|
||||
//
|
||||
// stoll
|
||||
//
|
||||
template<typename Elem, typename Traits>
|
||||
inline SPROUT_CONSTEXPR long long
|
||||
stoll(sprout::basic_string_view<Elem, Traits> const& str, std::size_t* idx, int base = 10) {
|
||||
return sprout::string_to_int<long long>(str, idx, base);
|
||||
}
|
||||
template<typename Elem, typename Traits>
|
||||
inline SPROUT_CONSTEXPR long long
|
||||
stoll(sprout::basic_string_view<Elem, Traits> const& str, int base = 10) {
|
||||
return sprout::string_to_int<long long>(str, base);
|
||||
}
|
||||
|
||||
//
|
||||
// stoull
|
||||
//
|
||||
template<typename Elem, typename Traits>
|
||||
inline SPROUT_CONSTEXPR unsigned long long
|
||||
stoull(sprout::basic_string_view<Elem, Traits> const& str, std::size_t* idx, int base = 10) {
|
||||
return sprout::string_to_int<unsigned long long>(str, idx, base);
|
||||
}
|
||||
template<typename Elem, typename Traits>
|
||||
inline SPROUT_CONSTEXPR unsigned long long
|
||||
stoull(sprout::basic_string_view<Elem, Traits> const& str, int base = 10) {
|
||||
return sprout::string_to_int<unsigned long long>(str, base);
|
||||
}
|
||||
|
||||
//
|
||||
// stoimax
|
||||
//
|
||||
template<typename Elem, typename Traits>
|
||||
inline SPROUT_CONSTEXPR std::intmax_t
|
||||
stoimax(sprout::basic_string_view<Elem, Traits> const& str, std::size_t* idx, int base = 10) {
|
||||
return sprout::string_to_int<std::intmax_t>(str, idx, base);
|
||||
}
|
||||
template<typename Elem, typename Traits>
|
||||
inline SPROUT_CONSTEXPR std::intmax_t
|
||||
stoimax(sprout::basic_string_view<Elem, Traits> const& str, int base = 10) {
|
||||
return sprout::string_to_int<std::intmax_t>(str, base);
|
||||
}
|
||||
|
||||
//
|
||||
// stoumax
|
||||
//
|
||||
template<typename Elem, typename Traits>
|
||||
inline SPROUT_CONSTEXPR std::uintmax_t
|
||||
stoumax(sprout::basic_string_view<Elem, Traits> const& str, std::size_t* idx, int base = 10) {
|
||||
return sprout::string_to_int<std::uintmax_t>(str, idx, base);
|
||||
}
|
||||
template<typename Elem, typename Traits>
|
||||
inline SPROUT_CONSTEXPR std::uintmax_t
|
||||
stoumax(sprout::basic_string_view<Elem, Traits> const& str, int base = 10) {
|
||||
return sprout::string_to_int<std::uintmax_t>(str, base);
|
||||
}
|
||||
|
||||
//
|
||||
// from_string
|
||||
//
|
||||
template<
|
||||
typename IntType, typename Elem, typename Traits,
|
||||
typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR IntType
|
||||
from_string(sprout::basic_string_view<Elem, Traits> const& str, std::size_t* idx) {
|
||||
return sprout::string_to_int<IntType>(str, idx, 0);
|
||||
}
|
||||
template<
|
||||
typename IntType, typename Elem, typename Traits,
|
||||
typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR IntType
|
||||
from_string(sprout::basic_string_view<Elem, Traits> const& str) {
|
||||
return sprout::string_to_int<IntType>(str, 0);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_UTILITY_STRING_VIEW_STRING_TO_INT_HPP
|
616
sprout/utility/string_view/string_view.hpp
Normal file
616
sprout/utility/string_view/string_view.hpp
Normal file
|
@ -0,0 +1,616 @@
|
|||
/*=============================================================================
|
||||
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_VIEW_HPP
|
||||
#define SPROUT_UTILITY_STRING_VIEW_STRING_VIEW_HPP
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/workaround/std/cstddef.hpp>
|
||||
#include <sprout/iterator/reverse_iterator.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
#include <sprout/utility/swap.hpp>
|
||||
#include <sprout/string/char_traits.hpp>
|
||||
#include <sprout/string/npos.hpp>
|
||||
#include <sprout/string/string.hpp>
|
||||
#include <sprout/string/detail/operations.hpp>
|
||||
#include <sprout/type_traits/integral_constant.hpp>
|
||||
#include HDR_ALGORITHM_MIN_MAX_SSCRISK_CEL_OR_SPROUT
|
||||
#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION
|
||||
# include <sprout/iterator/index_iterator.hpp>
|
||||
#endif
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// basic_string_view
|
||||
//
|
||||
template<typename T, typename Traits = sprout::char_traits<T> >
|
||||
class basic_string_view {
|
||||
public:
|
||||
typedef T value_type;
|
||||
#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION
|
||||
typedef sprout::index_iterator<basic_string_view&, true> iterator;
|
||||
typedef sprout::index_iterator<basic_string_view const&, true> const_iterator;
|
||||
#else
|
||||
typedef T const* iterator;
|
||||
typedef T const* const_iterator;
|
||||
#endif
|
||||
typedef T const& reference;
|
||||
typedef T const& const_reference;
|
||||
typedef std::size_t size_type;
|
||||
typedef std::ptrdiff_t difference_type;
|
||||
typedef T const* pointer;
|
||||
typedef T const* const_pointer;
|
||||
typedef sprout::reverse_iterator<iterator> reverse_iterator;
|
||||
typedef sprout::reverse_iterator<const_iterator> const_reverse_iterator;
|
||||
typedef Traits traits_type;
|
||||
#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION
|
||||
private:
|
||||
template<typename Iterator>
|
||||
class is_string_view_iterator
|
||||
: public sprout::bool_constant<
|
||||
std::is_same<Iterator, sprout::index_iterator<basic_string_view&, true> >::value
|
||||
|| std::is_same<Iterator, sprout::index_iterator<basic_string_view const&, true> >::value
|
||||
>
|
||||
{};
|
||||
template<typename Iterator>
|
||||
class is_string_view_iterator<Iterator const>
|
||||
: public is_string_view_iterator<Iterator>
|
||||
{};
|
||||
template<typename Iterator>
|
||||
class is_string_view_iterator<Iterator volatile>
|
||||
: public is_string_view_iterator<Iterator>
|
||||
{};
|
||||
template<typename Iterator>
|
||||
class is_string_view_iterator<Iterator const volatile>
|
||||
: public is_string_view_iterator<Iterator>
|
||||
{};
|
||||
#endif
|
||||
public:
|
||||
SPROUT_STATIC_CONSTEXPR size_type npos = sprout::npos_t::get<size_type>::value;
|
||||
private:
|
||||
const_pointer ptr_;
|
||||
size_type len_;
|
||||
private:
|
||||
public:
|
||||
// construct/copy/destroy:
|
||||
SPROUT_CONSTEXPR basic_string_view()
|
||||
: ptr_(0), len_(0)
|
||||
{}
|
||||
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_view(const_pointer str)
|
||||
: ptr_(str), len_(traits_type::length(str))
|
||||
{}
|
||||
template<std::size_t N>
|
||||
SPROUT_CONSTEXPR basic_string_view(sprout::basic_string<T, N, Traits> const& str)
|
||||
: ptr_(str.data()), len_(str.size())
|
||||
{}
|
||||
template<typename Allocator>
|
||||
SPROUT_NON_CONSTEXPR basic_string_view(std::basic_string<T, Traits, Allocator> const& str)
|
||||
: ptr_(str.data()), len_(str.size())
|
||||
{}
|
||||
SPROUT_CONSTEXPR basic_string_view(const_pointer str, size_type len)
|
||||
: ptr_(str), len_(len)
|
||||
{}
|
||||
// iterators:
|
||||
#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION
|
||||
SPROUT_CXX14_CONSTEXPR iterator
|
||||
begin() SPROUT_NOEXCEPT {
|
||||
return iterator(*this, 0);
|
||||
}
|
||||
SPROUT_CONSTEXPR const_iterator
|
||||
begin() const SPROUT_NOEXCEPT {
|
||||
return const_iterator(*this, 0);
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR iterator
|
||||
end() SPROUT_NOEXCEPT {
|
||||
return iterator(*this, size());
|
||||
}
|
||||
SPROUT_CONSTEXPR const_iterator
|
||||
end() const SPROUT_NOEXCEPT {
|
||||
return const_iterator(*this, size());
|
||||
}
|
||||
#else
|
||||
SPROUT_CXX14_CONSTEXPR iterator
|
||||
begin() SPROUT_NOEXCEPT {
|
||||
return ptr_;
|
||||
}
|
||||
SPROUT_CONSTEXPR const_iterator
|
||||
begin() const SPROUT_NOEXCEPT {
|
||||
return ptr_;
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR iterator
|
||||
end() SPROUT_NOEXCEPT {
|
||||
return ptr_ + size();
|
||||
}
|
||||
SPROUT_CONSTEXPR const_iterator
|
||||
end() const SPROUT_NOEXCEPT {
|
||||
return ptr_ + size();
|
||||
}
|
||||
#endif
|
||||
SPROUT_CONSTEXPR const_reverse_iterator
|
||||
rbegin() const SPROUT_NOEXCEPT {
|
||||
return const_reverse_iterator(end());
|
||||
}
|
||||
SPROUT_CONSTEXPR const_reverse_iterator
|
||||
rend() const SPROUT_NOEXCEPT {
|
||||
return const_reverse_iterator(begin());
|
||||
}
|
||||
#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION
|
||||
SPROUT_CONSTEXPR const_iterator
|
||||
cbegin() const SPROUT_NOEXCEPT {
|
||||
return const_iterator(*this, 0);
|
||||
}
|
||||
SPROUT_CONSTEXPR const_iterator
|
||||
cend() const SPROUT_NOEXCEPT {
|
||||
return const_iterator(*this, size());
|
||||
}
|
||||
#else
|
||||
SPROUT_CONSTEXPR const_iterator
|
||||
cbegin() const SPROUT_NOEXCEPT {
|
||||
return ptr_;
|
||||
}
|
||||
SPROUT_CONSTEXPR const_iterator
|
||||
cend() const SPROUT_NOEXCEPT {
|
||||
return ptr_ + size();
|
||||
}
|
||||
#endif
|
||||
SPROUT_CONSTEXPR const_reverse_iterator
|
||||
crbegin() const SPROUT_NOEXCEPT {
|
||||
return const_reverse_iterator(end());
|
||||
}
|
||||
SPROUT_CONSTEXPR const_reverse_iterator
|
||||
crend() const SPROUT_NOEXCEPT {
|
||||
return const_reverse_iterator(begin());
|
||||
}
|
||||
// capacity:
|
||||
SPROUT_CONSTEXPR size_type
|
||||
size() const SPROUT_NOEXCEPT {
|
||||
return len_;
|
||||
}
|
||||
SPROUT_CONSTEXPR size_type
|
||||
length() const SPROUT_NOEXCEPT {
|
||||
return size();
|
||||
}
|
||||
SPROUT_CONSTEXPR size_type
|
||||
max_size() const SPROUT_NOEXCEPT {
|
||||
return size();
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
clear() {
|
||||
len_ = 0;
|
||||
}
|
||||
SPROUT_CONSTEXPR bool
|
||||
empty() const SPROUT_NOEXCEPT {
|
||||
return size() == 0;
|
||||
}
|
||||
// element access:
|
||||
SPROUT_CONSTEXPR const_reference
|
||||
operator[](size_type i) const {
|
||||
return ptr_[i];
|
||||
}
|
||||
SPROUT_CONSTEXPR const_reference
|
||||
at(size_type i) const {
|
||||
return i < size() ? ptr_[i]
|
||||
: (throw std::out_of_range("basic_string_view<>: index out of range"), ptr_[i])
|
||||
;
|
||||
}
|
||||
SPROUT_CONSTEXPR const_reference
|
||||
front() const {
|
||||
return ptr_[0];
|
||||
}
|
||||
SPROUT_CONSTEXPR const_reference
|
||||
back() const {
|
||||
return ptr_[size() - 1];
|
||||
}
|
||||
// modifiers:
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
swap(basic_string_view& other)
|
||||
SPROUT_NOEXCEPT
|
||||
{
|
||||
sprout::swap(ptr_, other.ptr_);
|
||||
sprout::swap(len_, other.len_);
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
remove_prefix(size_type n) {
|
||||
if (n > size()) {
|
||||
n = size();
|
||||
}
|
||||
ptr_ += n;
|
||||
len_ -= n;
|
||||
}
|
||||
SPROUT_CONSTEXPR basic_string_view
|
||||
remove_prefix(size_type n) const {
|
||||
return n > size() ? basic_string_view(ptr_ + size(), 0)
|
||||
: basic_string_view(ptr_ + n, size() - n)
|
||||
;
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
remove_suffix(size_type n) {
|
||||
if (n > size()) {
|
||||
n = size();
|
||||
}
|
||||
len_ -= n;
|
||||
}
|
||||
SPROUT_CONSTEXPR basic_string_view
|
||||
remove_suffix(size_type n) const {
|
||||
return n > size() ? basic_string_view(ptr_, 0)
|
||||
: basic_string_view(ptr_, size() - n)
|
||||
;
|
||||
}
|
||||
// string operations:
|
||||
SPROUT_CONSTEXPR const_pointer
|
||||
c_str() const SPROUT_NOEXCEPT {
|
||||
return data();
|
||||
}
|
||||
SPROUT_CONSTEXPR const_pointer
|
||||
data() const SPROUT_NOEXCEPT {
|
||||
return ptr_;
|
||||
}
|
||||
|
||||
SPROUT_CONSTEXPR size_type
|
||||
find(basic_string_view const& str, size_type pos = 0) const SPROUT_NOEXCEPT {
|
||||
return sprout::string_detail::find_impl<basic_string_view>(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<basic_string_view>(begin(), size(), s, pos, n);
|
||||
}
|
||||
SPROUT_CONSTEXPR size_type
|
||||
find(value_type const* s, size_type pos = 0) const {
|
||||
return find(s, pos, traits_type::length(s));
|
||||
}
|
||||
SPROUT_CONSTEXPR size_type
|
||||
find(value_type c, size_type pos = 0) const {
|
||||
return sprout::string_detail::find_c_impl<basic_string_view>(begin(), size(), c, pos);
|
||||
}
|
||||
SPROUT_CONSTEXPR size_type
|
||||
rfind(basic_string_view const& str, size_type pos = npos) const SPROUT_NOEXCEPT {
|
||||
return sprout::string_detail::rfind_impl<basic_string_view>(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<basic_string_view>(begin(), size(), s, pos, n);
|
||||
}
|
||||
SPROUT_CONSTEXPR size_type
|
||||
rfind(value_type const* s, size_type pos = npos) const {
|
||||
return rfind(s, pos, traits_type::length(s));
|
||||
}
|
||||
SPROUT_CONSTEXPR size_type
|
||||
rfind(value_type c, size_type pos = npos) const {
|
||||
return sprout::string_detail::rfind_c_impl<basic_string_view>(begin(), size(), c, pos);
|
||||
}
|
||||
SPROUT_CONSTEXPR size_type
|
||||
find_first_of(basic_string_view const& str, size_type pos = 0) const SPROUT_NOEXCEPT {
|
||||
return sprout::string_detail::find_first_of_impl<basic_string_view>(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<basic_string_view>(begin(), size(), s, pos, n);
|
||||
}
|
||||
SPROUT_CONSTEXPR size_type
|
||||
find_first_of(value_type const* s, size_type pos = 0) const {
|
||||
return find_first_of(s, pos, traits_type::length(s));
|
||||
}
|
||||
SPROUT_CONSTEXPR size_type
|
||||
find_first_of(value_type c, size_type pos = 0) const {
|
||||
return find(c, pos);
|
||||
}
|
||||
SPROUT_CONSTEXPR size_type
|
||||
find_last_of(basic_string_view const& str, size_type pos = npos) const SPROUT_NOEXCEPT {
|
||||
return sprout::string_detail::find_last_of_impl<basic_string_view>(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<basic_string_view>(begin(), size(), s, pos, n);
|
||||
}
|
||||
SPROUT_CONSTEXPR size_type
|
||||
find_last_of(value_type const* s, size_type pos = npos) const {
|
||||
return find_last_of(s, pos, traits_type::length(s));
|
||||
}
|
||||
SPROUT_CONSTEXPR size_type
|
||||
find_last_of(value_type c, size_type pos = npos) const {
|
||||
return rfind(c, pos);
|
||||
}
|
||||
SPROUT_CONSTEXPR size_type
|
||||
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<basic_string_view>(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<basic_string_view>(begin(), size(), s, pos, n);
|
||||
}
|
||||
SPROUT_CONSTEXPR size_type
|
||||
find_first_not_of(value_type const* s, size_type pos = 0) const {
|
||||
return find_first_not_of(s, pos, traits_type::length(s));
|
||||
}
|
||||
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<basic_string_view>(begin(), size(), c, pos);
|
||||
}
|
||||
SPROUT_CONSTEXPR size_type
|
||||
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<basic_string_view>(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<basic_string_view>(begin(), size(), s, pos, n);
|
||||
}
|
||||
SPROUT_CONSTEXPR size_type
|
||||
find_last_not_of(value_type const* s, size_type pos = npos) const {
|
||||
return find_last_not_of(s, pos, traits_type::length(s));
|
||||
}
|
||||
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<basic_string_view>(begin(), size(), c, pos);
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR size_type
|
||||
copy(value_type* s, size_type n, size_type pos = 0) const {
|
||||
rangecheck(pos);
|
||||
size_type llen = NS_SSCRISK_CEL_OR_SPROUT::min(n, size() - pos);
|
||||
traits_type::copy(s, begin() + pos, llen);
|
||||
return llen;
|
||||
}
|
||||
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_view(c_str() + pos, n)
|
||||
: throw std::out_of_range("basic_string_view<>: index out of range")
|
||||
;
|
||||
}
|
||||
SPROUT_CONSTEXPR int
|
||||
compare(basic_string_view const& str) const {
|
||||
return compare(0, size(), str.begin(), str.size());
|
||||
}
|
||||
SPROUT_CONSTEXPR int
|
||||
compare(value_type const* s) const {
|
||||
return compare(0, size(), s, traits_type::length(s));
|
||||
}
|
||||
SPROUT_CONSTEXPR int
|
||||
compare(size_type pos1, size_type n1, basic_string_view const& str) const {
|
||||
return compare(pos1, n1, str, 0, npos);
|
||||
}
|
||||
SPROUT_CONSTEXPR int
|
||||
compare(size_type pos1, size_type n1, value_type const* s) const {
|
||||
return compare(pos1, n1, s, traits_type::length(s));
|
||||
}
|
||||
SPROUT_CONSTEXPR int
|
||||
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_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<basic_string_view>(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
|
||||
starts_with(value_type c) const {
|
||||
return !empty() && traits_type::eq(c, front());
|
||||
}
|
||||
SPROUT_CONSTEXPR bool
|
||||
starts_with(basic_string_view const& str) const {
|
||||
return size() >= str.size() && traits_type::compare(begin(), str.begin(), str.size()) == 0;
|
||||
}
|
||||
SPROUT_CONSTEXPR bool
|
||||
ends_with(value_type c) const {
|
||||
return !empty() && traits_type::eq(c, back());
|
||||
}
|
||||
SPROUT_CONSTEXPR bool
|
||||
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<std::size_t N>
|
||||
SPROUT_NON_CONSTEXPR sprout::basic_string<T, N, Traits>
|
||||
to_string() const {
|
||||
return sprout::basic_string<T, N, Traits>(ptr_, size());
|
||||
}
|
||||
template<typename Allocator = std::allocator<T> >
|
||||
SPROUT_NON_CONSTEXPR std::basic_string<T, Traits, Allocator>
|
||||
to_string() const {
|
||||
return std::basic_string<T, Traits, Allocator>(ptr_, size());
|
||||
}
|
||||
template<std::size_t N>
|
||||
SPROUT_EXPLICIT_CONVERSION SPROUT_NON_CONSTEXPR operator sprout::basic_string<T, N, Traits>() const {
|
||||
return to_string<N>();
|
||||
}
|
||||
template<typename Allocator>
|
||||
SPROUT_EXPLICIT_CONVERSION SPROUT_NON_CONSTEXPR operator std::basic_string<T, Traits, Allocator>() const {
|
||||
return to_string<Allocator>();
|
||||
}
|
||||
// others:
|
||||
SPROUT_CXX14_CONSTEXPR void
|
||||
rangecheck(size_type i) const {
|
||||
return i >= size() ? throw std::out_of_range("basic_string_view<>: index out of range")
|
||||
: (void)0
|
||||
;
|
||||
}
|
||||
|
||||
#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION
|
||||
template<typename ConstIterator>
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
is_string_view_iterator<ConstIterator>::value,
|
||||
size_type
|
||||
>::type
|
||||
find(ConstIterator s, size_type pos, size_type n) const {
|
||||
return sprout::string_detail::find_impl<basic_string_view>(begin(), size(), s, pos, n);
|
||||
}
|
||||
template<typename ConstIterator>
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
is_string_view_iterator<ConstIterator>::value,
|
||||
size_type
|
||||
>::type
|
||||
find(ConstIterator s, size_type pos = 0) const {
|
||||
return find(s, pos, traits_type::length(s));
|
||||
}
|
||||
template<typename ConstIterator>
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
is_string_view_iterator<ConstIterator>::value,
|
||||
size_type
|
||||
>::type
|
||||
rfind(ConstIterator s, size_type pos, size_type n) const {
|
||||
return sprout::string_detail::rfind_impl<basic_string_view>(begin(), size(), s, pos, n);
|
||||
}
|
||||
template<typename ConstIterator>
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
is_string_view_iterator<ConstIterator>::value,
|
||||
size_type
|
||||
>::type
|
||||
rfind(ConstIterator s, size_type pos = npos) const {
|
||||
return rfind(s, pos, traits_type::length(s));
|
||||
}
|
||||
template<typename ConstIterator>
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
is_string_view_iterator<ConstIterator>::value,
|
||||
size_type
|
||||
>::type
|
||||
find_first_of(ConstIterator s, size_type pos, size_type n) const {
|
||||
return sprout::string_detail::find_first_of_impl<basic_string_view>(begin(), size(), s, pos, n);
|
||||
}
|
||||
template<typename ConstIterator>
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
is_string_view_iterator<ConstIterator>::value,
|
||||
size_type
|
||||
>::type
|
||||
find_first_of(ConstIterator s, size_type pos = 0) const {
|
||||
return find_first_of(s, pos, traits_type::length(s));
|
||||
}
|
||||
template<typename ConstIterator>
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
is_string_view_iterator<ConstIterator>::value,
|
||||
size_type
|
||||
>::type
|
||||
find_last_of(ConstIterator s, size_type pos, size_type n) const {
|
||||
return sprout::string_detail::find_last_of_impl<basic_string_view>(begin(), size(), s, pos, n);
|
||||
}
|
||||
template<typename ConstIterator>
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
is_string_view_iterator<ConstIterator>::value,
|
||||
size_type
|
||||
>::type
|
||||
find_last_of(ConstIterator s, size_type pos = 0) const {
|
||||
return find_last_of(s, pos, traits_type::length(s));
|
||||
}
|
||||
template<typename ConstIterator>
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
is_string_view_iterator<ConstIterator>::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<basic_string_view>(begin(), size(), s, pos, n);
|
||||
}
|
||||
template<typename ConstIterator>
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
is_string_view_iterator<ConstIterator>::value,
|
||||
size_type
|
||||
>::type
|
||||
find_first_not_of(ConstIterator s, size_type pos = 0) const {
|
||||
return sprout::string_detail::find_first_not_of_impl<basic_string_view>(s, pos, traits_type::length(s));
|
||||
}
|
||||
template<typename ConstIterator>
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
is_string_view_iterator<ConstIterator>::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<basic_string_view>(begin(), size(), s, pos, n);
|
||||
}
|
||||
template<typename ConstIterator>
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
is_string_view_iterator<ConstIterator>::value,
|
||||
size_type
|
||||
>::type
|
||||
find_last_not_of(ConstIterator s, size_type pos = npos) const {
|
||||
return sprout::string_detail::find_last_not_of_impl<basic_string_view>(s, pos, traits_type::length(s));
|
||||
}
|
||||
template<typename ConstIterator>
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
is_string_view_iterator<ConstIterator>::value,
|
||||
int
|
||||
>::type
|
||||
compare(ConstIterator s) const {
|
||||
return compare(0, size(), s, traits_type::length(s));
|
||||
}
|
||||
template<typename ConstIterator>
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
is_string_view_iterator<ConstIterator>::value,
|
||||
int
|
||||
>::type
|
||||
compare(size_type pos1, size_type n1, ConstIterator s) const {
|
||||
return compare(pos1, n1, s, traits_type::length(s));
|
||||
}
|
||||
template<typename ConstIterator>
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
is_string_view_iterator<ConstIterator>::value,
|
||||
int
|
||||
>::type
|
||||
compare(size_type pos1, size_type n1, ConstIterator s, size_type n2) const {
|
||||
return !(size() < pos1)
|
||||
? sprout::string_detail::compare_impl<basic_string_view>(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<typename T, typename Traits>
|
||||
SPROUT_CONSTEXPR_OR_CONST typename sprout::basic_string_view<T, Traits>::size_type sprout::basic_string_view<T, Traits>::npos;
|
||||
|
||||
//
|
||||
// swap
|
||||
//
|
||||
template<typename T, typename Traits>
|
||||
inline SPROUT_CXX14_CONSTEXPR void
|
||||
swap(sprout::basic_string_view<T, Traits>& lhs, sprout::basic_string_view<T, Traits>& rhs)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(lhs.swap(rhs))
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
|
||||
//
|
||||
// to_string_view
|
||||
//
|
||||
template<typename T, typename Traits>
|
||||
inline SPROUT_CONSTEXPR sprout::basic_string_view<T, Traits>
|
||||
to_string_view(sprout::basic_string_view<T, Traits> const& s) {
|
||||
return s;
|
||||
}
|
||||
template<typename T, std::size_t N, typename Traits>
|
||||
inline SPROUT_CONSTEXPR sprout::basic_string_view<T, Traits>
|
||||
to_string_view(sprout::basic_string<T, N, Traits> const& s) {
|
||||
return sprout::basic_string_view<T, Traits>(s);
|
||||
}
|
||||
template<typename T, typename Traits>
|
||||
inline SPROUT_NON_CONSTEXPR sprout::basic_string_view<T, Traits>
|
||||
to_string_view(std::basic_string<T, Traits> const& s) {
|
||||
return sprout::basic_string_view<T, Traits>(s);
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR sprout::basic_string_view<T>
|
||||
to_string_view(T const* str) {
|
||||
return sprout::basic_string_view<T>(str);
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR sprout::basic_string_view<T>
|
||||
to_string_view(T const* str, std::size_t len) {
|
||||
return sprout::basic_string_view<T>(str, len);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_UTILITY_STRING_VIEW_STRING_VIEW_HPP
|
105
sprout/utility/string_view/type_traits.hpp
Normal file
105
sprout/utility/string_view/type_traits.hpp
Normal file
|
@ -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 <sprout/config.hpp>
|
||||
#include <sprout/utility/string_view/string_view.hpp>
|
||||
#include <sprout/type_traits/integral_constant.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// is_basic_string_view
|
||||
//
|
||||
template<typename T>
|
||||
struct is_basic_string_view
|
||||
: public sprout::false_type
|
||||
{};
|
||||
template<typename T>
|
||||
struct is_basic_string_view<T const>
|
||||
: public sprout::is_basic_string_view<T>
|
||||
{};
|
||||
template<typename T>
|
||||
struct is_basic_string_view<T const volatile>
|
||||
: public sprout::is_basic_string_view<T>
|
||||
{};
|
||||
template<typename T, typename Traits>
|
||||
struct is_basic_string_view<sprout::basic_string_view<T, Traits> >
|
||||
: public sprout::true_type
|
||||
{};
|
||||
|
||||
//
|
||||
// is_string_view_of
|
||||
//
|
||||
template<typename T, typename Elem>
|
||||
struct is_string_view_of
|
||||
: public sprout::false_type
|
||||
{};
|
||||
template<typename T, typename Elem>
|
||||
struct is_string_view_of<T const, Elem>
|
||||
: public sprout::is_string_view_of<T, Elem>
|
||||
{};
|
||||
template<typename T, typename Elem>
|
||||
struct is_string_view_of<T const volatile, Elem>
|
||||
: public sprout::is_string_view_of<T, Elem>
|
||||
{};
|
||||
template<typename T, typename Traits, typename Elem>
|
||||
struct is_string_view_of<sprout::basic_string_view<T, Traits>, Elem>
|
||||
: public sprout::true_type
|
||||
{};
|
||||
|
||||
//
|
||||
// is_string_view
|
||||
//
|
||||
template<typename T>
|
||||
struct is_string_view
|
||||
: public sprout::is_string_view_of<T, char>
|
||||
{};
|
||||
//
|
||||
// is_wstring_view
|
||||
//
|
||||
template<typename T>
|
||||
struct is_wstring_view
|
||||
: public sprout::is_string_view_of<T, wchar_t>
|
||||
{};
|
||||
#if SPROUT_USE_UNICODE_LITERALS
|
||||
//
|
||||
// is_u16string_view
|
||||
//
|
||||
template<typename T>
|
||||
struct is_u16string_view
|
||||
: public sprout::is_string_view_of<T, char16_t>
|
||||
{};
|
||||
//
|
||||
// is_u32string_view
|
||||
//
|
||||
template<typename T>
|
||||
struct is_u32string_view
|
||||
: public sprout::is_string_view_of<T, char32_t>
|
||||
{};
|
||||
#endif
|
||||
|
||||
#if SPROUT_USE_VARIABLE_TEMPLATES
|
||||
template<typename T>
|
||||
SPROUT_STATIC_CONSTEXPR bool is_basic_string_view_v = sprout::is_basic_string_view<T>::value;
|
||||
template<typename T, typename Elem>
|
||||
SPROUT_STATIC_CONSTEXPR bool is_string_view_of_v = sprout::is_string_view_of<T, Elem>::value;
|
||||
template<typename T>
|
||||
SPROUT_STATIC_CONSTEXPR bool is_string_view_v = sprout::is_string_view<T>::value;
|
||||
template<typename T>
|
||||
SPROUT_STATIC_CONSTEXPR bool is_wstring_view_v = sprout::is_wstring_view<T>::value;
|
||||
#if SPROUT_USE_UNICODE_LITERALS
|
||||
template<typename T>
|
||||
SPROUT_STATIC_CONSTEXPR bool is_u16string_view_v = sprout::is_u16string_view<T>::value;
|
||||
template<typename T>
|
||||
SPROUT_STATIC_CONSTEXPR bool is_u32string_view_v = sprout::is_u32string_view<T>::value;
|
||||
#endif
|
||||
#endif // #if SPROUT_USE_VARIABLE_TEMPLATES
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_UTILITY_STRING_VIEW_TYPE_TRAITS_HPP
|
48
sprout/utility/string_view/udl.hpp
Normal file
48
sprout/utility/string_view/udl.hpp
Normal file
|
@ -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 <sprout/config.hpp>
|
||||
#include <sprout/utility/string_view/string_view.hpp>
|
||||
|
||||
#if SPROUT_USE_USER_DEFINED_LITERALS
|
||||
|
||||
#include <sprout/workaround/std/cstddef.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace udl {
|
||||
//
|
||||
// _sv
|
||||
//
|
||||
inline SPROUT_CONSTEXPR sprout::basic_string_view<char>
|
||||
operator"" _sv(char const* s, std::size_t size) {
|
||||
return sprout::basic_string_view<char>(s, size);
|
||||
}
|
||||
inline SPROUT_CONSTEXPR sprout::basic_string_view<wchar_t>
|
||||
operator"" _sv(wchar_t const* s, std::size_t size) {
|
||||
return sprout::basic_string_view<wchar_t>(s, size);
|
||||
}
|
||||
#if SPROUT_USE_UNICODE_LITERALS
|
||||
inline SPROUT_CONSTEXPR sprout::basic_string_view<char16_t>
|
||||
operator"" _sv(char16_t const* s, std::size_t size) {
|
||||
return sprout::basic_string_view<char16_t>(s, size);
|
||||
}
|
||||
inline SPROUT_CONSTEXPR sprout::basic_string_view<char32_t>
|
||||
operator"" _sv(char32_t const* s, std::size_t size) {
|
||||
return sprout::basic_string_view<char32_t>(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
|
Loading…
Add table
Add a link
Reference in a new issue