Thanks for the answers!
I haven't got much experience yet of std::string so I thought the grass was greener over there. But sure, functions like split() and trimmed() I use regularly, and they indeed seem to be lacking in std::string. So sorry QString about that brief moment of infidelity, won't happen again :-)


On 2019-10-18 03:49, Sze Howe Koh wrote:
On Fri, 18 Oct 2019 at 08:43, Alexander Nassian
<[email protected]> wrote:
C++ hasn‘t even proper Unicode handling integrated. std::string is a mess in my 
opinion.

Beste Grüße / Best regards,
Alexander Nassian

Am 18.10.2019 um 02:30 schrieb Henry Skoglund <[email protected]>:

 Hi, while writing lots of QString string fiddling code (keyboard macro 
utility) I feel something tugging at my sleeve:
the upcoming C++20, looking at std::format(), it seems really handy, e.g.:

std::string s = std::format("String '{}' has {} characters\n", string, 
string.length());

// for a German flavor you can use arg #
std::string s = std::format("{1} Zeichen lang ist die Zeichenkette '{0}'\n", 
string, string.length());

// lots of formatting options with a ':' inside the curlies
std::string s = std::format("{0:b} {0:d} {0:x}", 42);   // s == "101010 42 2a"

Using QString::arg() works fine but it's getting harder to ignore all the new 
C++ stuff and C++20 looks to be one of the bigger additions to the language 
since C++11.

Perhaps the time has come to think about a retirement plan for QString?

Rgrds Henry
I agree with Alexander; QString is far more pleasant to use than
std::string for many everyday tasks.

Aside from Unicode support, std::string lacks (clean) equivalents of
the following functions which I use regularly:
- QString::startsWith(), QString::endsWith()
- QString::split(), QString::section()
- QString::simplified(), QString::trimmed()
- QString::contains(), QString::indexOf() by regex
- QString::replace(), QString::remove() by substring or by regex

I refuse to ditch QString for std::string until Unicode and the above
functionality are offered in std::string, at the very least.


Here are more functions that are lacking in std::string. I personally
don't use them much, but they look pretty handy if the right project
comes along:
- QString::right()
- QString::localeAwareCompare()
- QString::compare() with Qt::CaseInsensitive
- QString::chop(), QString::chopped()
- QString::leftJustified(), QString::rightJustified()


Regards,
Sze-Howe
_______________________________________________
Development mailing list
[email protected]
https://lists.qt-project.org/listinfo/development

_______________________________________________
Development mailing list
[email protected]
https://lists.qt-project.org/listinfo/development

Reply via email to