fixed construct_from_utf16

This commit is contained in:
jez_higgins 2005-10-15 22:43:36 +00:00
parent 382a92a613
commit b730a73f62

View file

@ -95,23 +95,45 @@ public:
typedef Arabica::convert::basic_oconvertstream<wchar_t, std::char_traits<wchar_t>, typedef Arabica::convert::basic_oconvertstream<wchar_t, std::char_traits<wchar_t>,
char, std::char_traits<char> > narrower; char, std::char_traits<char> > narrower;
std::string construct_from_utf16(const wchar_t* str) static std::string construct_from_utf16(const wchar_t* str)
{ {
std::wstring s; #ifndef ARABICA_VS6_WORKAROUND
if(str) std::locale loc(std::locale(), new Arabica::convert::utf8ucs2codecvt());
s = str; #else
n_.str(s); std::locale loc(std::_Addfac(std::locale(), new Arabica::convert::utf8ucs2codecvt));
return n_.str(); #endif
narrower n;
n.imbue(loc);
n << str;
return n.str();
} // makeStringT } // makeStringT
std::string construct_from_utf16(const wchar_t* str, int length)
static std::string construct_from_utf16(const wchar_t* str, int length)
{ {
n_.str(std::wstring(str, length)); #ifndef ARABICA_VS6_WORKAROUND
return n_.str(); std::locale loc(std::locale(), new Arabica::convert::utf8ucs2codecvt());
} // makeStringT #else
std::wstring asStdWString(const std::string& str) std::locale loc(std::_Addfac(std::locale(), new Arabica::convert::utf8ucs2codecvt));
#endif
narrower n;
n.imbue(loc);
for(int i = 0; i < length; ++i)
n << str[i];
return n.str();
} // construct_from_utf16
static std::wstring asStdWString(const std::string& str)
{ {
w_.str(str); #ifndef ARABICA_VS6_WORKAROUND
return w_.str(); std::locale loc(std::locale(), new Arabica::convert::utf8ucs2codecvt());
#else
std::locale loc(std::_Addfac(std::locale(), new Arabica::convert::utf8ucs2codecvt));
#endif
widener w;
w.str(str);
return w.str();
} // toStdWString } // toStdWString
#endif #endif
@ -164,28 +186,6 @@ public:
static mutable_iterator begin(std::string& str) { return str.begin(); } static mutable_iterator begin(std::string& str) { return str.begin(); }
static const_iterator end(const std::string& str) { return str.end(); } static const_iterator end(const std::string& str) { return str.end(); }
static mutable_iterator end(std::string& str) { return str.end(); } static mutable_iterator end(std::string& str) { return str.end(); }
#ifndef ARABICA_NO_WCHAR_T
default_string_adaptor() :
#ifndef ARABICA_VS6_WORKAROUND
loc_(std::locale(), new Arabica::convert::utf8ucs2codecvt()),
#else
loc_(std::_Addfac(std::locale(), new Arabica::convert::utf8ucs2codecvt)),
#endif
n_(),
w_()
{
n_.imbue(loc_);
w_.imbue(loc_);
} // default_string_adaptor
private:
std::locale loc_;
mutable narrower n_;
mutable widener w_;
#else
default_string_adaptor() { }
#endif
}; // class default_string_adaptor }; // class default_string_adaptor
#ifndef ARABICA_NO_WCHAR_T #ifndef ARABICA_NO_WCHAR_T