2 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // Official repository: https://github.com/boostorg/beast
10 #ifndef BOOST_BEAST_WEBSOCKET_DETAIL_UTF8_CHECKER_HPP
11 #define BOOST_BEAST_WEBSOCKET_DETAIL_UTF8_CHECKER_HPP
13 #include <boost/beast/core/buffers_range.hpp>
14 #include <boost/asio/buffer.hpp>
25 This validator can be used to check if a buffer containing UTF8 text is
26 valid. The write function may be called incrementally with segmented UTF8
27 sequences. The finish function determines if all processed text is valid.
31 std::size_t need_ = 0; // chars we need to finish the code point
32 std::uint8_t* p_ = cp_; // current position in temp buffer
33 std::uint8_t cp_[4]; // a temp buffer for the code point
36 /** Prepare to process text as valid utf8
42 /** Check that all processed text is valid utf8
48 /** Check if text is valid UTF8
50 @return `true` if the text is valid utf8 or false otherwise.
54 write(std::uint8_t const* in, std::size_t size);
56 /** Check if text is valid UTF8
58 @return `true` if the text is valid utf8 or false otherwise.
60 template<class ConstBufferSequence>
62 write(ConstBufferSequence const& bs);
66 template<class ConstBufferSequence>
69 write(ConstBufferSequence const& buffers)
72 net::is_const_buffer_sequence<ConstBufferSequence>::value,
73 "ConstBufferSequence type requirements not met");
74 for(auto b : beast::buffers_range_ref(buffers))
75 if(! write(static_cast<
76 std::uint8_t const*>(b.data()),
85 check_utf8(char const* p, std::size_t n);
92 #if BOOST_BEAST_HEADER_ONLY
93 #include <boost/beast/websocket/detail/utf8_checker.ipp>