1
0
mirror of https://github.com/sys-fs/seddy synced 2024-11-22 11:54:16 -05:00

Fix behaviour of the i flag

This commit is contained in:
Thomas Mannay 2016-11-05 20:16:32 +00:00 committed by GitHub
parent 7cd7aaabb9
commit 51b66366ee

View File

@ -44,32 +44,32 @@ class Queue:
def empty(self): def empty(self):
return self.head == self.count return self.head == self.count
def find(self, s): def find(self, s, flags=0):
i = self.tail-1 i = self.tail-1
while True: while True:
if i == -1: if i == -1:
i = self.size-1 i = self.size-1
if re.search(s, self.data[i]): if re.search(s, self.data[i], flags):
return self.data[i] return self.data[i]
i -= 1 i -= 1
if i == self.tail-1 or self.data[i] is None: if i == self.tail-1 or self.data[i] is None:
return False return False
def seddy(sed, history): def seddy(sed, history):
flag = 0
regex = parse_sed.split(sed) regex = parse_sed.split(sed)
if len(regex) < 4: if len(regex) < 4:
return False return False
msg = history.find(regex[1]) if 'i' in regex[3]:
f = 0 flag |= re.I
msg = history.find(regex[1], flag)
if msg == False: if msg == False:
return False return False
if 'i' in regex[3]:
f |= re.I
if "g" in regex[3]: if "g" in regex[3]:
return re.sub(regex[1], regex[2], msg, flags=f) return re.sub(regex[1], regex[2], msg, flags=flag)
else: else:
return re.sub(regex[1], regex[2], msg, 1) return re.sub(regex[1], regex[2], msg, 1, flag)
def notice(msg): def notice(msg):
send.write('NOTICE ' + channel + ' :' + msg + '\r\n') send.write('NOTICE ' + channel + ' :' + msg + '\r\n')