Skip to content

Skipping the special character in string 5 of SNIP not working #79

@Poikilos

Description

@Poikilos

I renamed a couple variables for clarity.

In this code, i += 1 does nothing, because range is an iterator not a literal < check.

    def findString(self, n: int) -> int:
        '''Find start index of the nth string.
        Is aware of the 2nd version code byte.

        Args:
            n (int): Zero indexed.
        Returns:
            int: 0, or logs and returns -1 if the string isn't found
                within the buffer
        '''

        if n == 0:
            return 1  # first one is automatic
        currentStart = 1
        stringsFound = 0
        # scan over the buffer
        for i in range(1, 252):
            # checking for an end-of-string mark
            if self.data[i] == 0:
                # found one - this ends the stringCount string
                # if that's the request, return start
                if stringsFound == n:
                    return currentStart
                # if not, the _next_ character starts the next string
                currentStart = i+1
                stringsFound += 1
                # special case for the 5th string
                if stringsFound == 4:
                    i += 1
                    currentStart += 1
        # fell out without finding
        return 0

So I assume I should change it like this:

-        for i in range(1, 252):
-        i = 1
+        while i < 252:
  • then at the end of the loop add i += 1 to continue as the old code would:
+            i += 1

?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions