Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    strEndsWith has a little bug

    Bug Reporting (FUZE 4 Nintendo Switch)
    3
    3
    346
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • F
      fgalliat last edited by

      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 ;) )

      Z-Mann 1 Reply Last reply Reply Quote 4
      • Z-Mann
        Z-Mann @fgalliat last edited by

        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)

        1 Reply Last reply Reply Quote 2
        • Kat
          Kat Fuze Team last edited by

          Thank you @fgalliat and thank you for the additional info, @Z-Mann !!

          1 Reply Last reply Reply Quote 0
          • First post
            Last post