-
Notifications
You must be signed in to change notification settings - Fork 1
/
DogSearcher.java
48 lines (39 loc) · 1.01 KB
/
DogSearcher.java
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
43
44
45
46
47
48
//
// Class to search a connected url with a search expression
// (c) Jimmy Larsson 1998
//
public final class DogSearcher
{
protected DogConnectionContent content;
public DogSearcher (DogConnectionContent cont)
{
content = cont;
}
// Return number of occurances of the search expression
public int search (DogSearchExp searchExp)
{
int startIndex;
int occurs = 0;
String searchString;
String searchContent;
if (searchExp.caseSensitive())
{
searchString = searchExp.getSearchString();
searchContent = content.getData();
}
else
{
searchString = searchExp.getSearchString().toLowerCase();
searchContent = content.getDataLowerCase();
}
startIndex = searchContent.indexOf (searchString,0);
while (startIndex >= 0)
{
occurs++;
startIndex = searchContent.indexOf (searchString,startIndex + 1);
}
// FOR DEBUGGING
//System.out.println ("search, occurs: " + occurs);
return occurs;
}
}