3
* Copyright (C) 2008 W. Xaver
4
* W.Xaver[at]googlemail.com
5
* http://zdfmediathk.sourceforge.net/
7
* This program is free software: you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation, either version 3 of the License, or
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22
import java.util.ArrayList;
24
public class MSearchStringBuilder {
26
private StringBuilder cont;
27
private int pos1 = 0, pos2 = 0, pos3 = 0;
29
public MSearchStringBuilder() {
30
cont = new StringBuilder();
33
public MSearchStringBuilder(int capacity) {
34
cont = new StringBuilder(capacity);
37
public String substring(int start) {
38
return cont.substring(start);
41
public int lastIndexOf(String of) {
42
return cont.lastIndexOf(of);
49
public String substring(int start, int end) {
50
return cont.substring(start, end);
53
public synchronized void append(char[] str) {
57
public synchronized void append(char[] str, int offset, int len) {
58
cont.append(str, offset, len);
61
public synchronized void setLength(int newLength) {
62
cont.setLength(newLength);
65
public synchronized int indexOf(String str, int fromIndex) {
66
return cont.indexOf(str, fromIndex);
69
public synchronized int indexOf(String str) {
70
return cont.indexOf(str);
73
public String extract(String musterStart, String musterEnde) {
74
return extract(musterStart, musterEnde, 0);
77
public String extract(String musterStart, String musterEnde, int abPos) {
78
if ((pos1 = cont.indexOf(musterStart, abPos)) != -1) {
79
pos1 += musterStart.length();
80
if ((pos2 = cont.indexOf(musterEnde, pos1)) != -1) {
81
return cont.substring(pos1, pos2);
87
public void extractList(String musterStart, String musterEnde, int abPos, String addUrl, ArrayList<String> result) {
89
while ((pos1 = cont.indexOf(musterStart, pos1)) != -1) {
90
pos1 += musterStart.length();
91
if ((pos2 = cont.indexOf(musterEnde, pos1)) != -1) {
92
result.add(addUrl + cont.substring(pos1, pos2));
97
public String extractLast(String musterStart, String musterEnde) {
98
if ((pos1 = cont.lastIndexOf(musterStart)) != -1) {
99
pos1 += musterStart.length();
100
if ((pos2 = cont.indexOf(musterEnde, pos1)) != -1) {
101
return cont.substring(pos1, pos2);
107
public String extract(String musterStart, String musterEnde, int abPos, int stopPos) {
108
if ((pos1 = cont.indexOf(musterStart, abPos)) != -1) {
109
pos1 += musterStart.length();
110
if ((pos2 = cont.indexOf(musterEnde, pos1)) != -1) {
111
if (stopPos < 0 || pos2 < stopPos) {
112
return cont.substring(pos1, pos2);
119
public String extract(String musterStart1, String musterStart2, String musterEnde) {
120
return extract(musterStart1, musterStart2, musterEnde, 0, -1);
123
public String extract(String musterStart1, String musterStart2, String musterEnde, int abPos) {
124
return extract(musterStart1, musterStart2, musterEnde, abPos, -1);
127
public String extract(String musterStart1, String musterStart2, String musterEnde, int abPos, int stopPos) {
128
if ((pos1 = cont.indexOf(musterStart1, abPos)) != -1) {
129
pos1 += musterStart1.length();
130
if ((pos1 = cont.indexOf(musterStart2, pos1)) != -1) {
131
pos1 += musterStart2.length();
132
if ((pos2 = cont.indexOf(musterEnde, pos1)) != -1) {
133
if (stopPos < 0 || pos2 < stopPos) {
134
return cont.substring(pos1, pos2);