Mercurial > projects > dwt-addons
comparison dwtx/jface/internal/text/html/SubstitutionTextReader.d @ 162:1a5b8f8129df
...
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 08 Sep 2008 00:51:37 +0200 |
parents | 7926b636c282 |
children |
comparison
equal
deleted
inserted
replaced
161:f8d52b926852 | 162:1a5b8f8129df |
---|---|
19 import dwtx.jface.internal.text.html.BrowserInput; // packageimport | 19 import dwtx.jface.internal.text.html.BrowserInput; // packageimport |
20 import dwtx.jface.internal.text.html.SingleCharReader; // packageimport | 20 import dwtx.jface.internal.text.html.SingleCharReader; // packageimport |
21 import dwtx.jface.internal.text.html.BrowserInformationControlInput; // packageimport | 21 import dwtx.jface.internal.text.html.BrowserInformationControlInput; // packageimport |
22 import dwtx.jface.internal.text.html.HTMLMessages; // packageimport | 22 import dwtx.jface.internal.text.html.HTMLMessages; // packageimport |
23 | 23 |
24 | |
25 import dwt.dwthelper.utils; | 24 import dwt.dwthelper.utils; |
25 import tango.core.Exception; | |
26 | 26 |
27 /** | 27 /** |
28 * Reads the text contents from a reader and computes for each character | 28 * Reads the text contents from a reader and computes for each character |
29 * a potential substitution. The substitution may eat more characters than | 29 * a potential substitution. The substitution may eat more characters than |
30 * only the one passed into the computation routine. | 30 * only the one passed into the computation routine. |
90 * @throws IOException in case reading the character fails | 90 * @throws IOException in case reading the character fails |
91 */ | 91 */ |
92 protected int nextChar() { | 92 protected int nextChar() { |
93 fReadFromBuffer= (fBuffer.length() > 0); | 93 fReadFromBuffer= (fBuffer.length() > 0); |
94 if (fReadFromBuffer) { | 94 if (fReadFromBuffer) { |
95 char ch= fBuffer.charAt(fIndex++); | 95 char ch= fBuffer.slice().charAt(fIndex++); |
96 if (fIndex >= fBuffer.length()) { | 96 if (fIndex >= fBuffer.length()) { |
97 fBuffer.setLength(0); | 97 fBuffer.truncate(0); |
98 fIndex= 0; | 98 fIndex= 0; |
99 } | 99 } |
100 return ch; | 100 return ch; |
101 } | 101 } |
102 | 102 |
103 int ch= fCharAfterWhiteSpace; | 103 int ch= fCharAfterWhiteSpace; |
104 if (ch is -1) { | 104 if (ch is -1) { |
105 ch= fReader.read(); | 105 ch= fReader.read(); |
106 } | 106 } |
107 if (fSkipWhiteSpace && Character.isWhitespace(cast(wchar)ch)) { | 107 if (fSkipWhiteSpace && Character.isWhitespace(cast(char)ch)) { |
108 do { | 108 do { |
109 ch= fReader.read(); | 109 ch= fReader.read(); |
110 } while (Character.isWhitespace(cast(wchar)ch)); | 110 } while (Character.isWhitespace(cast(char)ch)); |
111 if (ch !is -1) { | 111 if (ch !is -1) { |
112 fCharAfterWhiteSpace= ch; | 112 fCharAfterWhiteSpace= ch; |
113 return ' '; | 113 return ' '; |
114 } | 114 } |
115 } else { | 115 } else { |
116 fCharAfterWhiteSpace= -1; | 116 fCharAfterWhiteSpace= -1; |
117 } | 117 } |
118 return ch; | 118 return ch; |
119 } | 119 } |
120 | 120 |
121 /// DWT | |
122 protected int nextDChar() { | |
123 char[4] buf = void; | |
124 int ch1 = nextChar(); | |
125 if( ch1 is -1 ) return -1; | |
126 buf[0] = cast(char)ch1; | |
127 if(( ch1 & 0x80 ) is 0x00 ){ | |
128 return ch1; | |
129 } | |
130 else if(( ch1 & 0xE0 ) is 0xC0 ){ | |
131 int ch2 = nextChar(); | |
132 if( ch2 is -1 ) throw new UnicodeException(__FILE__,__LINE__); | |
133 buf[1] = cast(char)ch2; | |
134 } | |
135 else if(( ch1 & 0xF0 ) is 0xE0 ){ | |
136 int ch2 = nextChar(); | |
137 if( ch1 is -1 ) throw new UnicodeException(__FILE__,__LINE__); | |
138 buf[1] = cast(char)ch2; | |
139 int ch3 = nextChar(); | |
140 if( ch3 is -1 ) throw new UnicodeException(__FILE__,__LINE__); | |
141 buf[2] = cast(char)ch3; | |
142 } | |
143 else if(( ch1 & 0xF8 ) is 0xF0 ){ | |
144 int ch2 = nextChar(); | |
145 if( ch1 is -1 ) throw new UnicodeException(__FILE__,__LINE__); | |
146 buf[1] = cast(char)ch2; | |
147 int ch3 = nextChar(); | |
148 if( ch3 is -1 ) throw new UnicodeException(__FILE__,__LINE__); | |
149 buf[2] = cast(char)ch3; | |
150 int ch4 = nextChar(); | |
151 if( ch4 is -1 ) throw new UnicodeException(__FILE__,__LINE__); | |
152 buf[3] = cast(char)ch4; | |
153 } | |
154 else { | |
155 throw new UnicodeException(__FILE__,__LINE__); | |
156 } | |
157 uint ate; | |
158 return tango.text.convert.Utf.decode( buf, ate ); | |
159 } | |
160 | |
121 /** | 161 /** |
122 * @see Reader#read() | 162 * @see Reader#read() |
123 */ | 163 */ |
124 public int read() { | 164 public int read() { |
125 int c; | 165 int c; |
128 c= nextChar(); | 168 c= nextChar(); |
129 while (!fReadFromBuffer) { | 169 while (!fReadFromBuffer) { |
130 String s= computeSubstitution(c); | 170 String s= computeSubstitution(c); |
131 if (s is null) | 171 if (s is null) |
132 break; | 172 break; |
133 if (s.length() > 0) | 173 if (s.length() > 0){ |
134 fBuffer.insert(0, s); | 174 fBuffer.select(0, 0); |
175 fBuffer.replace(s); | |
176 } | |
135 c= nextChar(); | 177 c= nextChar(); |
136 } | 178 } |
137 | 179 |
138 } while (fSkipWhiteSpace && fWasWhiteSpace && (c is ' ')); | 180 } while (fSkipWhiteSpace && fWasWhiteSpace && (c is ' ')); |
139 fWasWhiteSpace= (c is ' ' || c is '\r' || c is '\n'); | 181 fWasWhiteSpace= (c is ' ' || c is '\r' || c is '\n'); |
159 */ | 201 */ |
160 public void reset() { | 202 public void reset() { |
161 fReader.reset(); | 203 fReader.reset(); |
162 fWasWhiteSpace= true; | 204 fWasWhiteSpace= true; |
163 fCharAfterWhiteSpace= -1; | 205 fCharAfterWhiteSpace= -1; |
164 fBuffer.setLength(0); | 206 fBuffer.truncate(0); |
165 fIndex= 0; | 207 fIndex= 0; |
166 } | 208 } |
167 | 209 |
168 protected final void setSkipWhitespace(bool state) { | 210 protected final void setSkipWhitespace(bool state) { |
169 fSkipWhiteSpace= state; | 211 fSkipWhiteSpace= state; |