1 /*****************************************************/
\r
2 /* This java file is a part of the */
\r
4 /* - Plouf's Java IRC Client - */
\r
6 /* Copyright (C) 2002 - 2004 Philippe Detournay */
\r
8 /* All contacts : theplouf@yahoo.com */
\r
10 /* PJIRC is free software; you can redistribute */
\r
11 /* it and/or modify it under the terms of the GNU */
\r
12 /* General Public License as published by the */
\r
13 /* Free Software Foundation; version 2 or later of */
\r
16 /* PJIRC is distributed in the hope that it will */
\r
17 /* be useful, but WITHOUT ANY WARRANTY; without */
\r
18 /* even the implied warranty of MERCHANTABILITY or */
\r
19 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
\r
20 /* General Public License for more details. */
\r
22 /* You should have received a copy of the GNU */
\r
23 /* General Public License along with PJIRC; if */
\r
24 /* not, write to the Free Software Foundation, */
\r
25 /* Inc., 59 Temple Place, Suite 330, Boston, */
\r
26 /* MA 02111-1307 USA */
\r
28 /*****************************************************/
\r
32 import java.util.Hashtable;
\r
33 import java.util.StringTokenizer;
\r
36 * Handling for unbound list of items.
\r
38 public class ListHandler {
\r
39 private boolean _baseAll;
\r
40 private Hashtable _list;
\r
41 private String _orig;
\r
44 * Create a new list of items.
\r
47 * item list. Syntax is : "" or "none+item1+item2+item3+..." or
\r
48 * "all-item1-item2-item3-..." If list is empty, it is equivalent to
\r
49 * "all". Items containing + or - characters can be used by replacing
\r
50 * them by \+ or \-. The \ character may be entenred using \\ syntax.
\r
52 public ListHandler(String list) {
\r
54 list = convert(list);
\r
56 _list = new Hashtable();
\r
57 StringTokenizer st = new StringTokenizer(list, "\1\2", true);
\r
58 if (!st.hasMoreTokens())
\r
60 String base = st.nextToken();
\r
61 if (base.equals("none"))
\r
63 while (st.hasMoreTokens()) {
\r
64 String mod = st.nextToken();
\r
65 if (mod.equals("\1"))
\r
67 else if (mod.equals("\2"))
\r
69 if (!st.hasMoreTokens())
\r
71 String token = st.nextToken().toLowerCase(java.util.Locale.ENGLISH);
\r
72 _list.put(token, mod);
\r
76 private String convert(String txt) {
\r
78 for (int i = 0; i < txt.length(); i++) {
\r
79 char c = txt.charAt(i);
\r
84 else if (c == '\\' && (i != txt.length() - 1)) {
\r
94 * Test wether the given item is in the list.
\r
98 * @return true if item is in the list, false otherwise.
\r
100 public boolean inList(String item) {
\r
101 item = item.toLowerCase(java.util.Locale.ENGLISH);
\r
102 String mod = (String) _list.get(item);
\r
105 if (mod.equals("+"))
\r
111 public String toString() {
\r