]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/Common/String.py
2 # This file is used to define common string related functions used in parsing process
4 # Copyright (c) 2007 - 2008, Intel Corporation. All rights reserved.<BR>
5 # This program and the accompanying materials
6 # are licensed and made available under the terms and conditions of the BSD License
7 # which accompanies this distribution. The full text of the license may be found at
8 # http://opensource.org/licenses/bsd-license.php
10 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21 import EdkLogger
as EdkLogger
24 from BuildToolError
import *
25 from CommonDataClass
.Exceptions
import *
27 gHexVerPatt
= re
.compile('0x[a-f0-9]{4}[a-f0-9]{4}$', re
.IGNORECASE
)
28 gHumanReadableVerPatt
= re
.compile(r
'([1-9][0-9]*|0)\.[0-9]{1,2}$')
32 # Get a value list from a string with multiple values splited with SplitTag
33 # The default SplitTag is DataType.TAB_VALUE_SPLIT
34 # 'AAA|BBB|CCC' -> ['AAA', 'BBB', 'CCC']
36 # @param String: The input string to be splitted
37 # @param SplitTag: The split key, default is DataType.TAB_VALUE_SPLIT
38 # @param MaxSplit: The max number of split values, default is -1
40 # @retval list() A list for splitted string
42 def GetSplitValueList(String
, SplitTag
=DataType
.TAB_VALUE_SPLIT
, MaxSplit
= -1):
47 for Index
in range(0, len(String
)):
51 # Found a splitter not in a string, split it
52 if not InString
and Char
== SplitTag
:
53 ValueList
.append(String
[Last
:Index
].strip())
55 if MaxSplit
> 0 and len(ValueList
) >= MaxSplit
:
58 if Char
== '\\' and InString
:
68 if Last
< len(String
):
69 ValueList
.append(String
[Last
:].strip())
70 elif Last
== len(String
):
77 # Get a value list from a string with multiple values splited with SplitString
78 # The default SplitTag is DataType.TAB_VALUE_SPLIT
79 # 'AAA|BBB|CCC' -> ['AAA', 'BBB', 'CCC']
81 # @param String: The input string to be splitted
82 # @param SplitStr: The split key, default is DataType.TAB_VALUE_SPLIT
83 # @param MaxSplit: The max number of split values, default is -1
85 # @retval list() A list for splitted string
87 def GetSplitList(String
, SplitStr
=DataType
.TAB_VALUE_SPLIT
, MaxSplit
= -1):
88 return map(lambda l
: l
.strip(), String
.split(SplitStr
, MaxSplit
))
92 # Find a key's all arches in dict, add the new arch to the list
93 # If not exist any arch, set the arch directly
95 # @param Dict: The input value for Dict
96 # @param Key: The input value for Key
97 # @param Arch: The Arch to be added or merged
99 def MergeArches(Dict
, Key
, Arch
):
100 if Key
in Dict
.keys():
101 Dict
[Key
].append(Arch
)
103 Dict
[Key
] = Arch
.split()
107 # Parse a string with format "DEFINE <VarName> = <PATH>"
108 # Generate a map Defines[VarName] = PATH
109 # Return False if invalid format
111 # @param String: String with DEFINE statement
112 # @param Arch: Supportted Arch
113 # @param Defines: DEFINE statement to be parsed
115 # @retval 0 DEFINE statement found, and valid
116 # @retval 1 DEFINE statement found, but not valid
117 # @retval -1 DEFINE statement not found
119 def GenDefines(String
, Arch
, Defines
):
120 if String
.find(DataType
.TAB_DEFINE
+ ' ') > -1:
121 List
= String
.replace(DataType
.TAB_DEFINE
+ ' ', '').split(DataType
.TAB_EQUAL_SPLIT
)
123 Defines
[(CleanString(List
[0]), Arch
)] = CleanString(List
[1])
132 # Parse a string with format "!include <Filename>"
133 # Return the file path
134 # Return False if invalid format or NOT FOUND
136 # @param String: String with INCLUDE statement
137 # @param IncludeFiles: INCLUDE statement to be parsed
138 # @param Arch: Supportted Arch
143 def GenInclude(String
, IncludeFiles
, Arch
):
144 if String
.upper().find(DataType
.TAB_INCLUDE
.upper() + ' ') > -1:
145 IncludeFile
= CleanString(String
[String
.upper().find(DataType
.TAB_INCLUDE
.upper() + ' ') + len(DataType
.TAB_INCLUDE
+ ' ') : ])
146 MergeArches(IncludeFiles
, IncludeFile
, Arch
)
151 ## GetLibraryClassesWithModuleType
153 # Get Library Class definition when no module type defined
155 # @param Lines: The content to be parsed
156 # @param Key: Reserved
157 # @param KeyValues: To store data after parsing
158 # @param CommentCharacter: Comment char, used to ignore comment content
160 # @retval True Get library classes successfully
162 def GetLibraryClassesWithModuleType(Lines
, Key
, KeyValues
, CommentCharacter
):
163 newKey
= SplitModuleType(Key
)
164 Lines
= Lines
.split(DataType
.TAB_SECTION_END
, 1)[1]
165 LineList
= Lines
.splitlines()
166 for Line
in LineList
:
167 Line
= CleanString(Line
, CommentCharacter
)
168 if Line
!= '' and Line
[0] != CommentCharacter
:
169 KeyValues
.append([CleanString(Line
, CommentCharacter
), newKey
[1]])
177 # @param Lines: The content to be parsed
178 # @param Key: Reserved
179 # @param KeyValues: To store data after parsing
180 # @param CommentCharacter: Comment char, used to ignore comment content
182 # @retval True Get Dynamic Pcds successfully
184 def GetDynamics(Lines
, Key
, KeyValues
, CommentCharacter
):
186 # Get SkuId Name List
188 SkuIdNameList
= SplitModuleType(Key
)
190 Lines
= Lines
.split(DataType
.TAB_SECTION_END
, 1)[1]
191 LineList
= Lines
.splitlines()
192 for Line
in LineList
:
193 Line
= CleanString(Line
, CommentCharacter
)
194 if Line
!= '' and Line
[0] != CommentCharacter
:
195 KeyValues
.append([CleanString(Line
, CommentCharacter
), SkuIdNameList
[1]])
201 # Split ModuleType out of section defien to get key
202 # [LibraryClass.Arch.ModuleType|ModuleType|ModuleType] -> [ 'LibraryClass.Arch', ['ModuleType', 'ModuleType', 'ModuleType'] ]
204 # @param Key: String to be parsed
206 # @retval ReturnValue A list for module types
208 def SplitModuleType(Key
):
209 KeyList
= Key
.split(DataType
.TAB_SPLIT
)
215 # Fill in for moduletype
219 KeyValue
= KeyList
[0]
221 KeyValue
= KeyValue
+ DataType
.TAB_SPLIT
+ KeyList
[1]
222 ReturnValue
.append(KeyValue
)
223 ReturnValue
.append(GetSplitValueList(KeyList
[2]))
227 ## Replace macro in strings list
229 # This method replace macros used in a given string list. The macros are
230 # given in a dictionary.
232 # @param StringList StringList to be processed
233 # @param MacroDefinitions The macro definitions in the form of dictionary
234 # @param SelfReplacement To decide whether replace un-defined macro to ''
236 # @retval NewList A new string list whose macros are replaced
238 def ReplaceMacros(StringList
, MacroDefinitions
={}, SelfReplacement
=False):
240 for String
in StringList
:
241 if type(String
) == type(''):
242 NewList
.append(ReplaceMacro(String
, MacroDefinitions
, SelfReplacement
))
244 NewList
.append(String
)
248 ## Replace macro in string
250 # This method replace macros used in given string. The macros are given in a
253 # @param String String to be processed
254 # @param MacroDefinitions The macro definitions in the form of dictionary
255 # @param SelfReplacement To decide whether replace un-defined macro to ''
257 # @retval string The string whose macros are replaced
259 def ReplaceMacro(String
, MacroDefinitions
={}, SelfReplacement
=False, RaiseError
=False):
261 while String
and MacroDefinitions
:
262 MacroUsed
= GlobalData
.gMacroRefPattern
.findall(String
)
263 # no macro found in String, stop replacing
264 if len(MacroUsed
) == 0:
267 for Macro
in MacroUsed
:
268 if Macro
not in MacroDefinitions
:
270 raise SymbolNotFound("%s not defined" % Macro
)
272 String
= String
.replace("$(%s)" % Macro
, '')
274 String
= String
.replace("$(%s)" % Macro
, MacroDefinitions
[Macro
])
275 # in case there's macro not defined
276 if String
== LastString
:
284 # Create a normal path
285 # And replace DFEINE in the path
287 # @param Path: The input value for Path to be converted
288 # @param Defines: A set for DEFINE statement
290 # @retval Path Formatted path
292 def NormPath(Path
, Defines
={}):
293 IsRelativePath
= False
296 IsRelativePath
= True
298 # Replace with Define
301 Path
= ReplaceMacro(Path
, Defines
)
303 # To local path format
305 Path
= os
.path
.normpath(Path
)
307 if IsRelativePath
and Path
[0] != '.':
308 Path
= os
.path
.join('.', Path
)
314 # Remove comments in a string
317 # @param Line: The string to be cleaned
318 # @param CommentCharacter: Comment char, used to ignore comment content, default is DataType.TAB_COMMENT_SPLIT
320 # @retval Path Formatted path
322 def CleanString(Line
, CommentCharacter
=DataType
.TAB_COMMENT_SPLIT
, AllowCppStyleComment
=False, BuildOption
=False):
328 # Replace Edk's comment character
330 if AllowCppStyleComment
:
331 Line
= Line
.replace(DataType
.TAB_COMMENT_EDK_SPLIT
, CommentCharacter
)
333 # remove comments, but we should escape comment character in string
336 CommentInString
= False
337 for Index
in range(0, len(Line
)):
338 if Line
[Index
] == '"':
339 InString
= not InString
340 elif Line
[Index
] == CommentCharacter
and InString
:
341 CommentInString
= True
342 elif Line
[Index
] == CommentCharacter
and not InString
:
343 Line
= Line
[0: Index
]
346 if CommentInString
and BuildOption
:
347 Line
= Line
.replace('"', '')
348 ChIndex
= Line
.find('#')
350 if GlobalData
.gIsWindows
:
351 if ChIndex
== 0 or Line
[ChIndex
- 1] != '^':
352 Line
= Line
[0:ChIndex
] + '^' + Line
[ChIndex
:]
353 ChIndex
= Line
.find('#', ChIndex
+ 2)
355 ChIndex
= Line
.find('#', ChIndex
+ 1)
357 if ChIndex
== 0 or Line
[ChIndex
- 1] != '\\':
358 Line
= Line
[0:ChIndex
] + '\\' + Line
[ChIndex
:]
359 ChIndex
= Line
.find('#', ChIndex
+ 2)
361 ChIndex
= Line
.find('#', ChIndex
+ 1)
363 # remove whitespace again
371 # Split statement with comments in a string
374 # @param Line: The string to be cleaned
375 # @param CommentCharacter: Comment char, used to ignore comment content, default is DataType.TAB_COMMENT_SPLIT
377 # @retval Path Formatted path
379 def CleanString2(Line
, CommentCharacter
=DataType
.TAB_COMMENT_SPLIT
, AllowCppStyleComment
=False):
385 # Replace Edk's comment character
387 if AllowCppStyleComment
:
388 Line
= Line
.replace(DataType
.TAB_COMMENT_EDK_SPLIT
, CommentCharacter
)
390 # separate comments and statements, but we should escape comment character in string
393 CommentInString
= False
395 for Index
in range(0, len(Line
)):
396 if Line
[Index
] == '"':
397 InString
= not InString
398 elif Line
[Index
] == CommentCharacter
and InString
:
399 CommentInString
= True
400 elif Line
[Index
] == CommentCharacter
and not InString
:
401 Comment
= Line
[Index
:].strip()
402 Line
= Line
[0:Index
].strip()
405 # Remove prefixed and trailing comment characters
408 while Start
< End
and Comment
.startswith(CommentCharacter
, Start
, End
):
410 while End
>= 0 and Comment
.endswith(CommentCharacter
, Start
, End
):
412 Comment
= Comment
[Start
:End
]
413 Comment
= Comment
.strip()
417 ## GetMultipleValuesOfKeyFromLines
419 # Parse multiple strings to clean comment and spaces
420 # The result is saved to KeyValues
422 # @param Lines: The content to be parsed
423 # @param Key: Reserved
424 # @param KeyValues: To store data after parsing
425 # @param CommentCharacter: Comment char, used to ignore comment content
427 # @retval True Successfully executed
429 def GetMultipleValuesOfKeyFromLines(Lines
, Key
, KeyValues
, CommentCharacter
):
430 Lines
= Lines
.split(DataType
.TAB_SECTION_END
, 1)[1]
431 LineList
= Lines
.split('\n')
432 for Line
in LineList
:
433 Line
= CleanString(Line
, CommentCharacter
)
434 if Line
!= '' and Line
[0] != CommentCharacter
:
441 # Parse a DEFINE statement to get defined value
444 # @param String: The content to be parsed
445 # @param Key: The key of DEFINE statement
446 # @param CommentCharacter: Comment char, used to ignore comment content
448 # @retval string The defined value
450 def GetDefineValue(String
, Key
, CommentCharacter
):
451 String
= CleanString(String
)
452 return String
[String
.find(Key
+ ' ') + len(Key
+ ' ') : ]
456 # Get a Hex Version Value
458 # @param VerString: The version string to be parsed
461 # @retval: If VerString is incorrectly formatted, return "None" which will break the build.
462 # If VerString is correctly formatted, return a Hex value of the Version Number (0xmmmmnnnn)
463 # where mmmm is the major number and nnnn is the adjusted minor number.
465 def GetHexVerValue(VerString
):
466 VerString
= CleanString(VerString
)
468 if gHumanReadableVerPatt
.match(VerString
):
469 ValueList
= VerString
.split('.')
474 DeciValue
= (int(Major
) << 16) + int(Minor
);
475 return "0x%08x" % DeciValue
476 elif gHexVerPatt
.match(VerString
):
482 ## GetSingleValueOfKeyFromLines
484 # Parse multiple strings as below to get value of each definition line
487 # The result is saved to Dictionary
489 # @param Lines: The content to be parsed
490 # @param Dictionary: To store data after parsing
491 # @param CommentCharacter: Comment char, be used to ignore comment content
492 # @param KeySplitCharacter: Key split char, between key name and key value. Key1 = Value1, '=' is the key split char
493 # @param ValueSplitFlag: Value split flag, be used to decide if has multiple values
494 # @param ValueSplitCharacter: Value split char, be used to split multiple values. Key1 = Value1|Value2, '|' is the value split char
496 # @retval True Successfully executed
498 def GetSingleValueOfKeyFromLines(Lines
, Dictionary
, CommentCharacter
, KeySplitCharacter
, ValueSplitFlag
, ValueSplitCharacter
):
499 Lines
= Lines
.split('\n')
507 # Handle DEFINE and SPEC
509 if Line
.find(DataType
.TAB_INF_DEFINES_DEFINE
+ ' ') > -1:
510 if '' in DefineValues
:
511 DefineValues
.remove('')
512 DefineValues
.append(GetDefineValue(Line
, DataType
.TAB_INF_DEFINES_DEFINE
, CommentCharacter
))
514 if Line
.find(DataType
.TAB_INF_DEFINES_SPEC
+ ' ') > -1:
516 SpecValues
.remove('')
517 SpecValues
.append(GetDefineValue(Line
, DataType
.TAB_INF_DEFINES_SPEC
, CommentCharacter
))
523 LineList
= Line
.split(KeySplitCharacter
, 1)
524 if len(LineList
) >= 2:
525 Key
= LineList
[0].split()
526 if len(Key
) == 1 and Key
[0][0] != CommentCharacter
:
528 # Remove comments and white spaces
530 LineList
[1] = CleanString(LineList
[1], CommentCharacter
)
532 Value
= map(string
.strip
, LineList
[1].split(ValueSplitCharacter
))
534 Value
= CleanString(LineList
[1], CommentCharacter
).splitlines()
536 if Key
[0] in Dictionary
:
537 if Key
[0] not in Keys
:
538 Dictionary
[Key
[0]] = Value
541 Dictionary
[Key
[0]].extend(Value
)
543 Dictionary
[DataType
.TAB_INF_DEFINES_MACRO
][Key
[0]] = Value
[0]
545 if DefineValues
== []:
549 Dictionary
[DataType
.TAB_INF_DEFINES_DEFINE
] = DefineValues
550 Dictionary
[DataType
.TAB_INF_DEFINES_SPEC
] = SpecValues
554 ## The content to be parsed
556 # Do pre-check for a file before it is parsed
560 # @param FileName: Used for error report
561 # @param FileContent: File content to be parsed
562 # @param SupSectionTag: Used for error report
564 def PreCheck(FileName
, FileContent
, SupSectionTag
):
568 for Line
in FileContent
.splitlines():
573 Line
= CleanString(Line
)
576 # Remove commented line
578 if Line
.find(DataType
.TAB_COMMA_SPLIT
) == 0:
583 if Line
.find('$') > -1:
584 if Line
.find('$(') < 0 or Line
.find(')') < 0:
585 EdkLogger
.error("Parser", FORMAT_INVALID
, Line
=LineNo
, File
=FileName
, RaiseError
=EdkLogger
.IsRaiseError
)
590 if Line
.find('[') > -1 or Line
.find(']') > -1:
592 # Only get one '[' or one ']'
594 if not (Line
.find('[') > -1 and Line
.find(']') > -1):
595 EdkLogger
.error("Parser", FORMAT_INVALID
, Line
=LineNo
, File
=FileName
, RaiseError
=EdkLogger
.IsRaiseError
)
598 # Regenerate FileContent
600 NewFileContent
= NewFileContent
+ Line
+ '\r\n'
603 EdkLogger
.error("Parser", FORMAT_INVALID
, Line
=LineNo
, File
=FileName
, RaiseError
=EdkLogger
.IsRaiseError
)
605 return NewFileContent
609 # Check if the Filename is including ExtName
610 # Return True if it exists
611 # Raise a error message if it not exists
613 # @param CheckFilename: Name of the file to be checked
614 # @param ExtName: Ext name of the file to be checked
615 # @param ContainerFilename: The container file which describes the file to be checked, used for error report
616 # @param SectionName: Used for error report
617 # @param Line: The line in container file which defines the file to be checked
619 # @retval True The file type is correct
621 def CheckFileType(CheckFilename
, ExtName
, ContainerFilename
, SectionName
, Line
, LineNo
= -1):
622 if CheckFilename
!= '' and CheckFilename
!= None:
623 (Root
, Ext
) = os
.path
.splitext(CheckFilename
)
624 if Ext
.upper() != ExtName
.upper():
625 ContainerFile
= open(ContainerFilename
, 'r').read()
627 LineNo
= GetLineNo(ContainerFile
, Line
)
628 ErrorMsg
= "Invalid %s. '%s' is found, but '%s' file is needed" % (SectionName
, CheckFilename
, ExtName
)
629 EdkLogger
.error("Parser", PARSER_ERROR
, ErrorMsg
, Line
=LineNo
,
630 File
=ContainerFilename
, RaiseError
=EdkLogger
.IsRaiseError
)
636 # Check if the file exists
637 # Return True if it exists
638 # Raise a error message if it not exists
640 # @param CheckFilename: Name of the file to be checked
641 # @param WorkspaceDir: Current workspace dir
642 # @param ContainerFilename: The container file which describes the file to be checked, used for error report
643 # @param SectionName: Used for error report
644 # @param Line: The line in container file which defines the file to be checked
646 # @retval The file full path if the file exists
648 def CheckFileExist(WorkspaceDir
, CheckFilename
, ContainerFilename
, SectionName
, Line
, LineNo
= -1):
650 if CheckFilename
!= '' and CheckFilename
!= None:
651 CheckFile
= WorkspaceFile(WorkspaceDir
, CheckFilename
)
652 if not os
.path
.isfile(CheckFile
):
653 ContainerFile
= open(ContainerFilename
, 'r').read()
655 LineNo
= GetLineNo(ContainerFile
, Line
)
656 ErrorMsg
= "Can't find file '%s' defined in section '%s'" % (CheckFile
, SectionName
)
657 EdkLogger
.error("Parser", PARSER_ERROR
, ErrorMsg
,
658 File
=ContainerFilename
, Line
=LineNo
, RaiseError
=EdkLogger
.IsRaiseError
)
664 # Find the index of a line in a file
666 # @param FileContent: Search scope
667 # @param Line: Search key
669 # @retval int Index of the line
670 # @retval -1 The line is not found
672 def GetLineNo(FileContent
, Line
, IsIgnoreComment
=True):
673 LineList
= FileContent
.splitlines()
674 for Index
in range(len(LineList
)):
675 if LineList
[Index
].find(Line
) > -1:
677 # Ignore statement in comment
680 if LineList
[Index
].strip()[0] == DataType
.TAB_COMMENT_SPLIT
:
688 # Raise a parser error
690 # @param Line: String which has error
691 # @param Section: Used for error report
692 # @param File: File which has the string
693 # @param Format: Correct format
695 def RaiseParserError(Line
, Section
, File
, Format
='', LineNo
= -1):
697 LineNo
= GetLineNo(open(os
.path
.normpath(File
), 'r').read(), Line
)
698 ErrorMsg
= "Invalid statement '%s' is found in section '%s'" % (Line
, Section
)
700 Format
= "Correct format is " + Format
701 EdkLogger
.error("Parser", PARSER_ERROR
, ErrorMsg
, File
=File
, Line
=LineNo
, ExtraData
=Format
, RaiseError
=EdkLogger
.IsRaiseError
)
705 # Return a full path with workspace dir
707 # @param WorkspaceDir: Workspace dir
708 # @param Filename: Relative file name
710 # @retval string A full path
712 def WorkspaceFile(WorkspaceDir
, Filename
):
713 return os
.path
.join(NormPath(WorkspaceDir
), NormPath(Filename
))
717 # Revmove '"' which startswith and endswith string
719 # @param String: The string need to be splited
721 # @retval String: The string after removed '""'
723 def SplitString(String
):
724 if String
.startswith('\"'):
726 if String
.endswith('\"'):
731 ## Convert To Sql String
733 # 1. Replace "'" with "''" in each item of StringList
735 # @param StringList: A list for strings to be converted
737 def ConvertToSqlString(StringList
):
738 return map(lambda s
: s
.replace("'", "''") , StringList
)
740 ## Convert To Sql String
742 # 1. Replace "'" with "''" in the String
744 # @param String: A String to be converted
746 def ConvertToSqlString2(String
):
747 return String
.replace("'", "''")
750 # Remove comment block
752 def RemoveBlockComment(Lines
):
753 IsFindBlockComment
= False
754 IsFindBlockCode
= False
761 # Remove comment block
763 if Line
.find(DataType
.TAB_COMMENT_EDK_START
) > -1:
764 ReservedLine
= GetSplitList(Line
, DataType
.TAB_COMMENT_EDK_START
, 1)[0]
765 IsFindBlockComment
= True
766 if Line
.find(DataType
.TAB_COMMENT_EDK_END
) > -1:
767 Line
= ReservedLine
+ GetSplitList(Line
, DataType
.TAB_COMMENT_EDK_END
, 1)[1]
769 IsFindBlockComment
= False
770 if IsFindBlockComment
:
774 NewLines
.append(Line
)
778 # Get String of a List
780 def GetStringOfList(List
, Split
=' '):
781 if type(List
) != type([]):
785 Str
= Str
+ Item
+ Split
790 # Get HelpTextList from HelpTextClassList
792 def GetHelpTextList(HelpTextClassList
):
794 if HelpTextClassList
:
795 for HelpText
in HelpTextClassList
:
796 if HelpText
.String
.endswith('\n'):
797 HelpText
.String
= HelpText
.String
[0: len(HelpText
.String
) - len('\n')]
798 List
.extend(HelpText
.String
.split('\n'))
802 def StringToArray(String
):
803 if isinstance(String
, unicode):
804 if len(unicode) == 0:
805 return "{0x00, 0x00}"
806 return "{%s, 0x00, 0x00}" % ", ".join(["0x%02x, 0x00" % ord(C
) for C
in String
])
807 elif String
.startswith('L"'):
808 if String
== "L\"\"":
809 return "{0x00, 0x00}"
811 return "{%s, 0x00, 0x00}" % ", ".join(["0x%02x, 0x00" % ord(C
) for C
in String
[2:-1]])
812 elif String
.startswith('"'):
816 return "{%s, 0x00}" % ", ".join(["0x%02x" % ord(C
) for C
in String
[1:-1]])
818 return '{%s, 0}' % ', '.join(String
.split())
820 def StringArrayLength(String
):
821 if isinstance(String
, unicode):
822 return (len(String
) + 1) * 2 + 1;
823 elif String
.startswith('L"'):
824 return (len(String
) - 3 + 1) * 2
825 elif String
.startswith('"'):
826 return (len(String
) - 2 + 1)
828 return len(String
.split()) + 1
830 def RemoveDupOption(OptionString
, Which
="/I", Against
=None):
831 OptionList
= OptionString
.split()
835 for Index
in range(len(OptionList
)):
836 Opt
= OptionList
[Index
]
837 if not Opt
.startswith(Which
):
839 if len(Opt
) > len(Which
):
840 Val
= Opt
[len(Which
):]
844 OptionList
[Index
] = ""
846 ValueList
.append(Val
)
847 return " ".join(OptionList
)
851 # This acts like the main() function for the script, unless it is 'import'ed into another
854 if __name__
== '__main__':