-
Notifications
You must be signed in to change notification settings - Fork 0
/
journosSearch.py
42 lines (34 loc) · 965 Bytes
/
journosSearch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import entry
class SearchParams:
def __init__(self, q=True, a=True, c=False):
# i.e., search question text? search answer text?
self.questions = q
self.answers = a
self.case_sensitive = c
def search(text, searchParam=None):
if not searchParam:
searchParam=SearchParams()
matches=[]
ent = entry.latest()
if ent.contains(text,searchParam):
matches.append(ent.date)
while ent.hasPrevious():
ent.getPrevious()
if ent.contains(text,searchParam):
matches.append(ent.date)
printMatches(matches, text, searchParam)
def printMatches(matches, text, searchParam):
ent = entry.Entry()
for d in matches:
ent.readEntry(d)
ent.printSearchMatches(text, searchParam)
def find_all_helper(a_str, sub):
start = 0
while True:
start = a_str.find(sub, start)
if start == -1: return
yield start
start += len(sub)
def find_all(a_str, sub):
# returns list of indexes in a_str where sub occurs
return list(find_all_helper(a_str, sub))