From 4afd3d042215afe68d00b9ab8c32f063a3a1c03f Mon Sep 17 00:00:00 2001 From: Liming Gao Date: Fri, 23 Aug 2013 02:18:16 +0000 Subject: Sync BaseTool trunk (version r2599) into EDKII BaseTools. Signed-off-by: Liming Gao Reviewed-by: Heshen Chen git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14591 6f19259b-4bc3-4df7-8a09-765794883524 --- BaseTools/Source/Python/Common/String.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'BaseTools/Source/Python/Common/String.py') diff --git a/BaseTools/Source/Python/Common/String.py b/BaseTools/Source/Python/Common/String.py index 068a63d1c1..c282326677 100644 --- a/BaseTools/Source/Python/Common/String.py +++ b/BaseTools/Source/Python/Common/String.py @@ -368,7 +368,7 @@ def CleanString(Line, CommentCharacter=DataType.TAB_COMMENT_SPLIT, AllowCppStyle ## CleanString2 # -# Split comments in a string +# Split statement with comments in a string # Remove spaces # # @param Line: The string to be cleaned @@ -387,15 +387,21 @@ def CleanString2(Line, CommentCharacter=DataType.TAB_COMMENT_SPLIT, AllowCppStyl if AllowCppStyleComment: Line = Line.replace(DataType.TAB_COMMENT_EDK_SPLIT, CommentCharacter) # - # separate comments and statements + # separate comments and statements, but we should escape comment character in string # - LineParts = Line.split(CommentCharacter, 1); - # - # remove whitespace again - # - Line = LineParts[0].strip(); - if len(LineParts) > 1: - Comment = LineParts[1].strip() + InString = False + CommentInString = False + Comment = '' + for Index in range(0, len(Line)): + if Line[Index] == '"': + InString = not InString + elif Line[Index] == CommentCharacter and InString: + CommentInString = True + elif Line[Index] == CommentCharacter and not InString: + Comment = Line[Index:].strip() + Line = Line[0:Index].strip() + break + if Comment: # Remove prefixed and trailing comment characters Start = 0 End = len(Comment) @@ -405,8 +411,6 @@ def CleanString2(Line, CommentCharacter=DataType.TAB_COMMENT_SPLIT, AllowCppStyl End -= 1 Comment = Comment[Start:End] Comment = Comment.strip() - else: - Comment = '' return Line, Comment -- cgit v1.2.3