|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
wxString, Format etc.Hi folks, what's the rationale behind wxString wrt. to converting to/from char * etc.? Is there any at all? Why doesn't wxString::Format understand wxStrings? One of the things I want to do is use wxString::Format with wxStrings. Seems this hasn't been anticipated. Now I've tried the various conversion functions (c_str(), char_str(), fn_str(), mb_str(), wchar_str(), wc_str(), To8BitData()) and only c_str() seems to work, however, the documentation says that it'll no longer work with wxWidgets 3. What am I supposed to use then? Another thing is pathnames; I'm using char_str() since fn_str() (which, according to the documentation, is the proper thing to use, doesn't work.) What's the canonical way to get anything useful out of a wxString? Portably and without having to write special code for each combination of OS/char width? I'm currently using wxGTK 2.8.7 / Unicode but it should work on all platforms (I don't care for ANSI builds). _______________________________________________ wx-users mailing list wx-users@... http://lists.wxwidgets.org/mailman/listinfo/wx-users |
|
|
Re: wxString, Format etc.On Mon, 08 Sep 2008 18:14:00 +0200 Matthias Buelow <mkb@...> wrote:
MB> what's the rationale behind wxString wrt. to converting to/from char * MB> etc.? What is the question here? I.e. rationale for what exactly are you asking about? MB> Why doesn't wxString::Format understand wxStrings? Because objects can't be passed to vararg functions. This is undefined behaviour in C++. You may be interested to know that in wx3 Format() (and Printf() and many other functions which used to be vararg) are now (pseudo-)variadic templates and so do accept strings being passed directly to them. MB> One of the things I want to do is use wxString::Format with wxStrings. MB> Seems this hasn't been anticipated. I do wonder how did we live for 15 years without it... MB> Now I've tried the various MB> conversion functions (c_str(), char_str(), fn_str(), mb_str(), MB> wchar_str(), wc_str(), To8BitData()) and only c_str() seems to work, MB> however, the documentation says that it'll no longer work with wxWidgets 3. Where exactly did you read it? If the documentation says this it should be corrected because this is patently wrong. As I wrote above, c_str() won't be _necessary_ in wx3 in this case but it doesn't mean it's not going to work. MB> What's the canonical way to get anything useful out of a wxString? This depends on what you consider to be useful. If "useful" means "suitable to be passed to wxString::Format("%s")" then the answer is c_str(). MB> I'm currently using wxGTK 2.8.7 / Unicode but it should work on all MB> platforms (I don't care for ANSI builds). Then c_str() is the same as wc_str() in your case so it's impossible that wc_str() doesn't work if c_str() does. Regards, VZ -- TT-Solutions: wxWidgets consultancy and technical support http://www.tt-solutions.com/ _______________________________________________ wx-users mailing list wx-users@... http://lists.wxwidgets.org/mailman/listinfo/wx-users |
|
|
|
|
|
Re[2]: wxString, Format etc.On Tue, 09 Sep 2008 15:17:40 +0200 Matthias Buelow <mkb@...> wrote:
MB> Vadim Zeitlin wrote: MB> MB> > MB> Why doesn't wxString::Format understand wxStrings? MB> > MB> > Because objects can't be passed to vararg functions. This is undefined MB> > behaviour in C++. MB> MB> Where's the problem with expecting a reference or a pointer? Passing pointer to printf() prints out a pointer, not the object. Passing a reference is undefined behaviour and doesn't work. MB> The thing is, I want to pass a wxString (however) to a wxString utility MB> member function and not have to guess which of the *_str() functions MB> would be necessary in this case. You don't need to guess. "%s" format specifier expects "wxChar *" string, c_str() returns it. And if you don't know what does c_str() return, you really should. MB> > Where exactly did you read it? If the documentation says this it should be MB> > corrected because this is patently wrong. As I wrote above, c_str() won't MB> > be necessary in wx3 in this case but it doesn't mean it's not going to MB> > work. MB> MB> http://docs.wxwidgets.org/stable/wx_wxstring.html#wxstringcstr Please reread this carefully. It doesn't nearly say what you wrote. MB> > MB> What's the canonical way to get anything useful out of a wxString? MB> > MB> > This depends on what you consider to be useful. If "useful" means MB> > "suitable to be passed to wxString::Format("%s")" then the answer is MB> > c_str(). MB> MB> Useful would mean that all functions in WxWidgets that want some kind of MB> string should accept a wxString, and not demand various forms of (w)char MB> *, (w)char buffers, or whatever, There is no whatever. All non-vararg functions do accept wxStrings (and in wx3 vararg ones accept them too), for vararg functions you need to use c_str(). MB> plus a consistent and reliable way of converting/extracting to/from MB> char* for system functions There is no such thing as "system functions" unfortunately. Different functions happen to require different encodings, hence the existence of several wxConvXXX classes. Regards, VZ -- TT-Solutions: wxWidgets consultancy and technical support http://www.tt-solutions.com/ _______________________________________________ wx-users mailing list wx-users@... http://lists.wxwidgets.org/mailman/listinfo/wx-users |
|
|
Re: wxString, Format etc.>>>>> "Matthias" == Matthias Buelow <mkb@...> writes:
Matthias> Vadim Zeitlin wrote: MB> Why doesn't wxString::Format understand wxStrings? >> Because objects can't be passed to vararg functions. This is >> undefined behaviour in C++. Matthias> Where's the problem with expecting a reference or a Matthias> pointer? The thing is, I want to pass a wxString (however) Matthias> to a wxString utility member function and not have to guess Matthias> which of the *_str() functions would be necessary in this Matthias> case. This is a completely uninteresting detail at that Matthias> point that I don't want to be bothered with. Why make an Matthias> own string class if it can't be used ubiquitously in the Matthias> library which defines it? Because it's a design defect in C++. Nothing wxWidgets can do about it. paul _______________________________________________ wx-users mailing list wx-users@... http://lists.wxwidgets.org/mailman/listinfo/wx-users |
| Free Forum Powered by Nabble | Forum Help |