File indexing completed on 2025-01-18 09:39:15
0001
0002
0003
0004
0005
0006
0007 #ifndef BOOST_LOCALE_CONVERTER_HPP_INCLUDED
0008 #define BOOST_LOCALE_CONVERTER_HPP_INCLUDED
0009
0010 #include <boost/locale/detail/facet_id.hpp>
0011 #include <boost/locale/detail/is_supported_char.hpp>
0012 #include <boost/locale/util/string.hpp>
0013 #include <locale>
0014
0015 #ifdef BOOST_MSVC
0016 # pragma warning(push)
0017 # pragma warning(disable : 4275 4251 4231 4660)
0018 #endif
0019
0020 namespace boost { namespace locale {
0021
0022
0023
0024
0025
0026
0027
0028 class converter_base {
0029 public:
0030
0031 enum conversion_type {
0032 normalization,
0033 upper_case,
0034 lower_case,
0035 case_folding,
0036 title_case
0037 };
0038 };
0039
0040
0041
0042
0043
0044 template<typename Char>
0045 class BOOST_SYMBOL_VISIBLE converter : public converter_base,
0046 public std::locale::facet,
0047 public detail::facet_id<converter<Char>> {
0048 BOOST_LOCALE_ASSERT_IS_SUPPORTED(Char);
0049
0050 public:
0051
0052 converter(size_t refs = 0) : std::locale::facet(refs) {}
0053
0054
0055 virtual std::basic_string<Char>
0056 convert(conversion_type how, const Char* begin, const Char* end, int flags = 0) const = 0;
0057 };
0058
0059
0060 enum norm_type {
0061 norm_nfd,
0062 norm_nfc,
0063 norm_nfkd,
0064 norm_nfkc,
0065 norm_default = norm_nfc,
0066 };
0067
0068
0069
0070
0071
0072
0073
0074
0075 template<typename CharType>
0076 std::basic_string<CharType> normalize(const CharType* begin,
0077 const CharType* end,
0078 norm_type n = norm_default,
0079 const std::locale& loc = std::locale())
0080 {
0081 return std::use_facet<converter<CharType>>(loc).convert(converter_base::normalization, begin, end, n);
0082 }
0083
0084
0085
0086
0087
0088
0089
0090
0091 template<typename CharType>
0092 std::basic_string<CharType> normalize(const std::basic_string<CharType>& str,
0093 norm_type n = norm_default,
0094 const std::locale& loc = std::locale())
0095 {
0096 return normalize(str.data(), str.data() + str.size(), n, loc);
0097 }
0098
0099
0100
0101
0102
0103
0104
0105
0106 template<typename CharType>
0107 std::basic_string<CharType>
0108 normalize(const CharType* str, norm_type n = norm_default, const std::locale& loc = std::locale())
0109 {
0110 return normalize(str, util::str_end(str), n, loc);
0111 }
0112
0113
0114
0115
0116
0117
0118 template<typename CharType>
0119 std::basic_string<CharType>
0120 to_upper(const CharType* begin, const CharType* end, const std::locale& loc = std::locale())
0121 {
0122 return std::use_facet<converter<CharType>>(loc).convert(converter_base::upper_case, begin, end);
0123 }
0124
0125
0126
0127
0128 template<typename CharType>
0129 std::basic_string<CharType> to_upper(const std::basic_string<CharType>& str, const std::locale& loc = std::locale())
0130 {
0131 return to_upper(str.data(), str.data() + str.size(), loc);
0132 }
0133
0134
0135
0136
0137 template<typename CharType>
0138 std::basic_string<CharType> to_upper(const CharType* str, const std::locale& loc = std::locale())
0139 {
0140 return to_upper(str, util::str_end(str), loc);
0141 }
0142
0143
0144
0145
0146
0147
0148 template<typename CharType>
0149 std::basic_string<CharType>
0150 to_lower(const CharType* begin, const CharType* end, const std::locale& loc = std::locale())
0151 {
0152 return std::use_facet<converter<CharType>>(loc).convert(converter_base::lower_case, begin, end);
0153 }
0154
0155
0156
0157
0158 template<typename CharType>
0159 std::basic_string<CharType> to_lower(const std::basic_string<CharType>& str, const std::locale& loc = std::locale())
0160 {
0161 return to_lower(str.data(), str.data() + str.size(), loc);
0162 }
0163
0164
0165
0166
0167 template<typename CharType>
0168 std::basic_string<CharType> to_lower(const CharType* str, const std::locale& loc = std::locale())
0169 {
0170 return to_lower(str, util::str_end(str), loc);
0171 }
0172
0173
0174
0175
0176
0177
0178 template<typename CharType>
0179 std::basic_string<CharType>
0180 to_title(const CharType* begin, const CharType* end, const std::locale& loc = std::locale())
0181 {
0182 return std::use_facet<converter<CharType>>(loc).convert(converter_base::title_case, begin, end);
0183 }
0184
0185
0186
0187
0188 template<typename CharType>
0189 std::basic_string<CharType> to_title(const std::basic_string<CharType>& str, const std::locale& loc = std::locale())
0190 {
0191 return to_title(str.data(), str.data() + str.size(), loc);
0192 }
0193
0194
0195
0196
0197 template<typename CharType>
0198 std::basic_string<CharType> to_title(const CharType* str, const std::locale& loc = std::locale())
0199 {
0200 return to_title(str, util::str_end(str), loc);
0201 }
0202
0203
0204
0205
0206
0207
0208 template<typename CharType>
0209 std::basic_string<CharType>
0210 fold_case(const CharType* begin, const CharType* end, const std::locale& loc = std::locale())
0211 {
0212 return std::use_facet<converter<CharType>>(loc).convert(converter_base::case_folding, begin, end);
0213 }
0214
0215
0216
0217
0218 template<typename CharType>
0219 std::basic_string<CharType> fold_case(const std::basic_string<CharType>& str,
0220 const std::locale& loc = std::locale())
0221 {
0222 return fold_case(str.data(), str.data() + str.size(), loc);
0223 }
0224
0225
0226
0227
0228 template<typename CharType>
0229 std::basic_string<CharType> fold_case(const CharType* str, const std::locale& loc = std::locale())
0230 {
0231 return fold_case(str, util::str_end(str), loc);
0232 }
0233
0234
0235 }}
0236
0237 #ifdef BOOST_MSVC
0238 # pragma warning(pop)
0239 #endif
0240
0241
0242
0243
0244
0245
0246
0247
0248
0249 #endif