Class | Line # | Actions | |||
---|---|---|---|---|---|
CharArrayBufferWrap | 17 | 9 | 7 |
1 | package // | |
2 | // This software is now distributed according to | |
3 | // the Lesser Gnu Public License. Please see | |
4 | // http://www.gnu.org/copyleft/lesser.txt for | |
5 | // the details. | |
6 | // -- Happy Computing! | |
7 | // | |
8 | com.stevesoft.pat.wrap; | |
9 | ||
10 | import com.stevesoft.pat.BasicStringBufferLike; | |
11 | import com.stevesoft.pat.StringLike; | |
12 | ||
13 | /** | |
14 | * Allows the outcome of a replaceAll() or replaceFirst() to be an array of | |
15 | * characters rather than a String. | |
16 | */ | |
17 | public class CharArrayBufferWrap implements BasicStringBufferLike | |
18 | { | |
19 | StringBuffer sb = new StringBuffer(); | |
20 | ||
21 | 0 | public void append(char c) |
22 | { | |
23 | 0 | sb.append(c); |
24 | } | |
25 | ||
26 | 0 | public void append(String s) |
27 | { | |
28 | 0 | sb.append(s); |
29 | } | |
30 | ||
31 | 0 | public StringLike toStringLike() |
32 | { | |
33 | 0 | char[] ca = new char[sb.length()]; |
34 | 0 | for (int i = 0; i < ca.length; i++) |
35 | { | |
36 | 0 | ca[i] = sb.charAt(i); |
37 | } | |
38 | 0 | return new CharArrayWrap(ca); |
39 | } | |
40 | ||
41 | 0 | public int length() |
42 | { | |
43 | 0 | return sb.length(); |
44 | } | |
45 | ||
46 | 0 | public String toString() |
47 | { | |
48 | 0 | return sb.toString(); |
49 | } | |
50 | ||
51 | 0 | public Object unwrap() |
52 | { | |
53 | 0 | return sb; |
54 | } | |
55 | } |