|
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 |
159
| public StringSplitter(char delimiter)
|
|
31 |
| { |
|
32 |
159
| 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 |
159
| public String[] splitToArray(String value)
|
|
49 |
| { |
|
50 |
159
| char[] buffer;
|
|
51 |
159
| int i;
|
|
52 |
159
| String[] result;
|
|
53 |
159
| int resultCount = 0;
|
|
54 |
159
| int start;
|
|
55 |
159
| int length;
|
|
56 |
159
| String token;
|
|
57 |
159
| String[] newResult;
|
|
58 |
159
| boolean first = true;
|
|
59 |
| |
|
60 |
159
| buffer = value.toCharArray();
|
|
61 |
| |
|
62 |
159
| result = new String[3];
|
|
63 |
| |
|
64 |
159
| start = 0;
|
|
65 |
159
| length = 0;
|
|
66 |
| |
|
67 |
159
| for (i = 0; i < buffer.length; i++)
|
|
68 |
| { |
|
69 |
1038
| if (buffer[i] != delimiter)
|
|
70 |
| { |
|
71 |
1035
| length++;
|
|
72 |
1035
| continue;
|
|
73 |
| } |
|
74 |
| |
|
75 |
| |
|
76 |
| |
|
77 |
3
| if (length > 0 || !first)
|
|
78 |
| { |
|
79 |
3
| token = new String(buffer, start, length);
|
|
80 |
| |
|
81 |
3
| 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 |
3
| result[resultCount++] = token;
|
|
91 |
| |
|
92 |
3
| first = false;
|
|
93 |
| } |
|
94 |
| |
|
95 |
3
| start = i + 1;
|
|
96 |
3
| length = 0;
|
|
97 |
| } |
|
98 |
| |
|
99 |
| |
|
100 |
| |
|
101 |
| |
|
102 |
| |
|
103 |
| |
|
104 |
| |
|
105 |
159
| if (start == 0 && length == buffer.length)
|
|
106 |
| { |
|
107 |
156
| result = new String[1];
|
|
108 |
156
| result[0] = value;
|
|
109 |
156
| return result;
|
|
110 |
| } |
|
111 |
| |
|
112 |
| |
|
113 |
| |
|
114 |
| |
|
115 |
3
| token = new String(buffer, start, length);
|
|
116 |
| |
|
117 |
3
| newResult = new String[resultCount + 1];
|
|
118 |
3
| System.arraycopy(result, 0, newResult, 0, resultCount);
|
|
119 |
3
| newResult[resultCount] = token;
|
|
120 |
| |
|
121 |
3
| return newResult;
|
|
122 |
| } |
|
123 |
| } |