6622: Change regular expression rules to use search rather than match

svn: r21975
This commit is contained in:
Nick Hall 2013-04-13 14:30:12 +00:00
parent 89847f1df3
commit 5d3735123e
5 changed files with 15 additions and 15 deletions

View File

@ -61,6 +61,6 @@ class HasNoteRegexBase(Rule):
for notehandle in notelist:
note = db.get_note_from_handle(notehandle)
n = note.get()
if self.match.match(n) is not None:
if self.match.search(n) is not None:
return True
return False

View File

@ -61,4 +61,4 @@ class RegExpIdBase(Rule):
self.match = re.compile('')
def apply(self, db, obj):
return self.match.match(obj.gramps_id) is not None
return self.match.search(obj.gramps_id) is not None

View File

@ -59,6 +59,6 @@ class MatchesRegexpOf(Rule):
def apply(self, db, note):
""" Apply the filter """
text = note.get()
if self.match.match(text) is not None:
if self.match.search(text) is not None:
return True
return False

View File

@ -111,31 +111,31 @@ class HasNameOf(Rule):
valpatr = 1
if self.regular_expression:
try:
if self.firstn and not re.match(self.firstn, name.get_first_name(), re.I|re.U|re.L):
if self.firstn and not re.search(self.firstn, name.get_first_name(), re.I|re.U|re.L):
val = 0
elif self.lastn and not re.match(self.lastn, name.get_surname(), re.I|re.U|re.L):
elif self.lastn and not re.search(self.lastn, name.get_surname(), re.I|re.U|re.L):
val = 0
elif self.suffix and not re.match(self.suffix, name.get_suffix(), re.I|re.U|re.L):
elif self.suffix and not re.search(self.suffix, name.get_suffix(), re.I|re.U|re.L):
val = 0
elif self.title and not re.match(self.title, name.get_title(), re.I|re.U|re.L):
elif self.title and not re.search(self.title, name.get_title(), re.I|re.U|re.L):
val = 0
elif self.calln and not re.match(self.calln, name.get_call_name(), re.I|re.U|re.L):
elif self.calln and not re.search(self.calln, name.get_call_name(), re.I|re.U|re.L):
val = 0
elif self.nick and not re.match(self.nick, name.get_nick_name(), re.I|re.U|re.L):
elif self.nick and not re.search(self.nick, name.get_nick_name(), re.I|re.U|re.L):
val = 0
elif self.famnick and not re.match(self.famnick, name.get_family_nick_name(), re.I|re.U|re.L):
elif self.famnick and not re.search(self.famnick, name.get_family_nick_name(), re.I|re.U|re.L):
val = 0
else:
#obtain surnames
for surn in name.get_surname_list():
if self.prefix and re.match(self.prefix, surn.get_prefix(), re.I|re.U|re.L):
if self.prefix and re.search(self.prefix, surn.get_prefix(), re.I|re.U|re.L):
valpref = 1
if self.surn and re.match(self.surn, surn.get_surname(), re.I|re.U|re.L):
if self.surn and re.search(self.surn, surn.get_surname(), re.I|re.U|re.L):
valsurn = 1
if self.con and re.match(self.con, surn.get_connector(), re.I|re.U|re.L):
if self.con and re.search(self.con, surn.get_connector(), re.I|re.U|re.L):
valcon = 1
if self.patr and surn.get_origintype().value == NameOriginType.PATRONYMIC \
and re.match(self.patr, surn.get_surname(), re.I|re.U|re.L):
and re.search(self.patr, surn.get_surname(), re.I|re.U|re.L):
valpatr = 1
except re.error:
#indicate error in the pattern by matching everyone

View File

@ -63,7 +63,7 @@ class RegExpName(Rule):
for name in [person.get_primary_name()] + person.get_alternate_names():
for field in [name.first_name, name.get_surname(), name.suffix,
name.title, name.nick, name.famnick, name.call]:
if self.match.match(field):
if self.match.search(field):
return True
else:
return False