\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
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
End -= 1\r
Comment = Comment[Start:End]\r
Comment = Comment.strip()\r
- else:\r
- Comment = ''\r
\r
return Line, Comment\r
\r