123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- #ifndef BOOST_LOCALE_CONVERTER_HPP_INCLUDED
- #define BOOST_LOCALE_CONVERTER_HPP_INCLUDED
- #include <boost/locale/detail/facet_id.hpp>
- #include <boost/locale/detail/is_supported_char.hpp>
- #include <boost/locale/util/string.hpp>
- #include <locale>
- #ifdef BOOST_MSVC
- # pragma warning(push)
- # pragma warning(disable : 4275 4251 4231 4660)
- #endif
- namespace boost { namespace locale {
-
-
-
-
-
- class converter_base {
- public:
-
- enum conversion_type {
- normalization,
- upper_case,
- lower_case,
- case_folding,
- title_case
- };
- };
-
-
-
-
- template<typename Char>
- class BOOST_SYMBOL_VISIBLE converter : public converter_base,
- public std::locale::facet,
- public detail::facet_id<converter<Char>> {
- BOOST_LOCALE_ASSERT_IS_SUPPORTED(Char);
- public:
-
- converter(size_t refs = 0) : std::locale::facet(refs) {}
-
-
- virtual std::basic_string<Char>
- convert(conversion_type how, const Char* begin, const Char* end, int flags = 0) const = 0;
- };
-
- enum norm_type {
- norm_nfd,
- norm_nfc,
- norm_nfkd,
- norm_nfkc,
- norm_default = norm_nfc,
- };
-
-
-
-
-
-
-
- template<typename CharType>
- std::basic_string<CharType> normalize(const CharType* begin,
- const CharType* end,
- norm_type n = norm_default,
- const std::locale& loc = std::locale())
- {
- return std::use_facet<converter<CharType>>(loc).convert(converter_base::normalization, begin, end, n);
- }
-
-
-
-
-
-
-
- template<typename CharType>
- std::basic_string<CharType> normalize(const std::basic_string<CharType>& str,
- norm_type n = norm_default,
- const std::locale& loc = std::locale())
- {
- return normalize(str.data(), str.data() + str.size(), n, loc);
- }
-
-
-
-
-
-
-
- template<typename CharType>
- std::basic_string<CharType>
- normalize(const CharType* str, norm_type n = norm_default, const std::locale& loc = std::locale())
- {
- return normalize(str, util::str_end(str), n, loc);
- }
-
-
-
-
- template<typename CharType>
- std::basic_string<CharType>
- to_upper(const CharType* begin, const CharType* end, const std::locale& loc = std::locale())
- {
- return std::use_facet<converter<CharType>>(loc).convert(converter_base::upper_case, begin, end);
- }
-
-
-
- template<typename CharType>
- std::basic_string<CharType> to_upper(const std::basic_string<CharType>& str, const std::locale& loc = std::locale())
- {
- return to_upper(str.data(), str.data() + str.size(), loc);
- }
-
-
-
- template<typename CharType>
- std::basic_string<CharType> to_upper(const CharType* str, const std::locale& loc = std::locale())
- {
- return to_upper(str, util::str_end(str), loc);
- }
-
-
-
-
- template<typename CharType>
- std::basic_string<CharType>
- to_lower(const CharType* begin, const CharType* end, const std::locale& loc = std::locale())
- {
- return std::use_facet<converter<CharType>>(loc).convert(converter_base::lower_case, begin, end);
- }
-
-
-
- template<typename CharType>
- std::basic_string<CharType> to_lower(const std::basic_string<CharType>& str, const std::locale& loc = std::locale())
- {
- return to_lower(str.data(), str.data() + str.size(), loc);
- }
-
-
-
- template<typename CharType>
- std::basic_string<CharType> to_lower(const CharType* str, const std::locale& loc = std::locale())
- {
- return to_lower(str, util::str_end(str), loc);
- }
-
-
-
-
- template<typename CharType>
- std::basic_string<CharType>
- to_title(const CharType* begin, const CharType* end, const std::locale& loc = std::locale())
- {
- return std::use_facet<converter<CharType>>(loc).convert(converter_base::title_case, begin, end);
- }
-
-
-
- template<typename CharType>
- std::basic_string<CharType> to_title(const std::basic_string<CharType>& str, const std::locale& loc = std::locale())
- {
- return to_title(str.data(), str.data() + str.size(), loc);
- }
-
-
-
- template<typename CharType>
- std::basic_string<CharType> to_title(const CharType* str, const std::locale& loc = std::locale())
- {
- return to_title(str, util::str_end(str), loc);
- }
-
-
-
-
- template<typename CharType>
- std::basic_string<CharType>
- fold_case(const CharType* begin, const CharType* end, const std::locale& loc = std::locale())
- {
- return std::use_facet<converter<CharType>>(loc).convert(converter_base::case_folding, begin, end);
- }
-
-
-
- template<typename CharType>
- std::basic_string<CharType> fold_case(const std::basic_string<CharType>& str,
- const std::locale& loc = std::locale())
- {
- return fold_case(str.data(), str.data() + str.size(), loc);
- }
-
-
-
- template<typename CharType>
- std::basic_string<CharType> fold_case(const CharType* str, const std::locale& loc = std::locale())
- {
- return fold_case(str, util::str_end(str), loc);
- }
-
- }}
- #ifdef BOOST_MSVC
- # pragma warning(pop)
- #endif
- #endif
|