Having first come across this function in the downloadable 1.69 version I have now double checked with the online version of the Lexicon. I am still confused. If you pass this function the default delimiter of a single space, does it really only remove a single character? TBH, I find the description in need of clarification if that is not the case. If it is the case what is the point of this function?
Thanks.
[edit]
Actually, having read and re-read the description multiple times now, I think it acts like what would be called Left/Right TrimString in other programming languages. If that is the case you would need to call it twice to trim both ends.
You have a string sSource which says “AAA BBB CCC DDD” and a string sParsed which is “BBB”, it returns a string which represents the string of a length equal to sParsed removed from sSource.
So in default implementation, if you call StringRemoveParsed(sSource, sParsed, " ", FALSE) - the last two aren’t neccesary, those are the defaults, “AAA BBB CCC DDD” would be returned as “AAA BBB CCC” - the last 3 letters (length of the sParsed string) and the trailing delimiter would be removed.
If you told me the name is misleading because you’d think “remove parsed” would remove the instance of sParsed from sSource, I’m right there with you, because that’s what I would have assumed as well.
I mostly agree with May but… I think it does just what it says.
You have “AAA BBB CCC DDD” and you do StringParse() and get “AAA”. Then you StringRemovedParsed() and you have “BBB CCC DDD”. So it removes what you parsed from the left (or doing it in reverse with DDD, right) of the source. Now you can StringParse() the source again and get the next token “BBB”.
I prefer the tokenizer myself. But it may be slower (if a bit more functional).
A universal rule of programming is that if it looks weird and you don’t understand why they’d do it that way… the answer is almost always “optimization.”
You can look for yourself, it’s in an include so it’s open source.
It deletes any number of characters (given by the length of the parse string) from the left or right of the source and then looks for delimiters to delete them too.
It’s really a confusing name since there is nothing parsed. If you ask why they not simply pass the number of characters as integer … well, this is most probably “optimization”.
Well, the idea is, as I said, you use it with StringParse() so there is something parsed before and then this removes what you parsed from the source so you can keep going. I don’t think the name is all that confusing.
Someone would have to call GetStringLength() somewhere. Caller or callee doesn’t matter too much I suppose.
It’s just that if you use it on its own without that, and thus divorce it from the context that dubs its name, it becomes quite confusing which is why I made a point of, er, pointing out the behaviour if its not the leading thing.