std::string and unicode

Milan Babuskov milanb at panonnet.net
Wed Apr 9 03:12:28 PDT 2008


Declan McMullen wrote:
> Any tips on how I should do it ?

We are using the following in FlameRobin:

//-----------------------------------------------------------------------------
std::string wx2std(const wxString& input, wxMBConv* conv = 0)
{
     if (input.empty())
         return "";
     if (!conv)
         conv = wxConvCurrent;
     const wxWX2MBbuf buf(input.mb_str(*conv));
     // conversion may fail and return 0,
     // which isn't a safe value to pass
     // to std:string constructor
     if (!buf)
         return "";
     return std::string(buf);
}
//-----------------------------------------------------------------------------
wxString std2wx(const std::string& input, wxMBConv* conv = 0)
{
    if (input.empty())
        return wxEmptyString;
    if (!conv)
        conv = wxConvCurrent;
    return wxString(input.c_str(), *conv);
}
//-----------------------------------------------------------------------------

Any comments are appreciated.

-- 
Milan Babuskov
http://www.flamerobin.org


More information about the wx-users mailing list