char.hpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. namespace detail
  15. {
  16. template<typename> struct is_char : std::false_type {};
  17. template<> struct is_char< char_type> : std:: true_type {};
  18. template<> struct is_char<wchar_type> : std:: true_type {};
  19. }
  20. template <typename T> struct is_char : detail::is_char<typename boost::remove_const<T>::type> {};
  21. template<typename char_type> inline bool is_space(char_type);
  22. template<typename char_type> inline char_type to_upper(char_type);
  23. template<> inline bool is_space ( char_type c) { return bool(std::isspace(static_cast<uchar_type>(c))); }
  24. template<> inline bool is_space (uchar_type c) { return bool(std::isspace(c)); }
  25. template<> inline bool is_space (wchar_type c) { return bool(std::iswspace(c)); }
  26. template<> inline char_type to_upper ( char_type c) { return std::toupper(static_cast<uchar_type>(c)); }
  27. template<> inline uchar_type to_upper (uchar_type c) { return std::toupper(c); }
  28. template<> inline wchar_type to_upper (wchar_type c) { return std::towupper(c); }
  29. }}
  30. #endif // BOOST_CONVERT_DETAIL_IS_CHAR_HPP