01: /*
02: * Create a graphviz graph based on the classes in the specified java
03: * source files.
04: *
05: * (C) Copyright 2002-2005 Diomidis Spinellis
06: *
07: * Permission to use, copy, and distribute this software and its
08: * documentation for any purpose and without fee is hereby granted,
09: * provided that the above copyright notice appear in all copies and that
10: * both that copyright notice and this permission notice appear in
11: * supporting documentation.
12: *
13: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
14: * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
15: * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16: *
17: * $Id: StringUtil.java,v 1.60 2007/11/27 09:04:22 dds Exp $
18: *
19: */
20:
21: package org.umlgraph.doclet;
22:
23: import java.util.*;
24:
25: /**
26: * String utility functions
27: * @version $Revision: 1.60 $
28: * @author <a href="http://www.spinellis.gr">Diomidis Spinellis</a>
29: */
30: class StringUtil {
31: /** Tokenize string s into an array */
32: public static String[] tokenize(String s) {
33: ArrayList<String> r = new ArrayList<String>();
34: String remain = s;
35: int n = 0, pos;
36:
37: remain = remain.trim();
38: while (remain.length() > 0) {
39: if (remain.startsWith("\"")) {
40: // Field in quotes
41: pos = remain.indexOf('"', 1);
42: if (pos == -1)
43: break;
44: r.add(remain.substring(1, pos));
45: if (pos + 1 < remain.length())
46: pos++;
47: } else {
48: // Space-separated field
49: pos = remain.indexOf(' ', 0);
50: if (pos == -1) {
51: r.add(remain);
52: remain = "";
53: } else
54: r.add(remain.substring(0, pos));
55: }
56: remain = remain.substring(pos + 1);
57: remain = remain.trim();
58: // - is used as a placeholder for empy fields
59: if (r.get(n).equals("-"))
60: r.set(n, "");
61: n++;
62: }
63: return r.toArray(new String[0]);
64: }
65:
66: }
|