diff options
author | Liming Gao <liming.gao@intel.com> | 2013-08-23 02:18:16 +0000 |
---|---|---|
committer | lgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524> | 2013-08-23 02:18:16 +0000 |
commit | 4afd3d042215afe68d00b9ab8c32f063a3a1c03f (patch) | |
tree | b5190bd11547ac22fe35eeceee85ef42bfe6eea5 /BaseTools/Source/Python/Common/String.py | |
parent | a365eed476687881ce0ed49af7d483fd3cb0c491 (diff) | |
download | edk2-platforms-4afd3d042215afe68d00b9ab8c32f063a3a1c03f.tar.xz |
Sync BaseTool trunk (version r2599) into EDKII BaseTools.
Signed-off-by: Liming Gao <liming.gao@intel.com>
Reviewed-by: Heshen Chen <chen.heshen@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14591 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'BaseTools/Source/Python/Common/String.py')
-rw-r--r-- | BaseTools/Source/Python/Common/String.py | 26 |
1 files changed, 15 insertions, 11 deletions
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
|