123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- #ifndef BOOST_BEAST_WEBSOCKET_DETAIL_UTF8_CHECKER_HPP
- #define BOOST_BEAST_WEBSOCKET_DETAIL_UTF8_CHECKER_HPP
- #include <boost/beast/core/buffers_range.hpp>
- #include <boost/asio/buffer.hpp>
- #include <cstdint>
- namespace boost {
- namespace beast {
- namespace websocket {
- namespace detail {
- class utf8_checker
- {
- std::size_t need_ = 0;
- std::uint8_t* p_ = cp_;
- std::uint8_t cp_[4];
- public:
-
- BOOST_BEAST_DECL
- void
- reset();
-
- BOOST_BEAST_DECL
- bool
- finish();
-
- BOOST_BEAST_DECL
- bool
- write(std::uint8_t const* in, std::size_t size);
-
- template<class ConstBufferSequence>
- bool
- write(ConstBufferSequence const& bs);
- };
- template<class ConstBufferSequence>
- bool
- utf8_checker::
- write(ConstBufferSequence const& buffers)
- {
- static_assert(
- net::is_const_buffer_sequence<ConstBufferSequence>::value,
- "ConstBufferSequence type requirements not met");
- for(auto b : beast::buffers_range_ref(buffers))
- if(! write(static_cast<
- std::uint8_t const*>(b.data()),
- b.size()))
- return false;
- return true;
- }
- BOOST_BEAST_DECL
- bool
- check_utf8(char const* p, std::size_t n);
- }
- }
- }
- }
- #if BOOST_BEAST_HEADER_ONLY
- #include <boost/beast/websocket/detail/utf8_checker.ipp>
- #endif
- #endif
|