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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75 | package Torello.Java;
class TagsGREP
{
static String grepIMG(String s)
{
String stlc = s.toLowerCase();
// System.out.println("1: " + stlc);
int imgPos = stlc.indexOf("<img ");
if (imgPos == -1) return null;
stlc = stlc.substring(imgPos + 5);
// System.out.println("2: " + stlc + "[imgPos=" + imgPos + "]");
// first check for double-quotes
String quote = "\"";
int srcPos = stlc.indexOf("src=\"");
if (srcPos == -1)
{
// if no double-quotes, try single quotes
srcPos = stlc.indexOf("src='");
if (srcPos == -1) return null;
quote = "'";
}
stlc = stlc.substring(srcPos + 5);
// System.out.println("3: " + stlc + "[srcPos=" + srcPos + "]");
int endSrcPos = stlc.indexOf(quote);
if (endSrcPos == -1) return null;
int urlStart = imgPos + srcPos + 10;
int urlEnd = urlStart + endSrcPos;
// System.out.println
// ("4: [endSrcPos=" + endSrcPos + ", urlStart=" + urlStart + ", urlEnd=" + urlEnd);
return s.substring(urlStart, urlEnd);
}
static String grepHREF(String s)
{
s = s.toLowerCase();
String quote = "\"";
int hrefPos = s.indexOf("href=\"");
if (hrefPos == -1)
{
hrefPos = s.indexOf("href='");
if (hrefPos == -1) return null;
quote = "'";
}
// System.out.print("\t[hrefPos=" + hrefPos + "]");
// the " + 6" is because the string HREF=" is 6 characters long
String ret = s.substring(hrefPos + 6);
int endQuotePos = ret.indexOf(quote);
if (endQuotePos == -1) throw new IllegalArgumentException
("HREF has no End-Quote!\n\nFor String:\n" + s);
// System.out.print("endQuotePos = " + endQuotePos + " " + ret.substring(0, endQuotePos));
return ret.substring(0,endQuotePos);
}
}
|