]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/UPT/Library/StringUtils.py
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / BaseTools / Source / Python / UPT / Library / StringUtils.py
index c2148a44fb078b35c37c79c93f98c37d7b4ca001..fbc5177caf5ab6b63bd07428ae88f2adfed5dbdc 100644 (file)
@@ -4,13 +4,7 @@
 #\r
 # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>\r
 #\r
-# This program and the accompanying materials are licensed and made available\r
-# under the terms and conditions of the BSD License which accompanies this\r
-# distribution. The full text of the license may be found at\r
-# http://opensource.org/licenses/bsd-license.php\r
-#\r
-# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
 #\r
 '''\r
 StringUtils\r
@@ -20,7 +14,6 @@ StringUtils
 #\r
 import re\r
 import os.path\r
-from string import strip\r
 import Logger.Log as Logger\r
 import Library.DataType as DataType\r
 from Logger.ToolError import FORMAT_INVALID\r
@@ -34,7 +27,7 @@ gMACRO_PATTERN = re.compile("\$\(([_A-Z][_A-Z0-9]*)\)", re.UNICODE)
 \r
 ## GetSplitValueList\r
 #\r
-# Get a value list from a string with multiple values splited with SplitTag\r
+# Get a value list from a string with multiple values split with SplitTag\r
 # The default SplitTag is DataType.TAB_VALUE_SPLIT\r
 # 'AAA|BBB|CCC' -> ['AAA', 'BBB', 'CCC']\r
 #\r
@@ -44,7 +37,7 @@ gMACRO_PATTERN = re.compile("\$\(([_A-Z][_A-Z0-9]*)\)", re.UNICODE)
 #\r
 #\r
 def GetSplitValueList(String, SplitTag=DataType.TAB_VALUE_SPLIT, MaxSplit= -1):\r
-    return map(lambda l: l.strip(), String.split(SplitTag, MaxSplit))\r
+    return list(map(lambda l: l.strip(), String.split(SplitTag, MaxSplit)))\r
 \r
 ## MergeArches\r
 #\r
@@ -68,7 +61,7 @@ def MergeArches(Dict, Key, Arch):
 # Return False if invalid format\r
 #\r
 # @param String:   String with DEFINE statement\r
-# @param Arch:     Supportted Arch\r
+# @param Arch:     Supported Arch\r
 # @param Defines:  DEFINE statement to be parsed\r
 #\r
 def GenDefines(String, Arch, Defines):\r
@@ -237,7 +230,7 @@ def ReplaceMacro(String, MacroDefinitions=None, SelfReplacement=False, Line=None
 ## NormPath\r
 #\r
 # Create a normal path\r
-# And replace DFEINE in the path\r
+# And replace DEFINE in the path\r
 #\r
 # @param Path:     The input value for Path to be converted\r
 # @param Defines:  A set for DEFINE statement\r
@@ -435,7 +428,7 @@ def GetSingleValueOfKeyFromLines(Lines, Dictionary, CommentCharacter, KeySplitCh
                 #\r
                 LineList[1] = CleanString(LineList[1], CommentCharacter)\r
                 if ValueSplitFlag:\r
-                    Value = map(strip, LineList[1].split(ValueSplitCharacter))\r
+                    Value = list(map(lambda x: x.strip(), LineList[1].split(ValueSplitCharacter)))\r
                 else:\r
                     Value = CleanString(LineList[1], CommentCharacter).splitlines()\r
 \r
@@ -614,9 +607,9 @@ def WorkspaceFile(WorkspaceDir, Filename):
 \r
 ## Split string\r
 #\r
-# Revmove '"' which startswith and endswith string\r
+# Remove '"' which startswith and endswith string\r
 #\r
-# @param String:  The string need to be splited\r
+# @param String:  The string need to be split\r
 #\r
 def SplitString(String):\r
     if String.startswith('\"'):\r
@@ -632,7 +625,7 @@ def SplitString(String):
 # @param StringList:  A list for strings to be converted\r
 #\r
 def ConvertToSqlString(StringList):\r
-    return map(lambda s: s.replace("'", "''"), StringList)\r
+    return list(map(lambda s: s.replace("'", "''"), StringList))\r
 \r
 ## Convert To Sql String\r
 #\r
@@ -735,7 +728,7 @@ def IsHexDigit(Str):
                 return False\r
     return False\r
 \r
-## Check if the string is HexDgit and its interger value within limit of UINT32\r
+## Check if the string is HexDgit and its integer value within limit of UINT32\r
 #\r
 # Return true if all characters in the string are digits and there is at\r
 # least one character\r
@@ -870,7 +863,7 @@ def ConvertNOTEQToNE(Expr):
 ## SplitPcdEntry\r
 #\r
 # Split an PCD entry string to Token.CName and PCD value and FFE.\r
-# NOTE: PCD Value and FFE can contain "|" in it's expression. And in INF specification, have below rule.\r
+# NOTE: PCD Value and FFE can contain "|" in its expression. And in INF specification, have below rule.\r
 # When using the characters "|" or "||" in an expression, the expression must be encapsulated in\r
 # open "(" and close ")" parenthesis.\r
 #\r
@@ -938,23 +931,24 @@ def SplitPcdEntry(String):
 def IsMatchArch(Arch1, Arch2):\r
     if 'COMMON' in Arch1 or 'COMMON' in Arch2:\r
         return True\r
-    if isinstance(Arch1, basestring) and isinstance(Arch2, basestring):\r
-        if Arch1 == Arch2:\r
-            return True\r
-\r
-    if isinstance(Arch1, basestring) and isinstance(Arch2, list):\r
-        return Arch1 in Arch2\r
+    try:\r
+        if isinstance(Arch1, list) and isinstance(Arch2, list):\r
+            for Item1 in Arch1:\r
+                for Item2 in Arch2:\r
+                    if Item1 == Item2:\r
+                        return True\r
 \r
-    if isinstance(Arch2, basestring) and isinstance(Arch1, list):\r
-        return Arch2 in Arch1\r
+        elif isinstance(Arch1, list):\r
+            return Arch2 in Arch1\r
 \r
-    if isinstance(Arch1, list) and isinstance(Arch2, list):\r
-        for Item1 in Arch1:\r
-            for Item2 in Arch2:\r
-                if Item1 == Item2:\r
-                    return True\r
+        elif isinstance(Arch2, list):\r
+            return Arch1 in Arch2\r
 \r
-    return False\r
+        else:\r
+            if Arch1 == Arch2:\r
+                return True\r
+    except:\r
+        return False\r
 \r
 # Search all files in FilePath to find the FileName with the largest index\r
 # Return the FileName with index +1 under the FilePath\r