2012-04-01 13:15:09 +00:00
|
|
|
|
#ifndef SPROUT_CSTRING_MEMCHR_HPP
|
|
|
|
|
#define SPROUT_CSTRING_MEMCHR_HPP
|
|
|
|
|
|
|
|
|
|
#include <cstddef>
|
|
|
|
|
#include <sprout/config.hpp>
|
|
|
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
|
// Copyright (C) 2011 RiSK (sscrisk)
|
|
|
|
|
|
|
|
|
|
namespace detail {
|
2012-10-05 15:58:56 +00:00
|
|
|
|
inline SPROUT_CONSTEXPR void const*
|
|
|
|
|
memchr_impl(unsigned char const* s, unsigned char c, std::size_t n) {
|
2012-04-01 13:15:09 +00:00
|
|
|
|
return !n ? 0
|
|
|
|
|
: *s == c ? s
|
|
|
|
|
: sprout::detail::memchr_impl(s + 1, c, n - 1)
|
2012-09-21 06:43:30 +00:00
|
|
|
|
;
|
2012-04-01 13:15:09 +00:00
|
|
|
|
}
|
|
|
|
|
} // namespace detail
|
|
|
|
|
|
|
|
|
|
// 7.21.5.1 memchr <20><EFBFBD>
|
2012-10-05 15:58:56 +00:00
|
|
|
|
inline SPROUT_CONSTEXPR void const*
|
|
|
|
|
memchr(void const* s, int c, size_t n) {
|
2012-04-01 13:15:09 +00:00
|
|
|
|
return sprout::detail::memchr_impl(static_cast<unsigned char const*>(s), static_cast<unsigned char>(c), n);
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-05 15:58:56 +00:00
|
|
|
|
inline SPROUT_CONSTEXPR void*
|
|
|
|
|
memchr(void* s, int c, size_t n) {
|
2012-04-01 13:15:09 +00:00
|
|
|
|
return const_cast<void*>(
|
|
|
|
|
sprout::detail::memchr_impl(static_cast<unsigned char*>(s), static_cast<unsigned char>(c), n)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_CSTRING_MEMCHR_HPP
|