char.hpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright (c) 2009-2020 Vladimir Batov.
  2. // Use, modification and distribution are subject to the Boost Software License,
  3. // Version 1.0. See http://www.boost.org/LICENSE_1_0.txt.
  4. #ifndef BOOST_CONVERT_DETAIL_IS_CHAR_HPP
  5. #define BOOST_CONVERT_DETAIL_IS_CHAR_HPP
  6. #include <boost/convert/detail/config.hpp>
  7. #include <cctype>
  8. #include <cwctype>
  9. namespace boost { namespace cnv
  10. {
  11. using char_type = char;
  12. using uchar_type = unsigned char;
  13. using wchar_type = wchar_t;
  14. using char_cptr = char const*;
  15. namespace detail
  16. {
  17. template<typename> struct is_char : std::false_type {};
  18. template<> struct is_char< char_type> : std:: true_type {};
  19. template<> struct is_char<wchar_type> : std:: true_type {};
  20. }
  21. template <typename T> struct is_char : detail::is_char<typename boost::remove_const<T>::type> {};
  22. template<typename char_type> inline bool is_space(char_type);
  23. template<typename char_type> inline char_type to_upper(char_type);
  24. template<> inline bool is_space ( char_type c) { return bool(std::isspace(static_cast<uchar_type>(c))); }
  25. template<> inline bool is_space (uchar_type c) { return bool(std::isspace(c)); }
  26. template<> inline bool is_space (wchar_type c) { return bool(std::iswspace(c)); }
  27. template<> inline char_type to_upper ( char_type c) { return std::toupper(static_cast<uchar_type>(c)); }
  28. template<> inline uchar_type to_upper (uchar_type c) { return std::toupper(c); }
  29. template<> inline wchar_type to_upper (wchar_type c) { return std::towupper(c); }
  30. }}
  31. #endif // BOOST_CONVERT_DETAIL_IS_CHAR_HPP