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.Vector;
\r
37 public class StringParser {
\r
39 * Trim the given string, without removing non-printable characters.
\r
43 * @return trimmed string.
\r
45 public static String trim(String t) {
\r
47 while ((a < t.length()) && (t.charAt(a) == ' '))
\r
49 if (a == t.length())
\r
51 int b = t.length() - 1;
\r
52 while ((b >= 0) && (t.charAt(b) == ' '))
\r
56 return t.substring(a, b + 1);
\r
59 private int indexOf(String s, char toFind) {
\r
61 for (int i = 0; i < s.length(); i++) {
\r
62 char c = s.charAt(i);
\r
63 if ((deep == 0) && (c == toFind))
\r
78 * @return arrays of strings.
\r
80 public String[] parseString(String line) {
\r
81 Vector res = new Vector();
\r
82 while (line.length() != 0) {
\r
83 int pos = indexOf(line, ' ');
\r
85 res.insertElementAt(line, res.size());
\r
88 String part = trim(line.substring(0, pos));
\r
89 line = trim(line.substring(pos));
\r
90 res.insertElementAt(part, res.size());
\r
94 String[] param = new String[res.size()];
\r
95 for (int i = 0; i < res.size(); i++)
\r
96 param[i] = (String) res.elementAt(i);
\r