| 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 | |
| 7 | #ifndef BOOST_LOCALE_UTIL_STRING_HPP |
| 8 | #define BOOST_LOCALE_UTIL_STRING_HPP |
| 9 | |
| 10 | #include <boost/locale/config.hpp> |
| 11 | #include <limits> |
| 12 | |
| 13 | namespace boost { namespace locale { namespace util { |
| 14 | /// Return the end of a C-string, i.e. the pointer to the trailing NULL byte |
| 15 | template<typename Char> |
| 16 | Char* str_end(Char* str) |
| 17 | { |
| 18 | while(*str) |
| 19 | ++str; |
| 20 | return str; |
| 21 | } |
| 22 | |
| 23 | inline constexpr bool is_upper_ascii(const char c) |
| 24 | { |
| 25 | return 'A' <= c && c <= 'Z'; |
| 26 | } |
| 27 | |
| 28 | inline constexpr bool is_lower_ascii(const char c) |
| 29 | { |
| 30 | return 'a' <= c && c <= 'z'; |
| 31 | } |
| 32 | |
| 33 | inline constexpr bool is_numeric_ascii(const char c) |
| 34 | { |
| 35 | return '0' <= c && c <= '9'; |
| 36 | } |
| 37 | |
| 38 | /// Cast an unsigned char to a (possibly signed) char avoiding implementation defined behavior |
| 39 | constexpr char to_char(unsigned char c) |
| 40 | { |
| 41 | return static_cast<char>((c - (std::numeric_limits<char>::min)()) + (std::numeric_limits<char>::min)()); |
| 42 | } |
| 43 | |
| 44 | }}} // namespace boost::locale::util |
| 45 | |
| 46 | #endif |