From: <man...@us...> - 2013-11-14 20:27:32
|
Revision: 3220 http://sourceforge.net/p/modplug/code/3220 Author: manxorist Date: 2013-11-14 20:27:22 +0000 (Thu, 14 Nov 2013) Log Message: ----------- [Ref] Improve string conversion functions for wide string literals. Modified Paths: -------------- trunk/OpenMPT/common/mptString.h trunk/OpenMPT/test/test.cpp Modified: trunk/OpenMPT/common/mptString.h =================================================================== --- trunk/OpenMPT/common/mptString.h 2013-11-14 20:05:27 UTC (rev 3219) +++ trunk/OpenMPT/common/mptString.h 2013-11-14 20:27:22 UTC (rev 3220) @@ -194,6 +194,12 @@ std::string ToLocale(const CString &str); std::string To(Charset to, const CString &str); +// Provide un-ambiguous conversion from wide string literal. +static inline std::wstring ToWide(const wchar_t * str) { return ToWide(str ? std::wstring(str) : std::wstring()); } +static inline std::string ToLocale(const wchar_t * str) { return ToLocale(str ? std::wstring(str) : std::wstring()); } +static inline std::string To(Charset to, const wchar_t * str) { return To(to, str ? std::wstring(str) : std::wstring()); } +static inline CString ToCString(const wchar_t * str) { return ToCString(str ? std::wstring(str) : std::wstring()); } + #endif Modified: trunk/OpenMPT/test/test.cpp =================================================================== --- trunk/OpenMPT/test/test.cpp 2013-11-14 20:05:27 UTC (rev 3219) +++ trunk/OpenMPT/test/test.cpp 2013-11-14 20:27:22 UTC (rev 3220) @@ -697,10 +697,10 @@ } // Charset conversions (basic sanity checks) - VERIFY_EQUAL(mpt::ToLocale(std::wstring(L"a")), "a"); - VERIFY_EQUAL(mpt::To(mpt::CharsetUTF8, std::wstring(L"a")), "a"); - VERIFY_EQUAL(mpt::To(mpt::CharsetISO8859_1, std::wstring(L"a")), "a"); - VERIFY_EQUAL(mpt::To(mpt::CharsetASCII, std::wstring(L"a")), "a"); + VERIFY_EQUAL(mpt::ToLocale(L"a"), "a"); + VERIFY_EQUAL(mpt::To(mpt::CharsetUTF8, L"a"), "a"); + VERIFY_EQUAL(mpt::To(mpt::CharsetISO8859_1, L"a"), "a"); + VERIFY_EQUAL(mpt::To(mpt::CharsetASCII, L"a"), "a"); VERIFY_EQUAL(mpt::ToWide(mpt::CharsetLocale, "a"), L"a"); VERIFY_EQUAL(mpt::ToWide(mpt::CharsetUTF8, "a"), L"a"); VERIFY_EQUAL(mpt::ToWide(mpt::CharsetISO8859_1, "a"), L"a"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |