From: machard@gmail.com on
Hi,

I wonder if there exists a paper/documentation providing hints for
std::string to wxString and wxString to std::string conversion. In my
local environment, to avoid problems with conversion I compiled
wxWidget in ansi (without unicode) support. When I compile wxWidget
with unicode support I have a lot of difficulties.

3 functions were created to manage this issue :

wxString rstd2wx(std::string s, char* file, int line) {
wxString wx ((wxChar *)s.c_str(), strlen(s.c_str()));
return wx;
}

std::string wx2std(wxString s, char* file, int line) {
std::string s2 ((const char *)(s.c_str()), strlen((const char *)
s.c_str()));
return s2;
}

std::string fnwx2std(wxString s, char* file, int line) {
std::string s3 ((const char *)s.fn_str(), strlen((const char *)
s.fn_str()));
return s3;
}

If somebody knows a method explaining how one can manage _properly_
this kind of conversion within an unicode environment, that would be
great.

Thanks in advance for your answer,
Pierre

From: John Ralls on

On Feb 9, 2006, at 8:48 AM, machard(a)gmail.com wrote:

>
> Hi,
>
> I wonder if there exists a paper/documentation providing hints for
> std::string to wxString and wxString to std::string conversion. In my
> local environment, to avoid problems with conversion I compiled
> wxWidget in ansi (without unicode) support. When I compile wxWidget
> with unicode support I have a lot of difficulties.
>
> 3 functions were created to manage this issue :
>
> wxString rstd2wx(std::string s, char* file, int line) {
> wxString wx ((wxChar *)s.c_str(), strlen(s.c_str()));
> return wx;
> }
>
> std::string wx2std(wxString s, char* file, int line) {
> std::string s2 ((const char *)(s.c_str()), strlen((const char *)
> s.c_str()));
> return s2;
> }
>
> std::string fnwx2std(wxString s, char* file, int line) {
> std::string s3 ((const char *)s.fn_str(), strlen((const char *)
> s.fn_str()));
> return s3;
> }
>
> If somebody knows a method explaining how one can manage _properly_
> this kind of conversion within an unicode environment, that would be
> great.
>
> Thanks in advance for your answer,
> Pierre

You needn't write your own functions. wxWidgets has transcoding
functions.
Read the following topic overviews in the documentation:

Unicode support in wxWidgets
wxMBConv classes overview
Internationalization
Writing non-English applications

There is also a chapter on internationalization in the wxWidgets book.

Regards,
John Ralls


---------------------------------------------------------------------
To unsubscribe, e-mail: wx-users-unsubscribe(a)lists.wxwidgets.org
For additional commands, e-mail: wx-users-help(a)lists.wxwidgets.org

From: Vadim Zeitlin on
On 9 Feb 2006 08:48:33 -0800 "machard(a)gmail.com" <machard(a)gmail.com> wrote:

m> I wonder if there exists a paper/documentation providing hints for
m> std::string to wxString and wxString to std::string conversion.

wxString can always be constructed from std::string.c_str(), although you
need to specify the encoding in Unicode build (but OTOH in Unicode you can
use std::wstring.c_str() directly). And std::string can always be
constructed from wxString.mb_str() (which is the same as c_str() in ANSI
build; in Unicode, again, you can construct std::wstring from c_str() but
you need mb_str() for narrow std::string).

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/


---------------------------------------------------------------------
To unsubscribe, e-mail: wx-users-unsubscribe(a)lists.wxwidgets.org
For additional commands, e-mail: wx-users-help(a)lists.wxwidgets.org

From: machard@gmail.com on
Hi once again...

machard(a)gmail.com a écrit :

> Hi,
>
> I wonder if there exists a paper/documentation providing hints for
> std::string to wxString and wxString to std::string conversion. In my
> local environment, to avoid problems with conversion I compiled
> wxWidget in ansi (without unicode) support. When I compile wxWidget
> with unicode support I have a lot of difficulties.

I read carefully all your pointers however I still do not understand
what's happening here. Let's have a look : (I am buildiing it in an
Unicode environment)

/* TargetPlatformsCheckListBox.cpp */

const TargetPlatformsCheckListBox::platforms_t
TargetPlatformsCheckListBox::platforms[2] =
{
{"Windows", WINDOWS_NT},
{"GNU/Linux", GNU_LINUX},
};

const wxString TargetPlatformsCheckListBox::PlatformsStrings[] =
{
std2wx(platforms[0].symbolicName),
std2wx(platforms[1].symbolicName),
};


/* inside Common.hh */
#define std2wx(x) rstd2wx(x, __FILE__, __LINE__)
[...]

/* inside Common.cpp */
wxString rstd2wx(std::string s, char* file, int line) {
const char* ascii_str = s.c_str();
wxString wx(s.c_str(), *wxConvCurrent, strlen(s.c_str())*4);

/*Debug output */
std::cerr << "std2wx: <= " << s << " (" << strlen(s.c_str()) << ")" <<
std::endl;
std::string tmp ((char*)wx.c_str(), wx.length());
std::cerr << "std2wx: => " << tmp << " (" << wx.length() << ")" <<
std::endl; std::cerr << "In " << file << ":" << line << std::endl;

return wx;
}


The most surpising thing is that the output is :
$>./my-file
std2wx: <= Windows (7)
std2wx: => Windows (28)
In TargetPlatformsCheckListBox.cpp:12
std2wx: <= GNU/Linux (9)
std2wx: => (0)
In TargetPlatformsCheckListBox.cpp:13
[...]

Why do I need to multiply my strlen by 4 to be able to print "Windows"?

Why the second string (GNU/Linux) do not print?

What happens here? What I am suppose to do to fix it?

(I know that my example is simple, but I need to have a lot of
string<=>wxstring conversion in my software)

Thanks in advance for your answers.
P.S: I am using wxWidgets version 2.6.1 which is currently included in
Debian/testing

Pierre

 | 
Pages: 1
Prev: wxwidget 2.6.2 and mysql 4.1.11
Next: wxThread