]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools: Support \x####\ in UNI files to specify non-ascii characters
authorYonghong Zhu <yonghong.zhu@intel.com>
Tue, 3 May 2016 07:44:27 +0000 (15:44 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Fri, 6 May 2016 02:06:58 +0000 (10:06 +0800)
UNI spec updated to allow using \x####\ to specify non-ascii characters,
# is a hex digit.

Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Yonghong Zhu <yonghong.zhu@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
BaseTools/Source/Python/AutoGen/UniClassObject.py

index a01381be5e6498a681d3f8a044ab4845fa1850c7..d28fd3a1ea6243db99ff28127c6aa88b83beb7f0 100644 (file)
@@ -4,7 +4,7 @@
 #\r
 # Copyright (c) 2014 Hewlett-Packard Development Company, L.P.<BR>\r
 #\r
-# Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2007 - 2016, 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
@@ -432,9 +432,19 @@ class UniFileClassObject(object):
             Line = Line.replace(u"\\'", u"'") \r
             Line = Line.replace(BACK_SLASH_PLACEHOLDER, u'\\')\r
 \r
-#           if Line.find(u'\\x'):\r
-#               hex = Line[Line.find(u'\\x') + 2 : Line.find(u'\\x') + 6]\r
-#               hex = "u'\\u" + hex + "'"\r
+            StartPos = Line.find(u'\\x')\r
+            while (StartPos != -1):\r
+                EndPos = Line.find(u'\\', StartPos + 1, StartPos + 7)\r
+                if EndPos != -1 and EndPos - StartPos == 6 :\r
+                    if re.match('[a-fA-F0-9]{4}', Line[StartPos + 2 : EndPos], re.UNICODE):\r
+                        EndStr = Line[EndPos: ]\r
+                        UniStr = ('\u' + (Line[StartPos + 2 : EndPos])).decode('unicode_escape')\r
+                        if EndStr.startswith(u'\\x') and len(EndStr) >= 7:\r
+                            if EndStr[6] == u'\\' and re.match('[a-fA-F0-9]{4}', EndStr[2 : 6], re.UNICODE):\r
+                                Line = Line[0 : StartPos] + UniStr + EndStr\r
+                        else:\r
+                            Line = Line[0 : StartPos] + UniStr + EndStr[1:]\r
+                StartPos = Line.find(u'\\x', StartPos)\r
 \r
             IncList = gIncludePattern.findall(Line)\r
             if len(IncList) == 1:\r