CppUnit wstring support

Stephan Bergmann sbergman at redhat.com
Mon Jul 7 00:09:00 PDT 2014


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


More information about the LibreOffice mailing list