]>
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()
407 ## GetMultipleValuesOfKeyFromLines
409 # Parse multiple strings to clean comment and spaces
410 # The result is saved to KeyValues
412 # @param Lines: The content to be parsed
413 # @param Key: Reserved
414 # @param KeyValues: To store data after parsing
415 # @param CommentCharacter: Comment char, used to ignore comment content
417 # @retval True Successfully executed
419 def GetMultipleValuesOfKeyFromLines(Lines
, Key
, KeyValues
, CommentCharacter
):
420 Lines
= Lines
.split(DataType
.TAB_SECTION_END
, 1)[1]
421 LineList
= Lines
.split('\n')
422 for Line
in LineList
:
423 Line
= CleanString(Line
, CommentCharacter
)
424 if Line
!= '' and Line
[0] != CommentCharacter
:
431 # Parse a DEFINE statement to get defined value
434 # @param String: The content to be parsed
435 # @param Key: The key of DEFINE statement
436 # @param CommentCharacter: Comment char, used to ignore comment content
438 # @retval string The defined value
440 def GetDefineValue(String
, Key
, CommentCharacter
):
441 String
= CleanString(String
)
442 return String
[String
.find(Key
+ ' ') + len(Key
+ ' ') : ]
446 # Get a Hex Version Value
448 # @param VerString: The version string to be parsed
451 # @retval: If VerString is incorrectly formatted, return "None" which will break the build.
452 # If VerString is correctly formatted, return a Hex value of the Version Number (0xmmmmnnnn)
453 # where mmmm is the major number and nnnn is the adjusted minor number.
455 def GetHexVerValue(VerString
):
456 VerString
= CleanString(VerString
)
458 if gHumanReadableVerPatt
.match(VerString
):
459 ValueList
= VerString
.split('.')
464 DeciValue
= (int(Major
) << 16) + int(Minor
);
465 return "0x%08x" % DeciValue
466 elif gHexVerPatt
.match(VerString
):
472 ## GetSingleValueOfKeyFromLines
474 # Parse multiple strings as below to get value of each definition line
477 # The result is saved to Dictionary
479 # @param Lines: The content to be parsed
480 # @param Dictionary: To store data after parsing
481 # @param CommentCharacter: Comment char, be used to ignore comment content
482 # @param KeySplitCharacter: Key split char, between key name and key value. Key1 = Value1, '=' is the key split char
483 # @param ValueSplitFlag: Value split flag, be used to decide if has multiple values
484 # @param ValueSplitCharacter: Value split char, be used to split multiple values. Key1 = Value1|Value2, '|' is the value split char
486 # @retval True Successfully executed
488 def GetSingleValueOfKeyFromLines(Lines
, Dictionary
, CommentCharacter
, KeySplitCharacter
, ValueSplitFlag
, ValueSplitCharacter
):
489 Lines
= Lines
.split('\n')
497 # Handle DEFINE and SPEC
499 if Line
.find(DataType
.TAB_INF_DEFINES_DEFINE
+ ' ') > -1:
500 if '' in DefineValues
:
501 DefineValues
.remove('')
502 DefineValues
.append(GetDefineValue(Line
, DataType
.TAB_INF_DEFINES_DEFINE
, CommentCharacter
))
504 if Line
.find(DataType
.TAB_INF_DEFINES_SPEC
+ ' ') > -1:
506 SpecValues
.remove('')
507 SpecValues
.append(GetDefineValue(Line
, DataType
.TAB_INF_DEFINES_SPEC
, CommentCharacter
))
513 LineList
= Line
.split(KeySplitCharacter
, 1)
514 if len(LineList
) >= 2:
515 Key
= LineList
[0].split()
516 if len(Key
) == 1 and Key
[0][0] != CommentCharacter
:
518 # Remove comments and white spaces
520 LineList
[1] = CleanString(LineList
[1], CommentCharacter
)
522 Value
= map(string
.strip
, LineList
[1].split(ValueSplitCharacter
))
524 Value
= CleanString(LineList
[1], CommentCharacter
).splitlines()
526 if Key
[0] in Dictionary
:
527 if Key
[0] not in Keys
:
528 Dictionary
[Key
[0]] = Value
531 Dictionary
[Key
[0]].extend(Value
)
533 Dictionary
[DataType
.TAB_INF_DEFINES_MACRO
][Key
[0]] = Value
[0]
535 if DefineValues
== []:
539 Dictionary
[DataType
.TAB_INF_DEFINES_DEFINE
] = DefineValues
540 Dictionary
[DataType
.TAB_INF_DEFINES_SPEC
] = SpecValues
544 ## The content to be parsed
546 # Do pre-check for a file before it is parsed
550 # @param FileName: Used for error report
551 # @param FileContent: File content to be parsed
552 # @param SupSectionTag: Used for error report
554 def PreCheck(FileName
, FileContent
, SupSectionTag
):
558 for Line
in FileContent
.splitlines():
563 Line
= CleanString(Line
)
566 # Remove commented line
568 if Line
.find(DataType
.TAB_COMMA_SPLIT
) == 0:
573 if Line
.find('$') > -1:
574 if Line
.find('$(') < 0 or Line
.find(')') < 0:
575 EdkLogger
.error("Parser", FORMAT_INVALID
, Line
=LineNo
, File
=FileName
, RaiseError
=EdkLogger
.IsRaiseError
)
580 if Line
.find('[') > -1 or Line
.find(']') > -1:
582 # Only get one '[' or one ']'
584 if not (Line
.find('[') > -1 and Line
.find(']') > -1):
585 EdkLogger
.error("Parser", FORMAT_INVALID
, Line
=LineNo
, File
=FileName
, RaiseError
=EdkLogger
.IsRaiseError
)
588 # Regenerate FileContent
590 NewFileContent
= NewFileContent
+ Line
+ '\r\n'
593 EdkLogger
.error("Parser", FORMAT_INVALID
, Line
=LineNo
, File
=FileName
, RaiseError
=EdkLogger
.IsRaiseError
)
595 return NewFileContent
599 # Check if the Filename is including ExtName
600 # Return True if it exists
601 # Raise a error message if it not exists
603 # @param CheckFilename: Name of the file to be checked
604 # @param ExtName: Ext name of the file to be checked
605 # @param ContainerFilename: The container file which describes the file to be checked, used for error report
606 # @param SectionName: Used for error report
607 # @param Line: The line in container file which defines the file to be checked
609 # @retval True The file type is correct
611 def CheckFileType(CheckFilename
, ExtName
, ContainerFilename
, SectionName
, Line
, LineNo
= -1):
612 if CheckFilename
!= '' and CheckFilename
!= None:
613 (Root
, Ext
) = os
.path
.splitext(CheckFilename
)
614 if Ext
.upper() != ExtName
.upper():
615 ContainerFile
= open(ContainerFilename
, 'r').read()
617 LineNo
= GetLineNo(ContainerFile
, Line
)
618 ErrorMsg
= "Invalid %s. '%s' is found, but '%s' file is needed" % (SectionName
, CheckFilename
, ExtName
)
619 EdkLogger
.error("Parser", PARSER_ERROR
, ErrorMsg
, Line
=LineNo
,
620 File
=ContainerFilename
, RaiseError
=EdkLogger
.IsRaiseError
)
626 # Check if the file exists
627 # Return True if it exists
628 # Raise a error message if it not exists
630 # @param CheckFilename: Name of the file to be checked
631 # @param WorkspaceDir: Current workspace dir
632 # @param ContainerFilename: The container file which describes the file to be checked, used for error report
633 # @param SectionName: Used for error report
634 # @param Line: The line in container file which defines the file to be checked
636 # @retval The file full path if the file exists
638 def CheckFileExist(WorkspaceDir
, CheckFilename
, ContainerFilename
, SectionName
, Line
, LineNo
= -1):
640 if CheckFilename
!= '' and CheckFilename
!= None:
641 CheckFile
= WorkspaceFile(WorkspaceDir
, CheckFilename
)
642 if not os
.path
.isfile(CheckFile
):
643 ContainerFile
= open(ContainerFilename
, 'r').read()
645 LineNo
= GetLineNo(ContainerFile
, Line
)
646 ErrorMsg
= "Can't find file '%s' defined in section '%s'" % (CheckFile
, SectionName
)
647 EdkLogger
.error("Parser", PARSER_ERROR
, ErrorMsg
,
648 File
=ContainerFilename
, Line
=LineNo
, RaiseError
=EdkLogger
.IsRaiseError
)
654 # Find the index of a line in a file
656 # @param FileContent: Search scope
657 # @param Line: Search key
659 # @retval int Index of the line
660 # @retval -1 The line is not found
662 def GetLineNo(FileContent
, Line
, IsIgnoreComment
=True):
663 LineList
= FileContent
.splitlines()
664 for Index
in range(len(LineList
)):
665 if LineList
[Index
].find(Line
) > -1:
667 # Ignore statement in comment
670 if LineList
[Index
].strip()[0] == DataType
.TAB_COMMENT_SPLIT
:
678 # Raise a parser error
680 # @param Line: String which has error
681 # @param Section: Used for error report
682 # @param File: File which has the string
683 # @param Format: Correct format
685 def RaiseParserError(Line
, Section
, File
, Format
='', LineNo
= -1):
687 LineNo
= GetLineNo(open(os
.path
.normpath(File
), 'r').read(), Line
)
688 ErrorMsg
= "Invalid statement '%s' is found in section '%s'" % (Line
, Section
)
690 Format
= "Correct format is " + Format
691 EdkLogger
.error("Parser", PARSER_ERROR
, ErrorMsg
, File
=File
, Line
=LineNo
, ExtraData
=Format
, RaiseError
=EdkLogger
.IsRaiseError
)
695 # Return a full path with workspace dir
697 # @param WorkspaceDir: Workspace dir
698 # @param Filename: Relative file name
700 # @retval string A full path
702 def WorkspaceFile(WorkspaceDir
, Filename
):
703 return os
.path
.join(NormPath(WorkspaceDir
), NormPath(Filename
))
707 # Revmove '"' which startswith and endswith string
709 # @param String: The string need to be splited
711 # @retval String: The string after removed '""'
713 def SplitString(String
):
714 if String
.startswith('\"'):
716 if String
.endswith('\"'):
721 ## Convert To Sql String
723 # 1. Replace "'" with "''" in each item of StringList
725 # @param StringList: A list for strings to be converted
727 def ConvertToSqlString(StringList
):
728 return map(lambda s
: s
.replace("'", "''") , StringList
)
730 ## Convert To Sql String
732 # 1. Replace "'" with "''" in the String
734 # @param String: A String to be converted
736 def ConvertToSqlString2(String
):
737 return String
.replace("'", "''")
740 # Remove comment block
742 def RemoveBlockComment(Lines
):
743 IsFindBlockComment
= False
744 IsFindBlockCode
= False
751 # Remove comment block
753 if Line
.find(DataType
.TAB_COMMENT_EDK_START
) > -1:
754 ReservedLine
= GetSplitList(Line
, DataType
.TAB_COMMENT_EDK_START
, 1)[0]
755 IsFindBlockComment
= True
756 if Line
.find(DataType
.TAB_COMMENT_EDK_END
) > -1:
757 Line
= ReservedLine
+ GetSplitList(Line
, DataType
.TAB_COMMENT_EDK_END
, 1)[1]
759 IsFindBlockComment
= False
760 if IsFindBlockComment
:
764 NewLines
.append(Line
)
768 # Get String of a List
770 def GetStringOfList(List
, Split
=' '):
771 if type(List
) != type([]):
775 Str
= Str
+ Item
+ Split
780 # Get HelpTextList from HelpTextClassList
782 def GetHelpTextList(HelpTextClassList
):
784 if HelpTextClassList
:
785 for HelpText
in HelpTextClassList
:
786 if HelpText
.String
.endswith('\n'):
787 HelpText
.String
= HelpText
.String
[0: len(HelpText
.String
) - len('\n')]
788 List
.extend(HelpText
.String
.split('\n'))
792 def StringToArray(String
):
793 if isinstance(String
, unicode):
794 if len(unicode) == 0:
795 return "{0x00, 0x00}"
796 return "{%s, 0x00, 0x00}" % ", ".join(["0x%02x, 0x00" % ord(C
) for C
in String
])
797 elif String
.startswith('L"'):
798 if String
== "L\"\"":
799 return "{0x00, 0x00}"
801 return "{%s, 0x00, 0x00}" % ", ".join(["0x%02x, 0x00" % ord(C
) for C
in String
[2:-1]])
802 elif String
.startswith('"'):
806 StringLen
= len(String
[1:-1])
808 return "{%s, 0x00}" % ", ".join(["0x%02x" % ord(C
) for C
in String
[1:-1]])
810 return "{%s, 0x00,0x00}" % ", ".join(["0x%02x" % ord(C
) for C
in String
[1:-1]])
811 elif String
.startswith('{'):
812 StringLen
= len(String
.split(","))
814 return "{%s, 0x00}" % ", ".join([ C
for C
in String
[1:-1].split(',')])
816 return "{%s}" % ", ".join([ C
for C
in String
[1:-1].split(',')])
819 if len(String
.split()) % 2:
820 return '{%s, 0}' % ', '.join(String
.split())
822 return '{%s, 0,0}' % ', '.join(String
.split())
824 def StringArrayLength(String
):
825 if isinstance(String
, unicode):
826 return (len(String
) + 1) * 2 + 1;
827 elif String
.startswith('L"'):
828 return (len(String
) - 3 + 1) * 2
829 elif String
.startswith('"'):
830 return (len(String
) - 2 + 1)
832 return len(String
.split()) + 1
834 def RemoveDupOption(OptionString
, Which
="/I", Against
=None):
835 OptionList
= OptionString
.split()
839 for Index
in range(len(OptionList
)):
840 Opt
= OptionList
[Index
]
841 if not Opt
.startswith(Which
):
843 if len(Opt
) > len(Which
):
844 Val
= Opt
[len(Which
):]
848 OptionList
[Index
] = ""
850 ValueList
.append(Val
)
851 return " ".join(OptionList
)
855 # This acts like the main() function for the script, unless it is 'import'ed into another
858 if __name__
== '__main__':