2
2
package org.crosswire.jsword.control.search;
4
import java.util.Enumeration;
5
import java.util.Hashtable;
6
import java.util.Vector;
4
import java.util.ArrayList;
5
import java.util.Iterator;
9
* Our command line parsing is a little specialized, so StringTokenizer is not
10
* up to the job. The specific problem is that there is sometimes no separator
11
* between parts of the command, and since this is specialized we also leave the
12
* results in a Vector of SearchWords.
14
* <table border='1' cellPadding='3' cellSpacing='0' width="100%">
15
* <tr><td bgColor='white'class='TableRowColor'><font size='-7'>
16
* Distribution Licence:<br />
17
* Project B is free software; you can redistribute it
18
* and/or modify it under the terms of the GNU General Public License,
19
* version 2 as published by the Free Software Foundation.<br />
20
* This program is distributed in the hope that it will be useful,
21
* but WITHOUT ANY WARRANTY; without even the implied warranty of
22
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23
* General Public License for more details.<br />
24
* The License is available on the internet
25
* <a href='http://www.gnu.org/copyleft/gpl.html'>here</a>, by writing to
26
* <i>Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
27
* MA 02111-1307, USA</i>, Or locally at the Licence link below.<br />
28
* The copyright to this program is held by it's authors.
29
* </font></td></tr></table>
30
* @see <a href='http://www.eireneh.com/servlets/Web'>Project B Home</a>
31
* @see <{docs.Licence}>
10
* Our command line parsing is a little specialized, so StringTokenizer is not
11
* up to the job. The specific problem is that there is sometimes no separator
12
* between parts of the command, and since this is specialized we also leave the
13
* results in a Vector of SearchWords.
15
* <p><table border='1' cellPadding='3' cellSpacing='0'>
16
* <tr><td bgColor='white' class='TableRowColor'><font size='-7'>
18
* Distribution Licence:<br />
19
* JSword is free software; you can redistribute it
20
* and/or modify it under the terms of the GNU General Public License,
21
* version 2 as published by the Free Software Foundation.<br />
22
* This program is distributed in the hope that it will be useful,
23
* but WITHOUT ANY WARRANTY; without even the implied warranty of
24
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25
* General Public License for more details.<br />
26
* The License is available on the internet
27
* <a href='http://www.gnu.org/copyleft/gpl.html'>here</a>, or by writing to:
28
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
29
* MA 02111-1307, USA<br />
30
* The copyright to this program is held by it's authors.
31
* </font></td></tr></table>
33
* @author Joe Walker [joe at eireneh dot com]
34
36
public class CustomTokenizer
39
41
* @param commands The Hashtable of SearchWords to select from
40
42
* @return An Vector of selected SearchWords
42
public static Vector tokenize(String sought, Hashtable commands) throws SearchException
44
public static List tokenize(String sought, Map commands) throws SearchException
44
Vector output = new Vector();
46
List output = new ArrayList();
45
47
String command_chars = getSingleCharWords(commands);
46
48
int current_type = charType(sought.charAt(0), command_chars);
47
49
int start_index = 0;
118
124
* @param commands The SearchWord source
119
125
* @param word The trigger to look for
121
private static void addWord(Vector output, Hashtable commands, String word)
127
private static void addWord(List output, Map commands, String word)
123
129
Object word_obj = commands.get(word);
124
if (word_obj == null) word_obj = new DefaultParamWord(word);
125
output.addElement(word_obj);
130
if (word_obj == null)
131
word_obj = new DefaultParamWord(word);
133
output.add(word_obj);
131
139
* @param commands The SearchWord source
132
140
* @param word The trigger to look for
134
private static String getSingleCharWords(Hashtable commands)
142
private static String getSingleCharWords(Map commands)
136
Enumeration en = commands.keys();
144
Iterator it = commands.keySet().iterator();
137
145
StringBuffer buf = new StringBuffer();
139
while (en.hasMoreElements())
141
String cmd = (String) en.nextElement();
149
String cmd = (String) it.next();
142
150
if (cmd.length() == 1) buf.append(cmd);