From e56468c072e0d53834787f4ad0e292b33cc6be08 Mon Sep 17 00:00:00 2001 From: qhuang8 Date: Mon, 6 Sep 2010 01:58:00 +0000 Subject: Sync EDKII BaseTools to BaseTools project r2042. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10850 6f19259b-4bc3-4df7-8a09-765794883524 --- BaseTools/Source/Python/Common/String.py | 44 ++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (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 896fb7da0f..283e913b3b 100644 --- a/BaseTools/Source/Python/Common/String.py +++ b/BaseTools/Source/Python/Common/String.py @@ -296,6 +296,50 @@ def CleanString(Line, CommentCharacter = DataType.TAB_COMMENT_SPLIT, AllowCppSty return Line +## CleanString2 +# +# Split comments in a string +# Remove spaces +# +# @param Line: The string to be cleaned +# @param CommentCharacter: Comment char, used to ignore comment content, default is DataType.TAB_COMMENT_SPLIT +# +# @retval Path Formatted path +# +def CleanString2(Line, CommentCharacter = DataType.TAB_COMMENT_SPLIT, AllowCppStyleComment=False): + # + # remove whitespace + # + Line = Line.strip(); + # + # Replace R8's comment character + # + if AllowCppStyleComment: + Line = Line.replace(DataType.TAB_COMMENT_R8_SPLIT, CommentCharacter) + # + # separate comments and statements + # + LineParts = Line.split(CommentCharacter, 1); + # + # remove whitespace again + # + Line = LineParts[0].strip(); + if len(LineParts) > 1: + Comment = LineParts[1].strip() + # Remove prefixed and trailing comment characters + Start = 0 + End = len(Comment) + while Start < End and Comment.startswith(CommentCharacter, Start, End): + Start += 1 + while End >= 0 and Comment.endswith(CommentCharacter, Start, End): + End -= 1 + Comment = Comment[Start:End] + Comment = Comment.strip() + else: + Comment = '' + + return Line, Comment + ## GetMultipleValuesOfKeyFromLines # # Parse multiple strings to clean comment and spaces -- cgit v1.2.3