FM> in a patch (not yet applied) I've proposed to add the functions:
FM>
FM> + wxString Join(const wxString& sep) const;
FM> + static wxArrayString Split(const wxString &str, const wxString &sep);
FM>
FM> functions to wxArrayString (the second is a simple call to wxStringTokenize).
FM>
FM> Vadim suggested to add similar ones also to wxList and wxArray and to move this
FM> discussion to wx-dev, so I'm doing it now.
Just the explain, the reason I'd like to have this as a function instead
of a member so that it could work with std::vector (and possibly std::list,
...) later.
Also, these functions, although not rocket-scientifically complicated, are
less trivial than what your patch implements as they have to do something
about separators. E.g. when you do Join(":") you must somehow escape any
colons inside the array elements (and Split() must undo this).
Regards,
VZ
AA> > I don't understand why should you do this, sorry. Join() should be a
AA> > simple and safe function. And being safe is more important that being
AA> > suitable for some esoteric uses or compatible with ECMAScript.
AA> I really do not see in which way it is less safe.
Because it makes it very easy to get wrong results.
AA> BTW is there at least a version of Join without separator?
I'm afraid we completely disagree about the purpose of this function. For
me Join() should be used to create a string from which an array can later
be recreated by Split(). It doesn't and shouldn't try to do everything. And
besides, "Join without separator" is really too trivial to speak about.
Regards,
VZ
AA> > AA> > I don't understand why should you do this, sorry. Join() should be a
AA> > AA> > simple and safe function. And being safe is more important that
AA> > being
AA> > AA> > suitable for some esoteric uses or compatible with ECMAScript.
AA> > AA> I really do not see in which way it is less safe.
AA> >
AA> > Because it makes it very easy to get wrong results.
AA> just stating "it's less safe because it's less safe" is not what I call an
AA> argument
I gave the argument in the very beginning. If you don't escape the
separators you can save one thing and restore something different. If you
don't see why is this a problem, I'm afraid I can't explain it any better.
AA> OK don't care, people will then continue to do their Join as "text =
AA> wxT(""); for (i=0; i<length; +i) text += array[i]", they will still claim
AA> that wx is damn slow, and we here will wonder 'but why do they say that'.
The loop will be hardly slower than Join() (faster in fact). And what does
the API design have to do with performance anyhow?
Regards,
VZ
Armel