| Boost.Locale

util.hpp
1//
2// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
3// Copyright (c) 2022-2023 Alexander Grund
4//
5// Distributed under the Boost Software License, Version 1.0.
6// https://www.boost.org/LICENSE_1_0.txt
7
8#ifndef BOOST_LOCALE_UTIL_HPP
9#define BOOST_LOCALE_UTIL_HPP
10
11#include <boost/locale/generator.hpp>
12#include <boost/locale/utf.hpp>
13#include <boost/assert.hpp>
14#include <cstdint>
15#include <locale>
16#include <memory>
17#include <typeinfo>
18
19 namespace boost { namespace locale {
22 namespace util {
23
34 BOOST_LOCALE_DECL
35 std::string get_system_locale(bool use_utf8_on_windows = false);
36
52 BOOST_LOCALE_DECL
53 std::locale create_info(const std::locale& in, const std::string& name);
54
67 class BOOST_LOCALE_DECL base_converter {
68 public:
72 static constexpr utf::code_point illegal = utf::illegal;
73
76 static constexpr utf::code_point incomplete = utf::incomplete;
77
78 virtual ~base_converter();
79
82 virtual int max_len() const { return 1; }
83
91 virtual bool is_thread_safe() const { return false; }
92
94 virtual base_converter* clone() const
95 {
96 BOOST_ASSERT(typeid(*this) == typeid(base_converter));
97 return new base_converter();
98 }
99
114 virtual utf::code_point to_unicode(const char*& begin, const char* end)
115 {
116 if(begin == end)
117 return incomplete; // LCOV_EXCL_LINE
118 unsigned char cp = *begin;
119 if(cp <= 0x7F) {
120 begin++;
121 return cp;
122 }
123 return illegal;
124 }
125
136 virtual utf::len_or_error from_unicode(utf::code_point u, char* begin, const char* end)
137 {
138 if(begin == end)
139 return incomplete; // LCOV_EXCL_LINE
140 if(u >= 0x80)
141 return illegal;
142 *begin = static_cast<char>(u);
143 return 1;
144 }
145 };
146
149 BOOST_LOCALE_DECL std::unique_ptr<base_converter> create_utf8_converter();
150
151 BOOST_DEPRECATED("This function is deprecated, use 'create_utf8_converter()'")
152 inline std::unique_ptr<base_converter> create_utf8_converter_unique_ptr()
153 {
154 return create_utf8_converter();
155 }
156
162 BOOST_LOCALE_DECL std::unique_ptr<base_converter> create_simple_converter(const std::string& encoding);
163
164 BOOST_DEPRECATED("This function is deprecated, use 'create_simple_converter()'")
165 inline std::unique_ptr<base_converter> create_simple_converter_unique_ptr(const std::string& encoding)
166 {
167 return create_simple_converter(encoding);
168 }
169
180 BOOST_LOCALE_DECL
181 std::locale create_codecvt(const std::locale& in, std::unique_ptr<base_converter> cvt, char_facet_t type);
182
183 BOOST_DEPRECATED("This function is deprecated, use 'create_codecvt()'")
184 inline std::locale create_codecvt_from_pointer(const std::locale& in, base_converter* cvt, char_facet_t type)
185 {
186 return create_codecvt(in, std::unique_ptr<base_converter>(cvt), type);
187 }
188
189 BOOST_DEPRECATED("This function is deprecated, use 'create_utf8_converter()'")
190 BOOST_LOCALE_DECL base_converter* create_utf8_converter_new_ptr();
191
192 BOOST_DEPRECATED("This function is deprecated, use 'create_simple_converter()'")
193 BOOST_LOCALE_DECL base_converter* create_simple_converter_new_ptr(const std::string& encoding);
194
197 BOOST_LOCALE_DECL
198 std::locale create_utf8_codecvt(const std::locale& in, char_facet_t type);
199
205 BOOST_LOCALE_DECL
206 std::locale create_simple_codecvt(const std::locale& in, const std::string& encoding, char_facet_t type);
207 } // namespace util
208}} // namespace boost::locale
209
210#endif
boost::locale::util::base_converter
This class represent a simple stateless converter from UCS-4 and to UCS-4 for each single code point.
Definition: util.hpp:67
boost::locale::util::base_converter::from_unicode
virtual utf::len_or_error from_unicode(utf::code_point u, char *begin, const char *end)
Definition: util.hpp:136
boost::locale::util::base_converter::max_len
virtual int max_len() const
Definition: util.hpp:82
boost::locale::util::base_converter::is_thread_safe
virtual bool is_thread_safe() const
Definition: util.hpp:91
boost::locale::util::base_converter::to_unicode
virtual utf::code_point to_unicode(const char *&begin, const char *end)
Definition: util.hpp:114
boost::locale::util::base_converter::clone
virtual base_converter * clone() const
Create a polymorphic copy of this object, usually called only if is_thread_safe() return false.
Definition: util.hpp:94
boost::locale::utf::code_point
uint32_t code_point
The integral type that can hold a Unicode code point.
Definition: utf.hpp:19
boost::locale::utf::len_or_error
code_point len_or_error
Either a length/size or an error (illegal/incomplete)
Definition: utf.hpp:27
boost::locale::util::create_utf8_codecvt
std::locale create_utf8_codecvt(const std::locale &in, char_facet_t type)
boost::locale::util::create_simple_converter
std::unique_ptr< base_converter > create_simple_converter(const std::string &encoding)
boost::locale::util::create_codecvt
std::locale create_codecvt(const std::locale &in, std::unique_ptr< base_converter > cvt, char_facet_t type)
boost::locale::util::get_system_locale
std::string get_system_locale(bool use_utf8_on_windows=false)
Return default system locale name in POSIX format.
boost::locale::util::create_info
std::locale create_info(const std::locale &in, const std::string &name)
Installs information facet to locale in based on locale name name.
boost::locale::util::create_utf8_converter
std::unique_ptr< base_converter > create_utf8_converter()
boost::locale::util::create_simple_codecvt
std::locale create_simple_codecvt(const std::locale &in, const std::string &encoding, char_facet_t type)
boost::locale::char_facet_t
char_facet_t
Definition: generator.hpp:34
- © Copyright 2009-2012 Artyom Beilis, Distributed under the Boost Software License, Version 1.0.