diff options
author | lgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524> | 2011-09-18 12:17:25 +0000 |
---|---|---|
committer | lgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524> | 2011-09-18 12:17:25 +0000 |
commit | b36d134faf4305247830522b8e2bb255e98c5699 (patch) | |
tree | ec37795cbc86b693528a062030cb516039bcb1c2 /BaseTools/Source/Python/Common/String.py | |
parent | e7fe4028631b6a7d70e3c02c7c40ff1504321daa (diff) | |
download | edk2-platforms-b36d134faf4305247830522b8e2bb255e98c5699.tar.xz |
Sync BaseTools Branch (version r2321) to EDKII main trunk.
Signed-off-by: lgao4
Reviewed-by: gikidy
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12372 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'BaseTools/Source/Python/Common/String.py')
-rw-r--r-- | BaseTools/Source/Python/Common/String.py | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/BaseTools/Source/Python/Common/String.py b/BaseTools/Source/Python/Common/String.py index 195fa5c6ca..4880768866 100644 --- a/BaseTools/Source/Python/Common/String.py +++ b/BaseTools/Source/Python/Common/String.py @@ -20,7 +20,7 @@ import os.path import string
import EdkLogger as EdkLogger
-from GlobalData import *
+import GlobalData
from BuildToolError import *
gHexVerPatt = re.compile('0x[a-f0-9]{4}[a-f0-9]{4}$',re.IGNORECASE)
@@ -213,7 +213,7 @@ def ReplaceMacros(StringList, MacroDefinitions={}, SelfReplacement = False): def ReplaceMacro(String, MacroDefinitions={}, SelfReplacement = False):
LastString = String
while MacroDefinitions:
- MacroUsed = gMacroPattern.findall(String)
+ MacroUsed = GlobalData.gMacroPattern.findall(String)
# no macro found in String, stop replacing
if len(MacroUsed) == 0:
break
@@ -277,21 +277,40 @@ def CleanString(Line, CommentCharacter = DataType.TAB_COMMENT_SPLIT, AllowCppSty #
Line = Line.strip();
#
- # Replace R8's comment character
+ # Replace Edk's comment character
#
if AllowCppStyleComment:
- Line = Line.replace(DataType.TAB_COMMENT_R8_SPLIT, CommentCharacter)
+ Line = Line.replace(DataType.TAB_COMMENT_EDK_SPLIT, CommentCharacter)
#
# remove comments, but we should escape comment character in string
#
InString = False
+ CommentInString = False
for Index in range(0, len(Line)):
if Line[Index] == '"':
InString = not InString
- elif Line[Index] == CommentCharacter and not InString:
+ elif Line[Index] == CommentCharacter and InString :
+ CommentInString = True
+ elif Line[Index] == CommentCharacter and not InString :
Line = Line[0: Index]
break
-
+
+ if CommentInString:
+ Line = Line.replace('"', '')
+ ChIndex = Line.find('#')
+ while ChIndex >= 0:
+ if GlobalData.gIsWindows:
+ if ChIndex == 0 or Line[ChIndex-1] != '^':
+ Line = Line[0:ChIndex] + '^' + Line[ChIndex:]
+ ChIndex = Line.find('#', ChIndex + 2)
+ else:
+ ChIndex = Line.find('#', ChIndex + 1)
+ else:
+ if ChIndex == 0 or Line[ChIndex-1] != '\\':
+ Line = Line[0:ChIndex] + '\\' + Line[ChIndex:]
+ ChIndex = Line.find('#', ChIndex + 2)
+ else:
+ ChIndex = Line.find('#', ChIndex + 1)
#
# remove whitespace again
#
@@ -315,10 +334,10 @@ def CleanString2(Line, CommentCharacter = DataType.TAB_COMMENT_SPLIT, AllowCppSt #
Line = Line.strip();
#
- # Replace R8's comment character
+ # Replace Edk's comment character
#
if AllowCppStyleComment:
- Line = Line.replace(DataType.TAB_COMMENT_R8_SPLIT, CommentCharacter)
+ Line = Line.replace(DataType.TAB_COMMENT_EDK_SPLIT, CommentCharacter)
#
# separate comments and statements
#
@@ -689,11 +708,11 @@ def RemoveBlockComment(Lines): #
# Remove comment block
#
- if Line.find(DataType.TAB_COMMENT_R8_START) > -1:
- ReservedLine = GetSplitValueList(Line, DataType.TAB_COMMENT_R8_START, 1)[0]
+ if Line.find(DataType.TAB_COMMENT_EDK_START) > -1:
+ ReservedLine = GetSplitValueList(Line, DataType.TAB_COMMENT_EDK_START, 1)[0]
IsFindBlockComment = True
- if Line.find(DataType.TAB_COMMENT_R8_END) > -1:
- Line = ReservedLine + GetSplitValueList(Line, DataType.TAB_COMMENT_R8_END, 1)[1]
+ if Line.find(DataType.TAB_COMMENT_EDK_END) > -1:
+ Line = ReservedLine + GetSplitValueList(Line, DataType.TAB_COMMENT_EDK_END, 1)[1]
ReservedLine = ''
IsFindBlockComment = False
if IsFindBlockComment:
|