const char* ctype<Pt::Char>::do_widen(const char* begin, const char* end, Pt::Char* dest) const { for(const char* cur = begin; cur < end; ++cur) { *dest = do_widen(*cur); ++dest; } return end; }
/** * @brief Initialize an internal data structure of ctype<char> * * This was previously an inline function and moved out of line with this * commit: * http://gcc.gnu.org/viewcvs?view=revision&revision=140238 * * See also this bug report: * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37455 * * std::ctype<char>::_M_widen_init() is a function added to libstdc++ by * Jerry Quinn with revision 74662 on Dec 16, 2003: * http://gcc.gnu.org/viewcvs?diff_format=h&view=revision&revision=74662 * * With explicit permission by Jerry Quinn from Oct 9, 2012, we include a * verbatim copy of _M_widen_init() here. However, a static_cast was added to * avoid a warning. * * Revision 74662 of the libstdc++-v3 file include/bits/locale_facets.h, where * std::ctype<char>::_M_widen_init() has been copied from, also included the * following notice in the file header: * http://gcc.gnu.org/viewcvs/trunk/libstdc%2B%2B-v3/include/bits/locale_facets.h?diff_format=h&view=markup&pathrev=74662 * * <blockquote> * As a special exception, you may use this file as part of a free software * library without restriction. [...] * <blockquote> */ void ctype<char>::_M_widen_init() const { char __tmp[sizeof(_M_widen)]; for (unsigned __i = 0; __i < sizeof(_M_widen); ++__i) __tmp[__i] = static_cast<char>(__i); do_widen(__tmp, __tmp + sizeof(__tmp), _M_widen); _M_widen_ok = 1; // Set _M_widen_ok to 2 if memcpy can't be used. for (unsigned __i = 0; __i < sizeof(_M_widen); ++__i) if (__tmp[__i] != _M_widen[__i]) { _M_widen_ok = 2; break; } }
YBUTIL_DECL const String std2str(const std::string &s, const std::string &enc_name) { #if defined(YB_USE_WX) if (enc_name.empty()) return wxString(s.c_str(), wxConvUTF8); wxCSConv conv(wxString(enc_name.c_str(), wxConvUTF8).GetData()); return wxString(s.c_str(), conv); #elif defined(YB_USE_QT) if (enc_name.empty()) return QString::fromLocal8Bit(s.c_str()); QTextCodec *codec = QTextCodec::codecForName(enc_name.c_str()); return codec->toUnicode(s.c_str()); #elif defined(YB_USE_UNICODE) std::locale loc(get_locale(enc_name).c_str()); return do_widen(s, loc); #else return s; #endif }
YBUTIL_DECL const std::wstring str_widen( const std::string &narrow, const std::string &enc_name) { std::locale loc(get_locale(enc_name).c_str()); return do_widen(narrow, loc); }