# - - - S c a n . f l a t I n t
def flatInt ( self, n ):
'''Parse a fixed-field integer of size n
'''
This method uses the same regular expression as Section 42, “Scan.integer(): Parse an integer”; see Section 8.5, “INT_PATTERN”.
First we make sure that there are at least characters left on the line. If so,
they are matched against nINT_PATTERN; if there is
a match, it must match all characters.
n
#-- 1 --
# [ if the current line has at least n characters left ->
# rawInt := the next n characters from the line
# else ->
# return None ]
if len(self.line) - self.pos < n:
return None
else:
rawInt = self.line[self.pos:self.pos+n]
#-- 2 --
# [ if rawInt matches INT_PATTERN ->
# matchLen := the length of the matching part
# else -> return None ]
m = INT_PATTERN.match ( rawInt )
if m is None:
return None
else:
matchLen = m.end() - m.start()
#-- 3 --
if matchLen < n:
return None
else:
return int(rawInt)