util.h
//
// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOSTER_LOCALE_UTIL_HPP
#define BOOSTER_LOCALE_UTIL_HPP
#include <locale>
#include <typeinfo>
#include <booster/cstdint.h>
#include <booster/locale/utf.h>
#include <booster/locale/generator.h>
#include <booster/assert.h>
#include <vector>
namespace booster {
namespace locale {
namespace util {
BOOSTER_API
std::string get_system_locale(bool use_utf8_on_windows = false);
BOOSTER_API
std::locale create_info(std::locale const &in,std::string const &name);
class base_converter {
public:
static const uint32_t illegal=utf::illegal;
static const uint32_t 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
{
BOOSTER_ASSERT(typeid(*this)==typeid(base_converter));
return new base_converter();
}
virtual uint32_t to_unicode(char const *&begin,char const *end)
{
if(begin == end)
return incomplete;
unsigned char cp = *begin;
if(cp <= 0x7F) {
begin++;
return cp;
}
return illegal;
}
virtual uint32_t from_unicode(uint32_t u,char *begin,char const *end)
{
if(begin==end)
return incomplete;
if(u >= 0x80)
return illegal;
*begin = static_cast<char>(u);
return 1;
}
};
BOOSTER_API std::auto_ptr<base_converter> create_utf8_converter();
BOOSTER_API std::auto_ptr<base_converter> create_simple_converter(std::string const &encoding);
BOOSTER_API
std::locale create_codecvt(std::locale const &in,std::auto_ptr<base_converter> cvt,character_facet_type type);
} // util
} // locale
} // boost
#endif
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
booster::locale::util::create_info
BOOSTER_API std::locale create_info(std::locale const &in, std::string const &name)
Installs information facet to locale in based on locale name name.
booster::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.h:77
booster::locale::util::create_utf8_converter
BOOSTER_API std::auto_ptr< base_converter > create_utf8_converter()
booster::locale::character_facet_type
uint32_t character_facet_type
type that specifies the character type that locales can be generated for
Definition: generator.h:43
booster::locale::util::create_codecvt
BOOSTER_API std::locale create_codecvt(std::locale const &in, std::auto_ptr< base_converter > cvt, character_facet_type type)
booster::locale::util::get_system_locale
BOOSTER_API std::string get_system_locale(bool use_utf8_on_windows=false)
Return default system locale name in POSIX format.
booster::locale::util::base_converter::to_unicode
virtual uint32_t to_unicode(char const *&begin, char const *end)
Definition: util.h:141
booster::locale::util::base_converter::clone
virtual base_converter * clone() const
Definition: util.h:120
booster::locale::util::base_converter::incomplete
static const uint32_t incomplete
Definition: util.h:91
booster::locale::util::base_converter::from_unicode
virtual uint32_t from_unicode(uint32_t u, char *begin, char const *end)
Definition: util.h:164
booster::locale::util::base_converter::illegal
static const uint32_t illegal
Definition: util.h:85
booster::locale::util::create_simple_converter
BOOSTER_API std::auto_ptr< base_converter > create_simple_converter(std::string const &encoding)
booster::locale::util::base_converter::is_thread_safe
virtual bool is_thread_safe() const
Definition: util.h:113
booster::locale::util::base_converter::max_len
virtual int max_len() const
Definition: util.h:100