Next / Previous / Contents / Shipman's homepage

38. Scan.matchArb(): Case-insensitive match

logscan.py
# - - -   S c a n . m a t c h A r b

    def matchArb(self, s):
        '''Does the rest of the line start with s, case-insensitive?
        '''

Conveniently, the Python slice operator does not complain if you specify an ending position beyond the end of the string.

logscan.py
        #-- 1 --
        endPos = self.pos + len(s)

        #-- 2 --
        # [ t  :=  contents of self.line from position self.pos
        #          up to position endPos or end of line, whichever
        #          is shorter ]
        t = self.line[self.pos:endPos]

        #-- 3 --
        if s.upper() == t.upper():
            return endPos
        else:
            return None