source: other-projects/FileTransfer-WebSocketPair/testGXTWithGreenstone/src/org/greenstone/gatherer/util/PatternTokenizer.java@ 33053

Last change on this file since 33053 was 33053, checked in by ak19, 5 years ago

I still had some stuff of Nathan Kelly's (FileTransfer-WebSocketPair) sitting on my USB. Had already commited the Themes folder at the time, 2 years back. Not sure if he wanted this additional folder commited. But I didn't want to delete it and decided it will be better off on SVN. When we use his project, if we find we didn't need this test folder, we can remove it from svn then.

File size: 2.4 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the Gatherer application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * Author: John Thompson, Greenstone Digital Library, University of Waikato
9 *
10 * Copyright (C) 1999 New Zealand Digital Library Project
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *########################################################################
26 */
27package org.greenstone.gatherer.util;
28
29public class PatternTokenizer {
30 private int index;
31 private String content;
32 private String pattern;
33 public PatternTokenizer(String content, String pattern) {
34 this.content = content;
35 this.index = 0;
36 this.pattern = pattern;
37 }
38 public boolean hasMoreTokens() {
39 return (index != -1 && content.length() - index > 0);
40 }
41 public String nextToken() {
42 // Special case when index is zero
43 if(index == 0) {
44 index = content.indexOf(pattern);
45 // No occurance of pattern, return whole string
46 if(index == -1) {
47 return content;
48 }
49 // Return the fragment from 0 to index
50 else {
51 return content.substring(0, index);
52 }
53 }
54 // Otherwise
55 else {
56 // We must first skip the pattern, as it should be at the head of our current view into content
57 index = index + pattern.length();
58 int end_index = content.indexOf(pattern, index);
59 String fragment;
60 // No occurance of pattern, return fragment from index to length
61 if(end_index == -1) {
62 fragment = content.substring(index);
63 }
64 // Return the fragment from index to end index, then set index to end index
65 else {
66 fragment = content.substring(index, end_index);
67 }
68 index = end_index;
69 return fragment;
70 }
71 }
72}
Note: See TracBrowser for help on using the repository browser.