This allows .uni input files to be encoded with UTF-8. Today, we only
support UTF-16 encoding.

The strings are still converted to UCS-2 data for use in EDK II
modules. (This is the only unicode character format supported by UEFI
and EDK II.)

Although UTF-8 would allow any UCS-4 character to be present in the
source file, we restrict the entire file to the UCS-2 range.
(Including comments.) This allows the files to be converted to UTF-16
if needed.

v2:
 * Drop .utf8 extension. Use .uni file for UTF-8 data (mdkinney)
 * Merge in 'BaseTools/UniClassObject: Verify string data is 16-bit'
   commit

v3:
 * Restrict the entire file's characters (including comments) to the
   UCS-2 range in addition to string data. (mdkinney)

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jordan Justen <jordan.l.jus...@intel.com>
Cc: Yingke D Liu <yingke.d....@intel.com>
Cc: Michael D Kinney <michael.d.kin...@intel.com>
---
 BaseTools/Source/Python/AutoGen/UniClassObject.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/UniClassObject.py 
b/BaseTools/Source/Python/AutoGen/UniClassObject.py
index 66fdbf0..6ccaef0 100644
--- a/BaseTools/Source/Python/AutoGen/UniClassObject.py
+++ b/BaseTools/Source/Python/AutoGen/UniClassObject.py
@@ -293,9 +293,12 @@ class UniFileClassObject(object):
             EdkLogger.Error("build", FILE_OPEN_FAILURE, ExtraData=File)
 
         #
-        # We currently only support UTF-16
+        # Detect Byte Order Mark at beginning of file.  Default to UTF-8
         #
-        Encoding = 'utf-16'
+        Encoding = 'utf-8'
+        if (FileIn.startswith(codecs.BOM_UTF16_BE) or
+            FileIn.startswith(codecs.BOM_UTF16_LE)):
+            Encoding = 'utf-16'
 
         self.VerifyUcs2Data(FileIn, FileName, Encoding)
 
-- 
2.1.4


------------------------------------------------------------------------------
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to