]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Common/String.py
BaseTools: Fix flexible PCD single quote and double quote bugs
[mirror_edk2.git] / BaseTools / Source / Python / Common / String.py
index 4a8c03e88e28297e7c158fc27a420f0851e22d62..5e50beff5cc39539a0eab1684d0281b0533b9918 100644 (file)
@@ -45,26 +45,32 @@ def GetSplitValueList(String, SplitTag=DataType.TAB_VALUE_SPLIT, MaxSplit= -1):
     ValueList = []\r
     Last = 0\r
     Escaped = False\r
-    InString = False\r
+    InSingleQuoteString = False\r
+    InDoubleQuoteString = False\r
     InParenthesis = 0\r
     for Index in range(0, len(String)):\r
         Char = String[Index]\r
 \r
         if not Escaped:\r
             # Found a splitter not in a string, split it\r
-            if not InString and InParenthesis == 0 and Char == SplitTag:\r
+            if (not InSingleQuoteString or not InDoubleQuoteString) and InParenthesis == 0 and Char == SplitTag:\r
                 ValueList.append(String[Last:Index].strip())\r
                 Last = Index + 1\r
                 if MaxSplit > 0 and len(ValueList) >= MaxSplit:\r
                     break\r
 \r
-            if Char == '\\' and InString:\r
+            if Char == '\\' and (InSingleQuoteString or InDoubleQuoteString):\r
                 Escaped = True\r
-            elif Char == '"':\r
-                if not InString:\r
-                    InString = True\r
+            elif Char == '"' and not InSingleQuoteString:\r
+                if not InDoubleQuoteString:\r
+                    InDoubleQuoteString = True\r
                 else:\r
-                    InString = False\r
+                    InDoubleQuoteString = False\r
+            elif Char == "'" and not InDoubleQuoteString:\r
+                if not InSingleQuoteString:\r
+                    InSingleQuoteString = True\r
+                else:\r
+                    InSingleQuoteString = False\r
             elif Char == '(':\r
                 InParenthesis = InParenthesis + 1\r
             elif Char == ')':\r
@@ -345,14 +351,17 @@ def CleanString(Line, CommentCharacter=DataType.TAB_COMMENT_SPLIT, AllowCppStyle
     #\r
     # remove comments, but we should escape comment character in string\r
     #\r
-    InString = False\r
+    InDoubleQuoteString = False\r
+    InSingleQuoteString = False\r
     CommentInString = False\r
     for Index in range(0, len(Line)):\r
-        if Line[Index] == '"':\r
-            InString = not InString\r
-        elif Line[Index] == CommentCharacter and InString :\r
+        if Line[Index] == '"' and not InSingleQuoteString:\r
+            InDoubleQuoteString = not InDoubleQuoteString\r
+        elif Line[Index] == "'" and not InDoubleQuoteString:\r
+            InSingleQuoteString = not InSingleQuoteString\r
+        elif Line[Index] == CommentCharacter and (InSingleQuoteString or InDoubleQuoteString):\r
             CommentInString = True\r
-        elif Line[Index] == CommentCharacter and not InString :\r
+        elif Line[Index] == CommentCharacter and not (InSingleQuoteString or InDoubleQuoteString):\r
             Line = Line[0: Index]\r
             break\r
 \r
@@ -402,15 +411,18 @@ def CleanString2(Line, CommentCharacter=DataType.TAB_COMMENT_SPLIT, AllowCppStyl
     #\r
     # separate comments and statements, but we should escape comment character in string\r
     #\r
-    InString = False\r
+    InDoubleQuoteString = False\r
+    InSingleQuoteString = False\r
     CommentInString = False\r
     Comment = ''\r
     for Index in range(0, len(Line)):\r
-        if Line[Index] == '"':\r
-            InString = not InString\r
-        elif Line[Index] == CommentCharacter and InString:\r
+        if Line[Index] == '"' and not InSingleQuoteString:\r
+            InDoubleQuoteString = not InDoubleQuoteString\r
+        elif Line[Index] == "'" and not InDoubleQuoteString:\r
+            InSingleQuoteString = not InSingleQuoteString\r
+        elif Line[Index] == CommentCharacter and (InDoubleQuoteString or InSingleQuoteString):\r
             CommentInString = True\r
-        elif Line[Index] == CommentCharacter and not InString:\r
+        elif Line[Index] == CommentCharacter and not (InDoubleQuoteString or InSingleQuoteString):\r
             Comment = Line[Index:].strip()\r
             Line = Line[0:Index].strip()\r
             break\r