]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Common/String.py
Sync BaseTool trunk (version r2599) into EDKII BaseTools.
[mirror_edk2.git] / BaseTools / Source / Python / Common / String.py
index 068a63d1c124cda1e67dbc8270244c3b0cb60bac..c282326677f6f49d6b58fc5fb0adc424d8dc6901 100644 (file)
@@ -368,7 +368,7 @@ def CleanString(Line, CommentCharacter=DataType.TAB_COMMENT_SPLIT, AllowCppStyle
 \r
 ## CleanString2\r
 #\r
-# Split comments in a string\r
+# Split statement with comments in a string\r
 # Remove spaces\r
 #\r
 # @param Line:              The string to be cleaned\r
@@ -387,15 +387,21 @@ def CleanString2(Line, CommentCharacter=DataType.TAB_COMMENT_SPLIT, AllowCppStyl
     if AllowCppStyleComment:\r
         Line = Line.replace(DataType.TAB_COMMENT_EDK_SPLIT, CommentCharacter)\r
     #\r
-    # separate comments and statements\r
+    # separate comments and statements, but we should escape comment character in string\r
     #\r
-    LineParts = Line.split(CommentCharacter, 1);\r
-    #\r
-    # remove whitespace again\r
-    #\r
-    Line = LineParts[0].strip();\r
-    if len(LineParts) > 1:\r
-        Comment = LineParts[1].strip()\r
+    InString = 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
+            CommentInString = True\r
+        elif Line[Index] == CommentCharacter and not InString:\r
+            Comment = Line[Index:].strip()\r
+            Line = Line[0:Index].strip()\r
+            break\r
+    if Comment:\r
         # Remove prefixed and trailing comment characters\r
         Start = 0\r
         End = len(Comment)\r
@@ -405,8 +411,6 @@ def CleanString2(Line, CommentCharacter=DataType.TAB_COMMENT_SPLIT, AllowCppStyl
             End -= 1\r
         Comment = Comment[Start:End]\r
         Comment = Comment.strip()\r
-    else:\r
-        Comment = ''\r
 \r
     return Line, Comment\r
 \r