Sort fix,, i forgor 💀
This commit is contained in:
parent
ce54787062
commit
7c7d406d4f
1 changed files with 76 additions and 56 deletions
132
dataobjs.py
132
dataobjs.py
|
@ -146,23 +146,79 @@ class pesterQuirks(object):
|
||||||
checkstate = int(q.checkstate)
|
checkstate = int(q.checkstate)
|
||||||
except Exception:
|
except Exception:
|
||||||
checkstate = 0
|
checkstate = 0
|
||||||
# Check for substring that should be excluded.
|
|
||||||
excludes = list()
|
# Exclude option is checked
|
||||||
# Check for links, store in list.
|
if checkstate == 2:
|
||||||
for match in re.finditer(_urlre, string):
|
# Check for substring that should be excluded.
|
||||||
excludes.append(match)
|
excludes = list()
|
||||||
# Check for smilies, store in list.
|
# Check for links, store in list.
|
||||||
for match in re.finditer(_smilere, string):
|
for match in re.finditer(_urlre, string):
|
||||||
excludes.append(match)
|
excludes.append(match)
|
||||||
# Check for @handles, store in list.
|
# Check for smilies, store in list.
|
||||||
for match in re.finditer(_handlere, string):
|
for match in re.finditer(_smilere, string):
|
||||||
excludes.append(match)
|
excludes.append(match)
|
||||||
# Check for #memos, store in list.
|
# Check for @handles, store in list.
|
||||||
for match in re.finditer(_memore, string):
|
for match in re.finditer(_handlere, string):
|
||||||
excludes.append(match)
|
excludes.append(match)
|
||||||
|
# Check for #memos, store in list.
|
||||||
# Checkstate == 0 means the exclude option is unchecked.
|
for match in re.finditer(_memore, string):
|
||||||
if (checkstate == 0) or (len(excludes) == 0):
|
excludes.append(match)
|
||||||
|
|
||||||
|
if len(excludes) >= 1:
|
||||||
|
# SORT !!!
|
||||||
|
excludes.sort(key=lambda exclude: exclude.start())
|
||||||
|
|
||||||
|
# Seperate parts to be quirked.
|
||||||
|
sendparts = list()
|
||||||
|
# Add string until start of exclude at index 0.
|
||||||
|
until = excludes[0].start()
|
||||||
|
sendparts.append(string[:until])
|
||||||
|
# Add strings between excludes.
|
||||||
|
for part in range(1, len(excludes)):
|
||||||
|
after = excludes[part-1].end()
|
||||||
|
until = excludes[part].start()
|
||||||
|
sendparts.append(string[after:until])
|
||||||
|
# Add string after exclude at last index.
|
||||||
|
after = excludes[-1].end()
|
||||||
|
sendparts.append(string[after:])
|
||||||
|
|
||||||
|
# Quirk to-be-quirked parts.
|
||||||
|
recvparts = list()
|
||||||
|
for part in sendparts:
|
||||||
|
# No split, apply like normal.
|
||||||
|
if q.type == 'regexp' or q.type == 'random':
|
||||||
|
recvparts.append(q.apply(part,
|
||||||
|
first=(i==0),
|
||||||
|
last=lastStr))
|
||||||
|
elif q.type == 'prefix' and i == 0:
|
||||||
|
recvparts.append(q.apply(part))
|
||||||
|
elif q.type == 'suffix' and lastStr:
|
||||||
|
recvparts.append(q.apply(part))
|
||||||
|
else:
|
||||||
|
recvparts.append(q.apply(part))
|
||||||
|
# Reconstruct and update string.
|
||||||
|
string = ''
|
||||||
|
print("excludes: " + str(excludes))
|
||||||
|
print("sendparts: " + str(sendparts))
|
||||||
|
print("recvparts: " + str(recvparts))
|
||||||
|
for part in range(0, len(excludes)):
|
||||||
|
string += recvparts[part]
|
||||||
|
string += excludes[part].group()
|
||||||
|
string += recvparts[-1]
|
||||||
|
else:
|
||||||
|
# No split, apply like normal.
|
||||||
|
if q.type != 'prefix' and q.type != 'suffix':
|
||||||
|
if q.type == 'regexp' or q.type == 'random':
|
||||||
|
string = q.apply(string,
|
||||||
|
first=(i==0),
|
||||||
|
last=lastStr)
|
||||||
|
else:
|
||||||
|
string = q.apply(string)
|
||||||
|
elif q.type == 'prefix' and i == 0:
|
||||||
|
string = q.apply(string)
|
||||||
|
elif q.type == 'suffix' and lastStr:
|
||||||
|
string = q.apply(string)
|
||||||
|
else:
|
||||||
# No split, apply like normal.
|
# No split, apply like normal.
|
||||||
if q.type != 'prefix' and q.type != 'suffix':
|
if q.type != 'prefix' and q.type != 'suffix':
|
||||||
if q.type == 'regexp' or q.type == 'random':
|
if q.type == 'regexp' or q.type == 'random':
|
||||||
|
@ -175,45 +231,9 @@ class pesterQuirks(object):
|
||||||
string = q.apply(string)
|
string = q.apply(string)
|
||||||
elif q.type == 'suffix' and lastStr:
|
elif q.type == 'suffix' and lastStr:
|
||||||
string = q.apply(string)
|
string = q.apply(string)
|
||||||
# Exclude option is checked, split string and only quirk
|
|
||||||
# the parts without links/smilies/@handle/#memo
|
|
||||||
elif (checkstate == 2) and (len(excludes) >= 1):
|
|
||||||
# Seperate parts to be quirked.
|
|
||||||
sendparts = list()
|
|
||||||
# Add string until start of exclude at index 0.
|
|
||||||
until = excludes[0].start()
|
|
||||||
sendparts.append(string[:until])
|
|
||||||
# Add strings between excludes.
|
|
||||||
for part in range(1, len(excludes)):
|
|
||||||
after = excludes[part-1].end()
|
|
||||||
until = excludes[part].start()
|
|
||||||
sendparts.append(string[after:until])
|
|
||||||
# Add string after exclude at last index.
|
|
||||||
after = excludes[-1].end()
|
|
||||||
sendparts.append(string[after:])
|
|
||||||
|
|
||||||
# Quirk to-be-quirked parts.
|
|
||||||
recvparts = list()
|
|
||||||
for part in sendparts:
|
|
||||||
# No split, apply like normal.
|
|
||||||
if q.type == 'regexp' or q.type == 'random':
|
|
||||||
recvparts.append(q.apply(part,
|
|
||||||
first=(i==0),
|
|
||||||
last=lastStr))
|
|
||||||
elif q.type == 'prefix' and i == 0:
|
|
||||||
recvparts.append(q.apply(part))
|
|
||||||
elif q.type == 'suffix' and lastStr:
|
|
||||||
recvparts.append(q.apply(part))
|
|
||||||
else:
|
|
||||||
recvparts.append(q.apply(part))
|
|
||||||
# Reconstruct and update string.
|
|
||||||
string = ''
|
|
||||||
#print("sendparts: " + str(sendparts))
|
|
||||||
#print("recvparts: " + str(recvparts))
|
|
||||||
for part in range(0, len(excludes)):
|
|
||||||
string += recvparts[part]
|
|
||||||
string += excludes[part].group()
|
|
||||||
string += recvparts[-1]
|
|
||||||
|
|
||||||
newlist.append(string)
|
newlist.append(string)
|
||||||
final = []
|
final = []
|
||||||
|
|
Loading…
Reference in a new issue