lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] Converting std::string to wxString (was: [lmi-commits] master


From: Vadim Zeitlin
Subject: Re: [lmi] Converting std::string to wxString (was: [lmi-commits] master 987adcc 06/10: Get sequence parser diagnostics from exception, not function)
Date: Mon, 6 Feb 2017 16:17:56 +0100

On Mon,  6 Feb 2017 04:10:56 +0000 (UTC) Greg Chicares <address@hidden> wrote:

GC> branch: master
GC> commit 987adcc3cb6aac1b5405ca7d41cc500c7a392fe9
GC> Author: Gregory W. Chicares <address@hidden>
GC> Commit: Gregory W. Chicares <address@hidden>
GC> 
GC>     Get sequence parser diagnostics from exception, not function
GC> ---
GC>  input_sequence_entry.cpp |   80 
++++++++++++++++++++++++++--------------------
GC>  1 file changed, 45 insertions(+), 35 deletions(-)
...
GC> +    catch(std::exception const& e)
GC>          {
GC> -        parser_diagnostics.erase(z);
GC> +        std::string parser_diagnostics(e.what());
GC> +        std::string::size_type z(parser_diagnostics.find('\n'));
GC> +        if(std::string::npos != z)
GC> +            {
GC> +            parser_diagnostics.erase(z);
GC> +            }
GC> +        return wxString(parser_diagnostics.c_str());
GC>          }

 This is not really related to the changes of this patch series, but while
reading them I noticed this line and just wanted to say that an explicit
call to "c_str()" is not needed with any relatively recent version of
wxWidgets (i.e. since many years) as wxString has a ctor from std::string
(unless it was explicitly disabled by setting wxUSE_STD_STRING, which is 1
by default, to 0). Moreover, this ctor is implicit, so you don't even need
to write "wxString(...)" neither, so the last added line above could be
rewritten either as

        return wxString(parser_diagnostics);

or even as just

        return parser_diagnostics;

 I'm not sure if the latter is not too magic and I'd understand if you
preferred to keep "wxString(...)" for clarity, but I'd definitely remove
".c_str()" which is just superfluous.

 Finally, for completeness, notice that the situation in the other
direction is, unfortunately, not symmetric as we can't add a ctor from
wxString to std::string class, so you still have to explicitly call
wxString::ToStdString() to convert a wxString to std::string.

 Regards,
VZ


reply via email to

[Prev in Thread] Current Thread [Next in Thread]