/*============================================================================= Copyright (c) 2011-2013 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_CSTRING_STRCHR_HPP #define SPROUT_CSTRING_STRCHR_HPP #include #include #include #include #include #include #include namespace sprout { namespace detail { template inline SPROUT_CONSTEXPR sprout::pair strchr_impl_1( sprout::pair const& current, T const& value, typename std::iterator_traits::difference_type n ) { typedef sprout::pair type; return current.second || !*current.first ? current : n == 1 ? *current.first == value ? type(current.first, true) : type(sprout::next(current.first), false) : sprout::detail::strchr_impl_1( sprout::detail::strchr_impl_1( current, value, n / 2 ), value, n - n / 2 ) ; } template inline SPROUT_CONSTEXPR sprout::pair strchr_impl( sprout::pair const& current, T const& value, typename std::iterator_traits::difference_type n ) { return current.second || !*current.first ? current : sprout::detail::strchr_impl( sprout::detail::strchr_impl_1( current, value, n ), value, n * 2 ) ; } template inline SPROUT_CONSTEXPR InputIterator strchr(InputIterator first, T const& value) { typedef sprout::pair type; return sprout::detail::strchr_impl(type(first, false), value, 1).first; } } // namespace detail // 7.21.5.2 strchr ֐ // // recursion depth: // O(log N) // inline SPROUT_CONSTEXPR char const* strchr(char const* s, int c) { return sprout::detail::str_find_check( sprout::detail::strchr(s, static_cast(c)), static_cast(c) ); } inline SPROUT_CONSTEXPR char* strchr(char* s, int c) { return sprout::detail::str_find_check( sprout::detail::strchr(s, static_cast(c)), static_cast(c) ); } template inline SPROUT_CONSTEXPR typename std::enable_if< sprout::is_char_type::value, Elem* >::type strchr(Elem* s, typename std::decay::type c) { return sprout::detail::str_find_check( sprout::detail::strchr(s, c), c ); } } // namespace sprout #endif // #ifndef SPROUT_CSTRING_STRCHR_HPP