![]() System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /usr/include/boost/beast/websocket/detail/ |
Upload File : |
// // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com) // // 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) // // Official repository: https://github.com/boostorg/beast // #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 { /** A UTF8 validator. This validator can be used to check if a buffer containing UTF8 text is valid. The write function may be called incrementally with segmented UTF8 sequences. The finish function determines if all processed text is valid. */ class utf8_checker { std::size_t need_ = 0; // chars we need to finish the code point std::uint8_t* p_ = cp_; // current position in temp buffer std::uint8_t cp_[4]; // a temp buffer for the code point public: /** Prepare to process text as valid utf8 */ BOOST_BEAST_DECL void reset(); /** Check that all processed text is valid utf8 */ BOOST_BEAST_DECL bool finish(); /** Check if text is valid UTF8 @return `true` if the text is valid utf8 or false otherwise. */ BOOST_BEAST_DECL bool write(std::uint8_t const* in, std::size_t size); /** Check if text is valid UTF8 @return `true` if the text is valid utf8 or false otherwise. */ 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); } // detail } // websocket } // beast } // boost #if BOOST_BEAST_HEADER_ONLY #include <boost/beast/websocket/detail/utf8_checker.ipp> #endif #endif