StringArray method request

currently, the only methods to have a StringArray built from a String that’s splitted around separators is to create the empty StringArray first, and call addTokens afterwards:

StringArray array;
array.addTokens ("1 2 3 etc");

I’d find it handy if there were a StringArray::fromTokens factory method that did just that, returning the resulting StringArray.

StringArray StringArray::fromTokens (..same parameters as addTokens() here..)
    StringArray array;
    array.addTokens (..passed parameters..);
    return array;

That would be perfect to inline simple StringArrays with simple and known content where it’s needed (for initialization purposes, for example).

What do you think you about that, jules?

1 Like

Yes, I’ve thought the same thing many times, just never quite got around to coding it!

while you’re at it, what about a setPointHeight for Font? the current withPointHeight requires one to do something like

Font f (some typeface here);
f = f.withPointHeight (10.0f);

which requires an unnecessarily complicated assignment just to do a simple

Well… that’s the opposite direction to the way I’d like the Font class to work. I regret not making it an immutable class from the start, so am avoiding adding any new non-const methods.

Ah right, now I remember… I think we had this conversation already.

What about a handy factory method for it too, then?

Why would you need a factory method?

e.g. it’s just as easy to write

You are right, I was just not comfortable enough with the idea of creating a temporary object just to create another one with a different size out of it