Boost.Locale: boost/locale/util.hpp Source File

| Boost.Locale

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Examples

- File List

boost/locale/util.hpp

    00001 //
    00002 //  Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
    00003 //
    00004 //  Distributed under the Boost Software License, Version 1.0. (See
    00005 //  accompanying file LICENSE_1_0.txt or copy at
    00006 //  http://www.boost.org/LICENSE_1_0.txt)
    00007 //
    00008 #ifndef BOOST_LOCALE_UTIL_HPP
    00009 #define BOOST_LOCALE_UTIL_HPP
    00010 #include <locale>
    00011 #include <typeinfo>
    00012 #include <boost/cstdint.hpp>
    00013 #include <boost/locale/utf.hpp>
    00014 #include <boost/locale/generator.hpp>
    00015 #include <boost/assert.hpp>
    00016
    00017 #include <vector>
    00018 namespace boost {
    00019 namespace locale {
    00024 namespace util {
    00025
    00039     BOOST_LOCALE_DECL
    00040     std::string get_system_locale(bool use_utf8_on_windows = false);
    00041
    00059     BOOST_LOCALE_DECL
    00060     std::locale create_info(std::locale const &in,std::string const &name);
    00061
    00062
    00077     class base_converter {
    00078     public:
    00079
    00085         static const uint32_t illegal=utf::illegal;
    00086
    00091         static const uint32_t incomplete=utf::incomplete;
    00092
    00093         virtual ~base_converter()
    00094         {
    00095         }
    00100         virtual int max_len() const
    00101         {
    00102             return 1;
    00103         }
    00113         virtual bool is_thread_safe() const
    00114         {
    00115             return false;
    00116         }
    00120         virtual base_converter *clone() const
    00121         {
    00122             BOOST_ASSERT(typeid(*this)==typeid(base_converter));
    00123             return new base_converter();
    00124         }
    00125
    00141         virtual uint32_t to_unicode(char const *&begin,char const *end)
    00142         {
    00143             if(begin == end)
    00144                 return incomplete;
    00145             unsigned char cp = *begin;
    00146             if(cp <= 0x7F) {
    00147                 begin++;
    00148                 return cp;
    00149             }
    00150             return illegal;
    00151         }
    00163
    00164         virtual uint32_t from_unicode(uint32_t u,char *begin,char const *end)
    00165         {
    00166             if(begin==end)
    00167                 return incomplete;
    00168             if(u >= 0x80)
    00169                 return illegal;
    00170             *begin = static_cast<char>(u);
    00171             return 1;
    00172         }
    00173     };
    00174
    00179     BOOST_LOCALE_DECL std::auto_ptr<base_converter> create_utf8_converter();
    00187     BOOST_LOCALE_DECL std::auto_ptr<base_converter> create_simple_converter(std::string const &encoding);
    00188
    00189
    00201     BOOST_LOCALE_DECL
    00202     std::locale create_codecvt(std::locale const &in,std::auto_ptr<base_converter> cvt,character_facet_type type);
    00203
    00204 } // util
    00205 } // locale
    00206 } // boost
    00207
    00208 #endif
    00209 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4