#include <overlay.h>
Collaboration diagram for OverlayStreamBuf:

Public Types | |
| enum | UTF8DecodeState { UTF8DecodeStart = 0, UTF8DecodeMultibyte = 1 } |
Public Member Functions | |
| int | overflow (int c=EOF) |
| OverlayStreamBuf () | |
| void | setOverlay (Overlay *) |
Private Attributes | |
| wchar_t | decodedChar |
| unsigned int | decodeShift |
| UTF8DecodeState | decodeState |
| Overlay * | overlay |
|
|
Definition at line 32 of file overlay.h. 00033 {
00034 UTF8DecodeStart = 0,
00035 UTF8DecodeMultibyte = 1,
00036 };
|
|
|
Definition at line 216 of file overlay.cpp. 00216 : 00217 overlay(NULL), 00218 decodeState(UTF8DecodeStart) 00219 { 00220 setbuf(0, 0); 00221 };
|
|
|
Definition at line 230 of file overlay.cpp. References decodedChar, decodeShift, decodeState, overlay, Overlay::print(), UTF8DecodeMultibyte, and UTF8DecodeStart. 00231 {
00232 if (overlay != NULL)
00233 {
00234 switch (decodeState)
00235 {
00236 case UTF8DecodeStart:
00237 if (c < 0x80)
00238 {
00239 // Just a normal 7-bit character
00240 overlay->print((char) c);
00241 }
00242 else
00243 {
00244 unsigned int count;
00245
00246 if ((c & 0xe0) == 0xc0)
00247 count = 2;
00248 else if ((c & 0xf0) == 0xe0)
00249 count = 3;
00250 else if ((c & 0xf8) == 0xf0)
00251 count = 4;
00252 else if ((c & 0xfc) == 0xf8)
00253 count = 5;
00254 else if ((c & 0xfe) == 0xfc)
00255 count = 6;
00256 else
00257 count = 1; // Invalid byte
00258
00259 if (count > 1)
00260 {
00261 unsigned int mask = (1 << (7 - count)) - 1;
00262 decodeShift = (count - 1) * 6;
00263 decodedChar = (c & mask) << decodeShift;
00264 decodeState = UTF8DecodeMultibyte;
00265 }
00266 else
00267 {
00268 // If the character isn't valid multibyte sequence head,
00269 // silently skip it by leaving the decoder state alone.
00270 }
00271 }
00272 break;
00273
00274 case UTF8DecodeMultibyte:
00275 if ((c & 0xc0) == 0x80)
00276 {
00277 // We have a valid non-head byte in the sequence
00278 decodeShift -= 6;
00279 decodedChar |= (c & 0x3f) << decodeShift;
00280 if (decodeShift == 0)
00281 {
00282 overlay->print(decodedChar);
00283 decodeState = UTF8DecodeStart;
00284 }
00285 }
00286 else
00287 {
00288 // Bad byte in UTF-8 encoded sequence; we'll silently ignore
00289 // it and reset the state of the UTF-8 decoder.
00290 decodeState = UTF8DecodeStart;
00291 }
00292 break;
00293 }
00294 }
00295
00296 return c;
00297 }
|
|
|
Definition at line 224 of file overlay.cpp. References overlay. Referenced by Overlay::Overlay(). 00225 {
00226 overlay = o;
00227 }
|
|
|
Definition at line 42 of file overlay.h. Referenced by overflow(). |
|
|
Definition at line 43 of file overlay.h. Referenced by overflow(). |
|
|
Definition at line 41 of file overlay.h. Referenced by overflow(). |
|
|
Definition at line 39 of file overlay.h. Referenced by overflow(), and setOverlay(). |
1.4.1