utf8_codecvt.hpp
//
// Copyright (c) 2015 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 BOOST_LOCALE_UTF8_CODECVT_HPP
#define BOOST_LOCALE_UTF8_CODECVT_HPP
#include <boost/locale/utf.hpp>
#include <boost/locale/generic_codecvt.hpp>
#include <boost/cstdint.hpp>
#include <locale>
namespace boost {
namespace locale {
template<typename CharType>
class utf8_codecvt : public generic_codecvt<CharType,utf8_codecvt<CharType> >
{
public:
struct state_type {};
utf8_codecvt(size_t refs = 0) : generic_codecvt<CharType,utf8_codecvt<CharType> >(refs)
{
}
static int max_encoding_length()
{
return 4;
}
static state_type initial_state(generic_codecvt_base::initial_convertion_state /* unused */)
{
return state_type();
}
static utf::code_point to_unicode(state_type &,char const *&begin,char const *end)
{
char const *p=begin;
utf::code_point c = utf::utf_traits<char>::decode(p,end);
if(c!=utf::illegal && c!=utf::incomplete)
begin = p;
return c;
}
static utf::code_point from_unicode(state_type &,utf::code_point u,char *begin,char const *end)
{
if(!utf::is_valid_codepoint(u))
return utf::illegal;
int width;
if((width=utf::utf_traits<char>::width(u)) > end - begin)
return utf::incomplete;
utf::utf_traits<char>::encode(u,begin);
return width;
}
};
} // locale
} // namespace boost
#endif
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
boost::locale::utf::utf_traits::decode
static code_point decode(Iterator &p, Iterator e)
boost::locale::utf::is_valid_codepoint
bool is_valid_codepoint(code_point v)
the function checks if v is a valid code point
Definition: utf.hpp:49
boost::locale::utf::utf_traits::encode
static Iterator encode(code_point value, Iterator out)
boost::locale::utf::incomplete
static const code_point incomplete
Special constant that defines incomplete code point.
Definition: utf.hpp:44
boost::locale::utf8_codecvt
Geneneric utf8 codecvt facet, it allows to convert UTF-8 strings to UTF-16 and UTF-32 using wchar_t...
Definition: utf8_codecvt.hpp:23
boost::locale::utf::code_point
uint32_t code_point
The integral type that can hold a Unicode code point.
Definition: utf.hpp:34
boost::locale::generic_codecvt_base::initial_convertion_state
initial_convertion_state
Definition: generic_codecvt.hpp:39
boost::locale::utf::illegal
static const code_point illegal
Special constant that defines illegal code point.
Definition: utf.hpp:39
boost::locale::utf8_codecvt::state_type
Definition: utf8_codecvt.hpp:27
boost::locale::generic_codecvt
Geneneric generic codecvt facet, various stateless encodings to UTF-16 and UTF-32 using wchar_t...
Definition: generic_codecvt.hpp:140
- © Copyright 2009-2012 Artyom Beilis, Distributed under the Boost Software License, Version 1.0.