1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.tapestry.util; |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| public class StringSplitter |
27 |
| { |
28 |
| private char delimiter; |
29 |
| |
30 |
106
| public StringSplitter(char delimiter)
|
31 |
| { |
32 |
106
| this.delimiter = delimiter;
|
33 |
| } |
34 |
| |
35 |
0
| public char getDelimiter()
|
36 |
| { |
37 |
0
| return delimiter;
|
38 |
| } |
39 |
| |
40 |
| |
41 |
| |
42 |
| |
43 |
| |
44 |
| |
45 |
| |
46 |
| |
47 |
| |
48 |
106
| public String[] splitToArray(String value)
|
49 |
| { |
50 |
106
| char[] buffer;
|
51 |
106
| int i;
|
52 |
106
| String[] result;
|
53 |
106
| int resultCount = 0;
|
54 |
106
| int start;
|
55 |
106
| int length;
|
56 |
106
| String token;
|
57 |
106
| String[] newResult;
|
58 |
106
| boolean first = true;
|
59 |
| |
60 |
106
| buffer = value.toCharArray();
|
61 |
| |
62 |
106
| result = new String[3];
|
63 |
| |
64 |
106
| start = 0;
|
65 |
106
| length = 0;
|
66 |
| |
67 |
106
| for (i = 0; i < buffer.length; i++)
|
68 |
| { |
69 |
692
| if (buffer[i] != delimiter)
|
70 |
| { |
71 |
690
| length++;
|
72 |
690
| continue;
|
73 |
| } |
74 |
| |
75 |
| |
76 |
| |
77 |
2
| if (length > 0 || !first)
|
78 |
| { |
79 |
2
| token = new String(buffer, start, length);
|
80 |
| |
81 |
2
| if (resultCount == result.length)
|
82 |
| { |
83 |
0
| newResult = new String[result.length * 2];
|
84 |
| |
85 |
0
| System.arraycopy(result, 0, newResult, 0, result.length);
|
86 |
| |
87 |
0
| result = newResult;
|
88 |
| } |
89 |
| |
90 |
2
| result[resultCount++] = token;
|
91 |
| |
92 |
2
| first = false;
|
93 |
| } |
94 |
| |
95 |
2
| start = i + 1;
|
96 |
2
| length = 0;
|
97 |
| } |
98 |
| |
99 |
| |
100 |
| |
101 |
| |
102 |
| |
103 |
| |
104 |
| |
105 |
106
| if (start == 0 && length == buffer.length)
|
106 |
| { |
107 |
104
| result = new String[1];
|
108 |
104
| result[0] = value;
|
109 |
104
| return result;
|
110 |
| } |
111 |
| |
112 |
| |
113 |
| |
114 |
| |
115 |
2
| token = new String(buffer, start, length);
|
116 |
| |
117 |
2
| newResult = new String[resultCount + 1];
|
118 |
2
| System.arraycopy(result, 0, newResult, 0, resultCount);
|
119 |
2
| newResult[resultCount] = token;
|
120 |
| |
121 |
2
| return newResult;
|
122 |
| } |
123 |
| } |