|
|
@ -58,12 +58,14 @@ class Bm(object): |
|
|
|
Return the index of the *first* occurrence of the pattern in the |
|
|
|
text, or '-1' if the pattern is not in the text. |
|
|
|
""" |
|
|
|
PATTERN_LENGTH = len(self.pattern) |
|
|
|
if not self.pattern or not self.text or len(self.text) < PATTERN_LENGTH: |
|
|
|
return -1 |
|
|
|
|
|
|
|
# The search works on one character at a time in the text. The current |
|
|
|
# location is the "head" (like a read-head on a disk) |
|
|
|
# It starts at the last character in the pattern, and gets moved in the |
|
|
|
# loop until we reach the end of the text |
|
|
|
PATTERN_LENGTH = len(self.pattern) |
|
|
|
head = PATTERN_LENGTH - 1 |
|
|
|
while head < len(self.text): |
|
|
|
# When the last character of the pattern matches the current head |
|
|
|