-/**@file\r
- Implementation translation among different code tyies.\r
+/** @file\r
+ Implementation of translation upon VT-UTF8.\r
\r
-Copyright (c) 2006, Intel Corporation. <BR>\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
http://opensource.org/licenses/bsd-license.php\r
\r
#include "Terminal.h"\r
\r
+/**\r
+ Translate all VT-UTF8 characters in the Raw FIFI into unicode characters,\r
+ and insert them into Unicode FIFO.\r
+\r
+ @param TerminalDevice The terminal device.\r
+\r
+**/\r
VOID\r
VTUTF8RawDataToUnicode (\r
IN TERMINAL_DEV *TerminalDevice\r
// and translate it into unicode, then push\r
// the unicode into unicode fifo, until the raw fifo is empty.\r
//\r
- while (!IsRawFiFoEmpty (TerminalDevice)) {\r
+ while (!IsRawFiFoEmpty (TerminalDevice) && !IsUnicodeFiFoFull (TerminalDevice)) {\r
\r
GetOneValidUtf8Char (TerminalDevice, &Utf8Char, &ValidBytes);\r
\r
}\r
}\r
\r
+/**\r
+ Get one valid VT-UTF8 characters set from Raw Data FIFO.\r
+\r
+ @param Utf8Device The terminal device.\r
+ @param Utf8Char Returned valid VT-UTF8 characters set.\r
+ @param ValidBytes The count of returned VT-VTF8 characters.\r
+ If ValidBytes is zero, no valid VT-UTF8 returned.\r
+\r
+**/\r
VOID\r
GetOneValidUtf8Char (\r
IN TERMINAL_DEV *Utf8Device,\r
break;\r
\r
case 2:\r
+ //\r
+ // two-byte utf8 char go on\r
+ //\r
if ((Temp & 0xc0) == 0x80) {\r
\r
Utf8Char->Utf8_2[0] = Temp;\r
break;\r
\r
case 3:\r
+ //\r
+ // three-byte utf8 char go on\r
+ //\r
if ((Temp & 0xc0) == 0x80) {\r
-\r
- Utf8Char->Utf8_3[2 - Index] = Temp;\r
- Index++;\r
- if (Index == 3) {\r
+ if (Index == 1) {\r
+ Utf8Char->Utf8_3[1] = Temp;\r
+ Index++;\r
+ } else {\r
+ Utf8Char->Utf8_3[0] = Temp;\r
FetchFlag = FALSE;\r
}\r
} else {\r
-\r
+ //\r
+ // reset *ValidBytes and Index to zero, let valid utf8 char search restart\r
+ //\r
*ValidBytes = 0;\r
Index = 0;\r
}\r
return ;\r
}\r
\r
+/**\r
+ Translate VT-UTF8 characters into one Unicode character.\r
+\r
+ UTF8 Encoding Table\r
+ Bits per Character | Unicode Character Range | Unicode Binary Encoding | UTF8 Binary Encoding\r
+ 0-7 | 0x0000 - 0x007F | 00000000 0xxxxxxx | 0xxxxxxx\r
+ 8-11 | 0x0080 - 0x07FF | 00000xxx xxxxxxxx | 110xxxxx 10xxxxxx\r
+ 12-16 | 0x0800 - 0xFFFF | xxxxxxxx xxxxxxxx | 1110xxxx 10xxxxxx 10xxxxxx\r
+\r
+\r
+ @param Utf8Char VT-UTF8 character set needs translating.\r
+ @param ValidBytes The count of valid VT-UTF8 characters.\r
+ @param UnicodeChar Returned unicode character.\r
+\r
+**/\r
VOID\r
Utf8ToUnicode (\r
IN UTF8_CHAR Utf8Char,\r
return ;\r
}\r
\r
+/**\r
+ Translate one Unicode character into VT-UTF8 characters.\r
+\r
+ UTF8 Encoding Table\r
+ Bits per Character | Unicode Character Range | Unicode Binary Encoding | UTF8 Binary Encoding\r
+ 0-7 | 0x0000 - 0x007F | 00000000 0xxxxxxx | 0xxxxxxx\r
+ 8-11 | 0x0080 - 0x07FF | 00000xxx xxxxxxxx | 110xxxxx 10xxxxxx\r
+ 12-16 | 0x0800 - 0xFFFF | xxxxxxxx xxxxxxxx | 1110xxxx 10xxxxxx 10xxxxxx\r
+\r
+\r
+ @param Unicode Unicode character need translating.\r
+ @param Utf8Char Return VT-UTF8 character set.\r
+ @param ValidBytes The count of valid VT-UTF8 characters. If\r
+ ValidBytes is zero, no valid VT-UTF8 returned.\r
+\r
+**/\r
VOID\r
UnicodeToUtf8 (\r
IN CHAR16 Unicode,\r
}\r
}\r
\r
+\r
+/**\r
+ Check if input string is valid VT-UTF8 string.\r
+\r
+ @param TerminalDevice The terminal device.\r
+ @param WString The input string.\r
+\r
+ @retval EFI_SUCCESS If all input characters are valid.\r
+\r
+**/\r
EFI_STATUS\r
VTUTF8TestString (\r
IN TERMINAL_DEV *TerminalDevice,\r