1
  /   ˆ{‹„„-i[D<†ªoZƒ›Ù«Â524_‘I|¥‰ÓMdœv ©ƒ†ü+=ÂÁ     ‹      Õ•Q�1ÇßïSÔ>ø³ˆ‘ëÖœ,‰D‡1ÆÓÝ¶¹Ý–´ÄOo—]/‡žQãùÔéì¿3ó›Ýí�'ñ¤?? ×óëš¾}5ön ¼k÷ây\=è4ƒ`0ÆgÎ­z Ûí¶¹m7µYÂ|™+òXgdêšÜqL/Hé£ˆd‚q¿"â¤Ë*.>#½@ ×ÎJ.ü¹�.62¶´�( …6»z	ƒ(ÍEPï»-°ë¤R¨ÂúDPg"‰æ»²€ðÏ'ó1÷(,Ùç,MC‰ËÐ†år©"ìô
S"‹%²&�0ÈT+IÎÔms)±ÜEøÃ°?ùèuà²ò4%eF,"ü²�/'QŒé˜‚ »_sí5W˜Ž˜u¨Ð\.¤àgÅ7•øF~90®4±°©‘+'µ:JÁ#ž¢¦:·+æYŸy‚Ìœª*	ÿY7Xú]3¦W³ÁxgUKxâXÝo½:L§ÌåP,�H�wÖ\U’§*±«ËÃÕU¹Ì¦5Ð½Ê_@]èœs
{ó †éÁ:­ôNi­ Õm„a#|�Âç½ ‹Ðã`0r#Ìž¡¶ÃZÝ*½U§þ‹þÄ'¶ö¡ŒNÄ7š£ëX­6
Â^§}Ëß©oþÖ¤ÿg-6þ·Æ´Zÿ>Àï?¨'�ý"PMÁ¯Áàdh    C   ˆl–Ãa¾”êh¥2 ¸&®6â˜´o�þ\ ‚³r�Hã€çÅ„NÿÄ_‹I|¥�+ýÿ¹ä³ÄÃ ?÷     //
//  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_GENERIC_CODECVT_HPP
#define BOOST_LOCALE_GENERIC_CODECVT_HPP

#include <boost/locale/utf.hpp>
#include <boost/cstdint.hpp>
#include <boost/static_assert.hpp>
#include <locale>

namespace boost {
namespace locale {

#ifndef BOOST_LOCALE_DOXYGEN
//
// Make sure that mbstate can keep 16 bit of UTF-16 sequence
//
BOOST_STATIC_ASSERT(sizeof(std::mbstate_t)>=2);
#endif

#if defined(_MSC_VER) && _MSC_VER < 1700
// up to MSVC 11 (2012) do_length is non-standard it counts wide characters instead of narrow and does not change mbstate
#define BOOST_LOCALE_DO_LENGTH_MBSTATE_CONST
#endif

///
/// \brief A base class that used to define constants for generic_codecvt
///
class generic_codecvt_base {
public:
    ///
    /// Initail state for converting to or from unicode code points, used by initial_state in derived classes
    ///
    enum initial_convertion_state {
        to_unicode_state, ///< The state would be used by to_unicode functions
        from_unicode_state ///< The state would be used by from_unicode functions
    };
};

///
/// \brief Geneneric generic codecvt facet, various stateless encodings to UTF-16 and UTF-32 using wchar_t, char32_t and char16_t
///
/// Implementations should dervide from this class defining itself as CodecvtImpl and provide following members
///
/// - `state_type` - a type of special object that allows to store intermediate cached data, for example `iconv_t` descriptor 
/// - `state_type initial_state(generic_codecvt_base::initial_convertion_state direction) const` - member function that creates initial state
/// - `int max_encoding_length() const` - a maximal length that one Unicode code point is represented, for UTF-8 for example it is 4 from ISO-8859-1 it is 1
/// - `utf::code_point to_unicode(state_type &state,char const *&begin,char const *end)` - extract first code point from the text in range [begin,end), in case of success begin would point to the next character sequence to be encoded to next code point, in case of incomplete sequence - utf::incomplete shell be returned, and in case of invalid input sequence utf::illegal shell be returned and begin would remain unmodified
/// - `utf::code_point from_unicode(state_type &state,utf::code_point u,char *begin,char const *end)` - convert a unicode code point `u` into a character seqnece at [begin,end). Return the length of the sequence in case of success, utf::incomplete in case of not enough room to encode the code point of utf::illegal in case conversion can not be performed
///
///
/// For example implementaion of codecvt for latin1/ISO-8859-1 character set
///
/// \code
///
/// template<typename CharType>
/// class latin1_codecvt :boost::locale::generic_codecvt<CharType,latin1_codecvt<CharType> > 
/// {
/// public:
///    
///     /* Standard codecvt constructor */ 
///     latin1_codecvt(size_t refs = 0) : boost::locale::generic_codecvt<CharType,latin1_codecvt<CharType> >(refs) 
///     {
///     }
///
///     /* State is unused but required by generic_codecvt */
///     struct state_type {};
///
///     state_type initial_state(generic_codecvt_base::initial_convertion_state /*unused*/) const
///     {
///         return state_type();
///     }
/