Date: prev next · Thread: first prev next last
2014 Archives by date, by thread · List index


On 07/04/2014 06:10 AM, Randall Britten wrote:
Is there a plan to include wstring support out-of-the-box for CppUnit?
If not, and in the mean time, what is the “correct” way to add support
for wstring, (e.g. such that the following will compile on a strict
compiler such as the one included with Xcode 5.1.1)?
[...]
static std::string toString(const std::wstring& ws)

         {

             std::wstring_convert<std::codecvt_utf8<wchar_t>,wchar_t> cv;

return cv.to_bytes(ws);

         }

Yes, the crucial part is providing a toString from wstring to string. While converting to UTF-8 may make sense in your use case, that need not generally hold. Also, codecvt_utf8 is only available since C++11. So a more generic solution might be to use the default codecvt<wchar_t,char,mbstate_t>. Also, the convenience class wstring_convert is only available since C++11.

Stephan

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.