call_next_char.hpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. //
  2. // Copyright (c) 2019-2024 Ruben Perez Hidalgo (rubenperez038 at gmail dot com)
  3. //
  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)
  6. //
  7. #ifndef BOOST_MYSQL_IMPL_INTERNAL_CALL_NEXT_CHAR_HPP
  8. #define BOOST_MYSQL_IMPL_INTERNAL_CALL_NEXT_CHAR_HPP
  9. #include <boost/mysql/character_set.hpp>
  10. #include <boost/assert.hpp>
  11. #include <cstddef>
  12. namespace boost {
  13. namespace mysql {
  14. namespace detail {
  15. inline std::size_t call_next_char(const character_set& charset, const char* first, const char* last) noexcept
  16. {
  17. // Range must be non-empty
  18. BOOST_ASSERT(last > first);
  19. // ASCII characters are always 1 byte (UTF-16 and friends are not supported)
  20. auto* data = reinterpret_cast<const unsigned char*>(first);
  21. if (*data < 0x80)
  22. return 1u;
  23. // May be a multi-byte character. Call the relevant function
  24. return charset.next_char({data, static_cast<std::size_t>(last - first)});
  25. }
  26. } // namespace detail
  27. } // namespace mysql
  28. } // namespace boost
  29. #endif