2012-04-01 13:15:09 +00:00
|
|
|
|
#ifndef SPROUT_CSTRING_STRPBRK_HPP
|
|
|
|
|
#define SPROUT_CSTRING_STRPBRK_HPP
|
|
|
|
|
|
2013-01-12 16:16:48 +00:00
|
|
|
|
#include <iterator>
|
|
|
|
|
#include <type_traits>
|
2012-04-01 13:15:09 +00:00
|
|
|
|
#include <sprout/config.hpp>
|
2013-01-12 16:16:48 +00:00
|
|
|
|
#include <sprout/iterator/operation.hpp>
|
2013-02-07 14:12:57 +00:00
|
|
|
|
#include <sprout/utility/pair/pair.hpp>
|
2013-01-12 16:16:48 +00:00
|
|
|
|
#include <sprout/type_traits/is_char_type.hpp>
|
2012-04-01 13:15:09 +00:00
|
|
|
|
#include <sprout/cstring/strchr.hpp>
|
2013-01-12 16:16:48 +00:00
|
|
|
|
#include <sprout/detail/str.hpp>
|
2012-04-01 13:15:09 +00:00
|
|
|
|
|
|
|
|
|
namespace sprout {
|
2013-01-12 16:16:48 +00:00
|
|
|
|
namespace detail {
|
|
|
|
|
template<typename InputIterator1, typename ForwardIterator2>
|
|
|
|
|
inline SPROUT_CONSTEXPR sprout::pair<InputIterator1, bool>
|
|
|
|
|
strpbrk_impl_1(
|
|
|
|
|
sprout::pair<InputIterator1, bool> current,
|
|
|
|
|
ForwardIterator2 first2,
|
|
|
|
|
typename std::iterator_traits<InputIterator1>::difference_type n
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
typedef sprout::pair<InputIterator1, bool> type;
|
|
|
|
|
return current.second || !*current.first ? current
|
|
|
|
|
: n == 1 ? sprout::strchr(first2, *current.first)
|
|
|
|
|
? type(current.first, true)
|
|
|
|
|
: type(sprout::next(current.first), false)
|
|
|
|
|
: sprout::detail::strpbrk_impl_1(
|
|
|
|
|
sprout::detail::strpbrk_impl_1(
|
|
|
|
|
current,
|
|
|
|
|
first2, n / 2
|
|
|
|
|
),
|
|
|
|
|
first2, n - n / 2
|
|
|
|
|
)
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
template<typename InputIterator1, typename ForwardIterator2>
|
|
|
|
|
inline SPROUT_CONSTEXPR sprout::pair<InputIterator1, bool>
|
|
|
|
|
strpbrk_impl(
|
|
|
|
|
sprout::pair<InputIterator1, bool> current,
|
|
|
|
|
ForwardIterator2 first2,
|
|
|
|
|
typename std::iterator_traits<InputIterator1>::difference_type n
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
return current.second || !*current.first ? current
|
|
|
|
|
: sprout::detail::strpbrk_impl(
|
|
|
|
|
sprout::detail::strpbrk_impl_1(
|
|
|
|
|
current,
|
|
|
|
|
first2, n
|
|
|
|
|
),
|
|
|
|
|
first2, n * 2
|
|
|
|
|
)
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
template<typename InputIterator1, typename ForwardIterator2>
|
|
|
|
|
inline SPROUT_CONSTEXPR InputIterator1
|
|
|
|
|
strpbrk(InputIterator1 first1, ForwardIterator2 first2) {
|
|
|
|
|
typedef sprout::pair<InputIterator1, bool> type;
|
|
|
|
|
return sprout::detail::strpbrk_impl(type(first1, false), first2, 1).first;
|
|
|
|
|
}
|
|
|
|
|
} // namespace detail
|
2012-04-01 13:15:09 +00:00
|
|
|
|
|
|
|
|
|
// 7.21.5.4 strpbrk <20><EFBFBD>
|
2013-01-12 16:16:48 +00:00
|
|
|
|
//
|
|
|
|
|
// recursion depth:
|
|
|
|
|
// O(log(N1+N2))
|
|
|
|
|
//
|
2012-10-05 15:58:56 +00:00
|
|
|
|
inline SPROUT_CONSTEXPR char const*
|
|
|
|
|
strpbrk(char const* s1, char const* s2) {
|
2013-01-12 16:16:48 +00:00
|
|
|
|
return sprout::detail::str_find_check(
|
|
|
|
|
sprout::detail::strpbrk(s1, s2)
|
|
|
|
|
);
|
2012-04-01 13:15:09 +00:00
|
|
|
|
}
|
2012-10-05 15:58:56 +00:00
|
|
|
|
inline SPROUT_CONSTEXPR char*
|
|
|
|
|
strpbrk(char* s1, char const* s2) {
|
2013-01-12 16:16:48 +00:00
|
|
|
|
return sprout::detail::str_find_check(
|
|
|
|
|
sprout::detail::strpbrk(s1, s2)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Elem>
|
|
|
|
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
|
|
|
|
sprout::is_char_type<Elem>::value,
|
|
|
|
|
Elem*
|
|
|
|
|
>::type
|
|
|
|
|
strpbrk(Elem* s1, typename std::remove_const<Elem>::type const* s2) {
|
|
|
|
|
return sprout::detail::str_find_check(
|
|
|
|
|
sprout::detail::strpbrk(s1, s2)
|
|
|
|
|
);
|
2012-04-01 13:15:09 +00:00
|
|
|
|
}
|
|
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_CSTRING_STRPBRK_HPP
|