#include <console.h>
Collaboration diagram for ConsoleStreamBuf:

Public Types | |
| enum | UTF8DecodeState { UTF8DecodeStart = 0, UTF8DecodeMultibyte = 1 } |
Public Member Functions | |
| ConsoleStreamBuf () | |
| int | overflow (int c=EOF) |
| void | setConsole (Console *) |
Private Attributes | |
| Console * | console |
| wchar_t | decodedChar |
| unsigned int | decodeShift |
| UTF8DecodeState | decodeState |
|
|
Definition at line 30 of file console.h. 00031 {
00032 UTF8DecodeStart = 0,
00033 UTF8DecodeMultibyte = 1,
00034 };
|
|
|
Definition at line 25 of file console.h. References console. 00025 : console(NULL) { setbuf(0, 0); };
|
|
|
Definition at line 238 of file console.cpp. References console, decodedChar, decodeShift, decodeState, Console::print(), UTF8DecodeMultibyte, and UTF8DecodeStart. 00239 {
00240 if (console != NULL)
00241 {
00242 switch (decodeState)
00243 {
00244 case UTF8DecodeStart:
00245 if (c < 0x80)
00246 {
00247 // Just a normal 7-bit character
00248 console->print((char) c);
00249 }
00250 else
00251 {
00252 unsigned int count;
00253
00254 if ((c & 0xe0) == 0xc0)
00255 count = 2;
00256 else if ((c & 0xf0) == 0xe0)
00257 count = 3;
00258 else if ((c & 0xf8) == 0xf0)
00259 count = 4;
00260 else if ((c & 0xfc) == 0xf8)
00261 count = 5;
00262 else if ((c & 0xfe) == 0xfc)
00263 count = 6;
00264 else
00265 count = 1; // Invalid byte
00266
00267 if (count > 1)
00268 {
00269 unsigned int mask = (1 << (7 - count)) - 1;
00270 decodeShift = (count - 1) * 6;
00271 decodedChar = (c & mask) << decodeShift;
00272 decodeState = UTF8DecodeMultibyte;
00273 }
00274 else
00275 {
00276 // If the character isn't valid multibyte sequence head,
00277 // silently skip it by leaving the decoder state alone.
00278 }
00279 }
00280 break;
00281
00282 case UTF8DecodeMultibyte:
00283 if ((c & 0xc0) == 0x80)
00284 {
00285 // We have a valid non-head byte in the sequence
00286 decodeShift -= 6;
00287 decodedChar |= (c & 0x3f) << decodeShift;
00288 if (decodeShift == 0)
00289 {
00290 console->print(decodedChar);
00291 decodeState = UTF8DecodeStart;
00292 }
00293 }
00294 else
00295 {
00296 // Bad byte in UTF-8 encoded sequence; we'll silently ignore
00297 // it and reset the state of the UTF-8 decoder.
00298 decodeState = UTF8DecodeStart;
00299 }
00300 break;
00301 }
00302 }
00303
00304 return c;
00305 }
|
|
|
Definition at line 233 of file console.cpp. References console. Referenced by Console::Console(). 00234 {
00235 console = c;
00236 }
|
|
|
Definition at line 37 of file console.h. Referenced by ConsoleStreamBuf(), overflow(), and setConsole(). |
|
|
Definition at line 39 of file console.h. Referenced by overflow(). |
|
|
Definition at line 40 of file console.h. Referenced by overflow(). |
|
|
Definition at line 38 of file console.h. Referenced by overflow(). |
1.4.1