Closed jstine35 closed 5 years ago
There is an xStringTokenizer
which uses a naming scheme matching wxWidgets and a state machine operational method similar to strtok
to split strings. I used to have split and join APIs somewhere, I thought, but they seem to be missing. Those are trivial to implement.
Not sure those would be ideal for printing vector types tho.
In the paradigm of type-enforced C++, String.Join(src, delimiter)
the src
parameter should already be an iterable container of strings, or some other type that has only one clearly-defined way of being converted to string. In the common case, it should be the programmer's responsibility to convert them to strings. Trying to do lots of magic implicit type-to-string conversion behind the scenes at the moment any random type is being passed into String.Join()
isn't a strategy I want to encourage in C++ based core libs.
In any case there's no harm to adding them. They're easy. :)
The original intent of adding this function was to provide a quick and dirty way to format lists of data in different ways without having to get "clever" about formatting templates.
For example, two common ways to print a list of numbers:
My thinking was to have a single common-case toString() method that returns the top one and then, optionally, one can compress the spaces out of the string if a compact form is what's preferred (or required). Example:
This idea was brought to me by unix shell (BASH) style logic. This sort of thing tends to make more sense to me (now) than trying to add booleans or flags or lots of weird custom string-encoded formatting templates as parameters to
toString()
.All that said, I haven't actually found a good use for it yet because my initial use case was better solved via something else anyway. But figured I should bake these APIs in anyway, for later.
Test Coverage
Absolutely none! This code might upload all your credit cards to my secret stash. Use at your own risk.