1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2024-11-12 21:09:01 +00:00
Sprout/sprout/cstring/memchr.hpp

54 lines
1.5 KiB
C++
Raw Normal View History

2012-04-01 13:15:09 +00:00
#ifndef SPROUT_CSTRING_MEMCHR_HPP
#define SPROUT_CSTRING_MEMCHR_HPP
#include <cstddef>
#include <sprout/config.hpp>
2012-12-21 16:02:49 +00:00
#include <sprout/iterator/ptr_index_iterator.hpp>
#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT
2012-04-01 13:15:09 +00:00
namespace sprout {
namespace detail {
2012-12-21 16:02:49 +00:00
inline SPROUT_CONSTEXPR unsigned char const*
memchr_impl(unsigned char const* found, unsigned char const* last) {
return found == last ? nullptr
: found
;
}
inline SPROUT_CONSTEXPR unsigned char*
memchr_impl(unsigned char* found, unsigned char* last) {
return found == last ? nullptr
: found
;
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*
2012-12-21 16:02:49 +00:00
memchr(void const* s, int c, std::size_t n) {
return sprout::detail::memchr_impl(
sprout::as_iterator_base(
NS_SSCRISK_CEL_OR_SPROUT::find(
sprout::as_iterator(static_cast<unsigned char const*>(s)), sprout::as_iterator(static_cast<unsigned char const*>(s), n),
static_cast<unsigned char>(c)
)
),
static_cast<unsigned char const*>(s) + n
);
2012-04-01 13:15:09 +00:00
}
2012-10-05 15:58:56 +00:00
inline SPROUT_CONSTEXPR void*
2012-12-21 16:02:49 +00:00
memchr(void* s, int c, std::size_t n) {
return sprout::detail::memchr_impl(
sprout::as_iterator_base(
NS_SSCRISK_CEL_OR_SPROUT::find(
sprout::as_iterator(static_cast<unsigned char*>(s)), sprout::as_iterator(static_cast<unsigned char*>(s), n),
static_cast<unsigned char>(c)
)
),
static_cast<unsigned char*>(s) + n
2012-04-01 13:15:09 +00:00
);
}
} // namespace sprout
#endif // #ifndef SPROUT_CSTRING_MEMCHR_HPP