Class |
Line # |
Actions |
|||
---|---|---|---|---|---|
StringBufferLike | 14 | 30 | 22 |
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; | |
9 | ||
10 | /** | |
11 | * A tool that is used to make the \E, \U, \L, and \Q elements of a | |
12 | * substitution. | |
13 | */ | |
14 | public class StringBufferLike implements BasicStringBufferLike | |
15 | { | |
16 | BasicStringBufferLike sbl; | |
17 | ||
18 | 3 | public StringBufferLike(BasicStringBufferLike sbl) |
19 | { | |
20 | 3 | this.sbl = sbl; |
21 | } | |
22 | ||
23 | char mode = 'E', altMode = ' '; | |
24 | ||
25 | 3 | public StringLike toStringLike() |
26 | { | |
27 | 3 | return sbl.toStringLike(); |
28 | } | |
29 | ||
30 | 0 | public String toString() |
31 | { | |
32 | 0 | return sbl.toString(); |
33 | } | |
34 | ||
35 | 130 | public void append(char c) |
36 | { | |
37 | ||
38 | 130 | switch (mode) |
39 | { | |
40 | 0 | case 'u': |
41 | 0 | mode = altMode; |
42 | 0 | altMode = ' '; |
43 | 0 | case 'U': |
44 | 0 | sbl.append(CaseMgr.toUpperCase(c)); |
45 | 0 | break; |
46 | 0 | case 'l': |
47 | 0 | mode = altMode; |
48 | 0 | altMode = ' '; |
49 | 0 | case 'L': |
50 | 0 | sbl.append(CaseMgr.toLowerCase(c)); |
51 | 0 | break; |
52 | 0 | case 'Q': |
53 | 0 | if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') |
54 | || (c >= '0' && c <= '9')) | |
55 | { | |
56 | 0 | ; |
57 | } | |
58 | else | |
59 | { | |
60 | 0 | sbl.append('\\'); |
61 | } | |
62 | 130 | default: |
63 | 130 | sbl.append(c); |
64 | 130 | break; |
65 | } | |
66 | } | |
67 | ||
68 | 3 | public void append(String s) |
69 | { | |
70 | 7 | for (int i = 0; i < s.length(); i++) |
71 | { | |
72 | 4 | append(s.charAt(i)); |
73 | } | |
74 | } | |
75 | ||
76 | 0 | public void setMode(char c) |
77 | { | |
78 | 0 | if (c == 'u' || c == 'l') |
79 | { | |
80 | 0 | if (altMode == ' ') |
81 | { | |
82 | 0 | altMode = mode; |
83 | } | |
84 | } | |
85 | 0 | mode = c; |
86 | } | |
87 | ||
88 | 0 | public Object unwrap() |
89 | { | |
90 | 0 | return sbl.unwrap(); |
91 | } | |
92 | } |