]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/UPT/Library/UniClassObject.py
BaseTools: Various typo
[mirror_edk2.git] / BaseTools / Source / Python / UPT / Library / UniClassObject.py
index 549f278b05c9a8bcbc7921aae56e14961586e04f..d575c6b1f87562a4c9346db5017145dd5527abd8 100644 (file)
@@ -14,6 +14,7 @@
 """\r
 Collect all defined strings in multiple uni files\r
 """\r
+from __future__ import print_function\r
 \r
 ##\r
 # Import Modules\r
@@ -118,21 +119,23 @@ def UniToHexList(Uni):
 # @retval NewUni:  The converted unicode string\r
 #\r
 def ConvertSpecialUnicodes(Uni):\r
-    NewUni = Uni\r
+    OldUni = NewUni = Uni\r
     NewUni = NewUni.replace(u'\u00A9', '(c)')\r
     NewUni = NewUni.replace(u'\u00AE', '(r)')\r
     NewUni = NewUni.replace(u'\u2122', '(tm)')\r
+    if OldUni == NewUni:\r
+        NewUni = OldUni\r
     return NewUni\r
 \r
 ## GetLanguageCode1766\r
 #\r
 # Check the language code read from .UNI file and convert RFC 4646 codes to RFC 1766 codes\r
-# RFC 1766 language codes supported in compatiblity mode\r
+# RFC 1766 language codes supported in compatibility mode\r
 # RFC 4646 language codes supported in native mode\r
 #\r
 # @param LangName:   Language codes read from .UNI file\r
 #\r
-# @retval LangName:  Valid lanugage code in RFC 1766 format or None\r
+# @retval LangName:  Valid language code in RFC 1766 format or None\r
 #\r
 def GetLanguageCode1766(LangName, File=None):\r
     return LangName\r
@@ -174,7 +177,7 @@ def GetLanguageCode1766(LangName, File=None):
 ## GetLanguageCode\r
 #\r
 # Check the language code read from .UNI file and convert RFC 1766 codes to RFC 4646 codes if appropriate\r
-# RFC 1766 language codes supported in compatiblity mode\r
+# RFC 1766 language codes supported in compatibility mode\r
 # RFC 4646 language codes supported in native mode\r
 #\r
 # @param LangName:   Language codes read from .UNI file\r
@@ -218,13 +221,13 @@ def GetLanguageCode(LangName, IsCompatibleMode, File):
 \r
 ## FormatUniEntry\r
 #\r
-# Formated the entry in Uni file.\r
+# Formatted the entry in Uni file.\r
 #\r
 # @param StrTokenName    StrTokenName.\r
 # @param TokenValueList  A list need to be processed.\r
 # @param ContainerFile   ContainerFile.\r
 #\r
-# @return formated entry\r
+# @return formatted entry\r
 def FormatUniEntry(StrTokenName, TokenValueList, ContainerFile):\r
     SubContent = ''\r
     PreFormatLength = 40\r
@@ -246,9 +249,9 @@ def FormatUniEntry(StrTokenName, TokenValueList, ContainerFile):
         for SubValue in ValueList:\r
             if SubValue.strip():\r
                 SubValueContent += \\r
-                ' ' * (PreFormatLength + len('#language en-US ')) + '\"%s\\n\"' % SubValue.strip() + '\n'\r
+                ' ' * (PreFormatLength + len('#language en-US ')) + '\"%s\\n\"' % SubValue.strip() + '\r\n'\r
         SubValueContent = SubValueContent[(PreFormatLength + len('#language en-US ')):SubValueContent.rfind('\\n')] \\r
-        + '\"' + '\n'\r
+        + '\"' + '\r\n'\r
         SubContent += ' '*PreFormatLength + '#language %-5s ' % Lang + SubValueContent\r
     if SubContent:\r
         SubContent = StrTokenName + ' '*(PreFormatLength - len(StrTokenName)) + SubContent[PreFormatLength:]\r
@@ -290,7 +293,7 @@ class StringDefClassObject(object):
     def UpdateValue(self, Value = None):\r
         if Value is not None:\r
             if self.StringValue:\r
-                self.StringValue = self.StringValue + '\n' + Value\r
+                self.StringValue = self.StringValue + '\r\n' + Value\r
             else:\r
                 self.StringValue = Value\r
             self.StringValueByteList = UniToHexList(self.StringValue)\r
@@ -464,7 +467,7 @@ class UniFileClassObject(object):
             if not Line.startswith(DT.TAB_COMMENT_EDK1_SPLIT) and HeaderStart and not HeaderEnd:\r
                 HeaderEnd = True\r
             if Line.startswith(DT.TAB_COMMENT_EDK1_SPLIT) and HeaderStart and not HeaderEnd and FirstGenHeader:\r
-                self.UniFileHeader += Line + '\n'\r
+                self.UniFileHeader += Line + '\r\n'\r
                 continue\r
 \r
         #\r
@@ -475,8 +478,8 @@ class UniFileClassObject(object):
         MultiLineFeedExits = False\r
         #\r
         # 0: initial value\r
-        # 1: signle String entry exist\r
-        # 2: line feed exist under the some signle String entry\r
+        # 1: single String entry exist\r
+        # 2: line feed exist under the some single String entry\r
         #\r
         StringEntryExistsFlag = 0\r
         for Line in FileIn:\r
@@ -494,7 +497,7 @@ class UniFileClassObject(object):
                     StringEntryExistsFlag = 2\r
                 #\r
                 # If the '#string' line and the '#language' line are not in the same line,\r
-                # there should be only one line feed character betwwen them\r
+                # there should be only one line feed character between them\r
                 #\r
                 if MultiLineFeedExits:\r
                     EdkLogger.Error("Unicode File Parser", ToolError.FORMAT_INVALID, ExtraData=File.Path)\r
@@ -502,7 +505,7 @@ class UniFileClassObject(object):
 \r
             MultiLineFeedExits = False\r
             #\r
-            # Process comment embeded in string define lines\r
+            # Process comment embedded in string define lines\r
             #\r
             FindFlag = Line.find(u'//')\r
             if FindFlag != -1 and Line.find(u'//') < Line.find(u'"'):\r
@@ -510,11 +513,11 @@ class UniFileClassObject(object):
                 if FileIn[LineCount].strip().startswith('#language'):\r
                     Line = Line + FileIn[LineCount]\r
                     FileIn[LineCount-1] = Line\r
-                    FileIn[LineCount] = '\n'\r
+                    FileIn[LineCount] = '\r\n'\r
                     LineCount -= 1\r
                     for Index in range (LineCount + 1, len (FileIn) - 1):\r
                         if (Index == len(FileIn) -1):\r
-                            FileIn[Index] = '\n'\r
+                            FileIn[Index] = '\r\n'\r
                         else:\r
                             FileIn[Index] = FileIn[Index + 1]\r
                     continue\r
@@ -565,6 +568,22 @@ class UniFileClassObject(object):
             if Line.startswith(u'#language') and len(Line.split()) == 2:\r
                 MultiLineFeedExits = True\r
 \r
+            #\r
+            # Check the situation that there only has one '"' for the language entry\r
+            #\r
+            if Line.startswith(u'#string') and Line.find(u'#language') > 0 and Line.count(u'"') == 1:\r
+                EdkLogger.Error("Unicode File Parser", ToolError.FORMAT_INVALID,\r
+                                ExtraData='''The line %s misses '"' at the end of it in file %s'''\r
+                                % (LineCount, File.Path))\r
+\r
+            #\r
+            # Check the situation that there has more than 2 '"' for the language entry\r
+            #\r
+            if Line.startswith(u'#string') and Line.find(u'#language') > 0 and Line.replace(u'\\"', '').count(u'"') > 2:\r
+                EdkLogger.Error("Unicode File Parser", ToolError.FORMAT_INVALID,\r
+                                ExtraData='''The line %s has more than 2 '"' for language entry in file %s'''\r
+                                % (LineCount, File.Path))\r
+\r
             #\r
             # Between two String entry, can not contain line feed\r
             #\r
@@ -726,6 +745,13 @@ class UniFileClassObject(object):
                 else:\r
                     EdkLogger.Error("Unicode File Parser", ToolError.FORMAT_INVALID, ExtraData=File.Path)\r
             elif Line.startswith(u'"'):\r
+                #\r
+                # Check the situation that there has more than 2 '"' for the language entry\r
+                #\r
+                if Line.replace(u'\\"', '').count(u'"') > 2:\r
+                    EdkLogger.Error("Unicode File Parser", ToolError.FORMAT_INVALID,\r
+                                    ExtraData='''The line %s has more than 2 '"' for language entry in file %s'''\r
+                                    % (LineCount, File.Path))\r
                 if u'#string' in Line  or u'#language' in Line:\r
                     EdkLogger.Error("Unicode File Parser", ToolError.FORMAT_INVALID, ExtraData=File.Path)\r
                 NewLines.append(Line)\r
@@ -745,7 +771,7 @@ class UniFileClassObject(object):
 \r
         #\r
         # Check Abstract, Description, BinaryAbstract and BinaryDescription order,\r
-        # should be Abstract, Description, BinaryAbstract, BinaryDesctiption\r
+        # should be Abstract, Description, BinaryAbstract, BinaryDescription\r
         AbstractPosition = -1\r
         DescriptionPosition = -1\r
         BinaryAbstractPosition = -1\r
@@ -866,12 +892,12 @@ class UniFileClassObject(object):
                                 Value = Value + Lines[IndexJ].strip()[1:-1]\r
                             CombineToken = False\r
                         else:\r
-                            Value = Value + Lines[IndexJ].strip()[1:-1] + '\n'\r
+                            Value = Value + Lines[IndexJ].strip()[1:-1] + '\r\n'\r
                     else:\r
                         IndexI = IndexJ\r
                         break\r
-                if Value.endswith('\n'):\r
-                    Value = Value[: Value.rfind('\n')]\r
+                if Value.endswith('\r\n'):\r
+                    Value = Value[: Value.rfind('\r\n')]\r
                 Language = GetLanguageCode(Language, self.IsCompatibleMode, self.File)\r
                 self.AddStringToList(Name, Language, Value)\r
                 continue\r