strEndsWith has a little bug
-
Hi, sorry if the topic has already been posted in the past (I didn't find it)
strEndsWith( toscan, tofind ) always return true if 'toscan' is an empty string..
Anyway, thanks for your job, FUZE is great (even if I wish to export my code to my computer... that's another subject ;) )
-
Confirmed that this is still the case, as long as toFind has a length of 1. Furthermore,
strEndsWith("AB", "B")
correctly returns 1,
strEndsWith("BA", "B")
correctly returns 0, but
strEndsWith("BAB", "B")
incorrectly returns 0. This works for longer search strings, too. Looks like strEndsWith is implemented like
function strEndsWith(myStr, toFind) return strFind(myStr, toFind) == len(myStr) - len(toFind)
which obviously gets tripped up if toFind appears more than once in myStr, and since strFind returns -1 if it does not find any occurrence, explains why strEndsWith("", "B") returns 1. And we can test the hypothesis with different inputs! strEndsWith should always incorrectly return 1 if toFind is one character longer than myStr. Indeed,
strEndsWith("ABC", "FUZE")
gives 1.
Workaround: Use this function instead:
function strEndsWith2(myStr, toFind) ret = false length = len(myStr) begin = length - len(toFind) if begin >= 0 then // otherwise, myStr is too short to match // this is the end part of myStr with the same length as toFind; the slicing/substring operation used is undocumented and a bit dangerous myStrEnd = myStr[begin:] ret = (toFind == myStrEnd) endIf return ret
(Also, documentation copy/paste error, the "Purpose" paragraph of the strEndsWith function is unaltered from strBeginsWith)
-