util.hpp
//
// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
// Copyright (c) 2022-2023 Alexander Grund
//
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#ifndef BOOST_LOCALE_UTIL_HPP
#define BOOST_LOCALE_UTIL_HPP
#include <boost/locale/generator.hpp>
#include <boost/locale/utf.hpp>
#include <boost/assert.hpp>
#include <cstdint>
#include <locale>
#include <memory>
#include <typeinfo>
namespace boost { namespace locale {
namespace util {
BOOST_LOCALE_DECL
std::string get_system_locale(bool use_utf8_on_windows = false);
BOOST_LOCALE_DECL
std::locale create_info(const std::locale& in, const std::string& name);
class BOOST_LOCALE_DECL base_converter {
public:
static constexpr utf::code_point illegal = utf::illegal;
static constexpr utf::code_point incomplete = utf::incomplete;
virtual ~base_converter();
virtual int max_len() const { return 1; }
virtual bool is_thread_safe() const { return false; }
virtual base_converter* clone() const
{
BOOST_ASSERT(typeid(*this) == typeid(base_converter));
return new base_converter();
}
virtual utf::code_point to_unicode(const char*& begin, const char* end)
{
if(begin == end)
return incomplete; // LCOV_EXCL_LINE
unsigned char cp = *begin;
if(cp <= 0x7F) {
begin++;
return cp;
}
return illegal;
}
virtual utf::len_or_error from_unicode(utf::code_point u, char* begin, const char* end)
{
if(begin == end)
return incomplete; // LCOV_EXCL_LINE
if(u >= 0x80)
return illegal;
*begin = static_cast<char>(u);
return 1;
}
};
BOOST_LOCALE_DECL std::unique_ptr<base_converter> create_utf8_converter();
BOOST_DEPRECATED("This function is deprecated, use 'create_utf8_converter()'")
inline std::unique_ptr<base_converter> create_utf8_converter_unique_ptr()
{
return create_utf8_converter();
}
BOOST_LOCALE_DECL std::unique_ptr<base_converter> create_simple_converter(const std::string& encoding);
BOOST_DEPRECATED("This function is deprecated, use 'create_simple_converter()'")
inline std::unique_ptr<base_converter> create_simple_converter_unique_ptr(const std::string& encoding)
{
return create_simple_converter(encoding);
}
BOOST_LOCALE_DECL
std::locale create_codecvt(const std::locale& in, std::unique_ptr<base_converter> cvt, char_facet_t type);
BOOST_DEPRECATED("This function is deprecated, use 'create_codecvt()'")
inline std::locale create_codecvt_from_pointer(const std::locale& in, base_converter* cvt, char_facet_t type)
{
return create_codecvt(in, std::unique_ptr<base_converter>(cvt), type);
}
BOOST_DEPRECATED("This function is deprecated, use 'create_utf8_converter()'")
BOOST_LOCALE_DECL base_converter* create_utf8_converter_new_ptr();
BOOST_DEPRECATED("This function is deprecated, use 'create_simple_converter()'")
BOOST_LOCALE_DECL base_converter* create_simple_converter_new_ptr(const std::string& encoding);
BOOST_LOCALE_DECL
std::locale create_utf8_codecvt(const std::locale& in, char_facet_t type);
BOOST_LOCALE_DECL
std::locale create_simple_codecvt(const std::locale& in, const std::string& encoding, char_facet_t type);
} // namespace util
}} // namespace boost::locale
#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.