Am 20.06.2013 22:03, schrieb Olaf Radicke:

Olaf Radicke <[email protected]> hat am 20. Juni 2013 um 20:10
geschrieben:
So my Idea is to add a "TString" class with this missing function in cxxtools
or
in Tntnet.
a little bit like this:

https://github.com/OlafRadicke/peruschim_cpp/blob/master/src/models/OString.h

Best regards

Olaf
Hi Olaf,

A class with just static members is a indication that it shouldn't be a class but free functions. There are programming languages, which do not support free functions like Java but luckily our chosen language is not so poor.

And std::string is not so poor as you and others think. It just has a different philosophy. Algorithms do not need to be members of the string class. It is much simpler to add algorithms when they are not members. And there is no good reason to implement split or join as members into a string class. Use that:

std::string myString = "foo:bar:baz";
std::vector<std::string> tokens;
cxxtools::split(':', myString, std::back_inserter(tokens));// split string

std::string newString = cxxtools::join(tokens.begin(), tokens.end(), ','); // get it as a comma separated list or ...

cxxtools::join(tokens.begin(), tokens.end(), '\n', std::cout); // print it to stdout a word per line

std::string number = cxxtools::convert<std::string>(5+6); // convert number to string unsigned unum = cxxtools::convert<unsigned>("4711"); // convert string to number


Btw. you may want to look at <cxxtools/trim.h> as well. And don't tell me, that the API documentation is missing there - I just saw it.

For lowercase the string there are solutions in the standard library:

|std::string data= "Abc"; std::transform(data.begin(), data.end(), data.begin(), ::tolower);|

Often they do not look just like you expect but if you understand the flexibility, you can see, why they are free functions.

The above std::transform solution works with std::vector<char> or other container type classes as well. Do you want to have a tolower in std::vector<char> and std::set<char> and std::list<char> as well? Just one function does all that for you.

You see - we have chosen a great programming language ;-)


Tommi
------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Tntnet-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tntnet-general

Reply via email to