string.hpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //
  2. // Copyright (c) 2022-2023 Alexander Grund
  3. //
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // https://www.boost.org/LICENSE_1_0.txt
  6. #ifndef BOOST_LOCALE_UTIL_STRING_HPP
  7. #define BOOST_LOCALE_UTIL_STRING_HPP
  8. #include <boost/locale/config.hpp>
  9. #include <limits>
  10. namespace boost { namespace locale { namespace util {
  11. /// Return the end of a C-string, i.e. the pointer to the trailing NULL byte
  12. template<typename Char>
  13. Char* str_end(Char* str)
  14. {
  15. while(*str)
  16. ++str;
  17. return str;
  18. }
  19. inline constexpr bool is_upper_ascii(const char c)
  20. {
  21. return 'A' <= c && c <= 'Z';
  22. }
  23. inline constexpr bool is_lower_ascii(const char c)
  24. {
  25. return 'a' <= c && c <= 'z';
  26. }
  27. inline constexpr bool is_numeric_ascii(const char c)
  28. {
  29. return '0' <= c && c <= '9';
  30. }
  31. /// Cast an unsigned char to a (possibly signed) char avoiding implementation defined behavior
  32. constexpr char to_char(unsigned char c)
  33. {
  34. return static_cast<char>((c - (std::numeric_limits<char>::min)()) + (std::numeric_limits<char>::min)());
  35. }
  36. }}} // namespace boost::locale::util
  37. #endif