]>
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):
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
]
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 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
392 LineParts
= Line
.split(CommentCharacter
, 1);
394 # remove whitespace again
396 Line
= LineParts
[0].strip();
397 if len(LineParts
) > 1:
398 Comment
= LineParts
[1].strip()
399 # Remove prefixed and trailing comment characters
402 while Start
< End
and Comment
.startswith(CommentCharacter
, Start
, End
):
404 while End
>= 0 and Comment
.endswith(CommentCharacter
, Start
, End
):
406 Comment
= Comment
[Start
:End
]
407 Comment
= Comment
.strip()
413 ## GetMultipleValuesOfKeyFromLines
415 # Parse multiple strings to clean comment and spaces
416 # The result is saved to KeyValues
418 # @param Lines: The content to be parsed
419 # @param Key: Reserved
420 # @param KeyValues: To store data after parsing
421 # @param CommentCharacter: Comment char, used to ignore comment content
423 # @retval True Successfully executed
425 def GetMultipleValuesOfKeyFromLines(Lines
, Key
, KeyValues
, CommentCharacter
):
426 Lines
= Lines
.split(DataType
.TAB_SECTION_END
, 1)[1]
427 LineList
= Lines
.split('\n')
428 for Line
in LineList
:
429 Line
= CleanString(Line
, CommentCharacter
)
430 if Line
!= '' and Line
[0] != CommentCharacter
:
437 # Parse a DEFINE statement to get defined value
440 # @param String: The content to be parsed
441 # @param Key: The key of DEFINE statement
442 # @param CommentCharacter: Comment char, used to ignore comment content
444 # @retval string The defined value
446 def GetDefineValue(String
, Key
, CommentCharacter
):
447 String
= CleanString(String
)
448 return String
[String
.find(Key
+ ' ') + len(Key
+ ' ') : ]
452 # Get a Hex Version Value
454 # @param VerString: The version string to be parsed
457 # @retval: If VerString is incorrectly formatted, return "None" which will break the build.
458 # If VerString is correctly formatted, return a Hex value of the Version Number (0xmmmmnnnn)
459 # where mmmm is the major number and nnnn is the adjusted minor number.
461 def GetHexVerValue(VerString
):
462 VerString
= CleanString(VerString
)
464 if gHumanReadableVerPatt
.match(VerString
):
465 ValueList
= VerString
.split('.')
470 DeciValue
= (int(Major
) << 16) + int(Minor
);
471 return "0x%08x" % DeciValue
472 elif gHexVerPatt
.match(VerString
):
478 ## GetSingleValueOfKeyFromLines
480 # Parse multiple strings as below to get value of each definition line
483 # The result is saved to Dictionary
485 # @param Lines: The content to be parsed
486 # @param Dictionary: To store data after parsing
487 # @param CommentCharacter: Comment char, be used to ignore comment content
488 # @param KeySplitCharacter: Key split char, between key name and key value. Key1 = Value1, '=' is the key split char
489 # @param ValueSplitFlag: Value split flag, be used to decide if has multiple values
490 # @param ValueSplitCharacter: Value split char, be used to split multiple values. Key1 = Value1|Value2, '|' is the value split char
492 # @retval True Successfully executed
494 def GetSingleValueOfKeyFromLines(Lines
, Dictionary
, CommentCharacter
, KeySplitCharacter
, ValueSplitFlag
, ValueSplitCharacter
):
495 Lines
= Lines
.split('\n')
503 # Handle DEFINE and SPEC
505 if Line
.find(DataType
.TAB_INF_DEFINES_DEFINE
+ ' ') > -1:
506 if '' in DefineValues
:
507 DefineValues
.remove('')
508 DefineValues
.append(GetDefineValue(Line
, DataType
.TAB_INF_DEFINES_DEFINE
, CommentCharacter
))
510 if Line
.find(DataType
.TAB_INF_DEFINES_SPEC
+ ' ') > -1:
512 SpecValues
.remove('')
513 SpecValues
.append(GetDefineValue(Line
, DataType
.TAB_INF_DEFINES_SPEC
, CommentCharacter
))
519 LineList
= Line
.split(KeySplitCharacter
, 1)
520 if len(LineList
) >= 2:
521 Key
= LineList
[0].split()
522 if len(Key
) == 1 and Key
[0][0] != CommentCharacter
:
524 # Remove comments and white spaces
526 LineList
[1] = CleanString(LineList
[1], CommentCharacter
)
528 Value
= map(string
.strip
, LineList
[1].split(ValueSplitCharacter
))
530 Value
= CleanString(LineList
[1], CommentCharacter
).splitlines()
532 if Key
[0] in Dictionary
:
533 if Key
[0] not in Keys
:
534 Dictionary
[Key
[0]] = Value
537 Dictionary
[Key
[0]].extend(Value
)
539 Dictionary
[DataType
.TAB_INF_DEFINES_MACRO
][Key
[0]] = Value
[0]
541 if DefineValues
== []:
545 Dictionary
[DataType
.TAB_INF_DEFINES_DEFINE
] = DefineValues
546 Dictionary
[DataType
.TAB_INF_DEFINES_SPEC
] = SpecValues
550 ## The content to be parsed
552 # Do pre-check for a file before it is parsed
556 # @param FileName: Used for error report
557 # @param FileContent: File content to be parsed
558 # @param SupSectionTag: Used for error report
560 def PreCheck(FileName
, FileContent
, SupSectionTag
):
564 for Line
in FileContent
.splitlines():
569 Line
= CleanString(Line
)
572 # Remove commented line
574 if Line
.find(DataType
.TAB_COMMA_SPLIT
) == 0:
579 if Line
.find('$') > -1:
580 if Line
.find('$(') < 0 or Line
.find(')') < 0:
581 EdkLogger
.error("Parser", FORMAT_INVALID
, Line
=LineNo
, File
=FileName
, RaiseError
=EdkLogger
.IsRaiseError
)
586 if Line
.find('[') > -1 or Line
.find(']') > -1:
588 # Only get one '[' or one ']'
590 if not (Line
.find('[') > -1 and Line
.find(']') > -1):
591 EdkLogger
.error("Parser", FORMAT_INVALID
, Line
=LineNo
, File
=FileName
, RaiseError
=EdkLogger
.IsRaiseError
)
594 # Regenerate FileContent
596 NewFileContent
= NewFileContent
+ Line
+ '\r\n'
599 EdkLogger
.error("Parser", FORMAT_INVALID
, Line
=LineNo
, File
=FileName
, RaiseError
=EdkLogger
.IsRaiseError
)
601 return NewFileContent
605 # Check if the Filename is including ExtName
606 # Return True if it exists
607 # Raise a error message if it not exists
609 # @param CheckFilename: Name of the file to be checked
610 # @param ExtName: Ext name of the file to be checked
611 # @param ContainerFilename: The container file which describes the file to be checked, used for error report
612 # @param SectionName: Used for error report
613 # @param Line: The line in container file which defines the file to be checked
615 # @retval True The file type is correct
617 def CheckFileType(CheckFilename
, ExtName
, ContainerFilename
, SectionName
, Line
, LineNo
= -1):
618 if CheckFilename
!= '' and CheckFilename
!= None:
619 (Root
, Ext
) = os
.path
.splitext(CheckFilename
)
620 if Ext
.upper() != ExtName
.upper():
621 ContainerFile
= open(ContainerFilename
, 'r').read()
623 LineNo
= GetLineNo(ContainerFile
, Line
)
624 ErrorMsg
= "Invalid %s. '%s' is found, but '%s' file is needed" % (SectionName
, CheckFilename
, ExtName
)
625 EdkLogger
.error("Parser", PARSER_ERROR
, ErrorMsg
, Line
=LineNo
,
626 File
=ContainerFilename
, RaiseError
=EdkLogger
.IsRaiseError
)
632 # Check if the file exists
633 # Return True if it exists
634 # Raise a error message if it not exists
636 # @param CheckFilename: Name of the file to be checked
637 # @param WorkspaceDir: Current workspace dir
638 # @param ContainerFilename: The container file which describes the file to be checked, used for error report
639 # @param SectionName: Used for error report
640 # @param Line: The line in container file which defines the file to be checked
642 # @retval The file full path if the file exists
644 def CheckFileExist(WorkspaceDir
, CheckFilename
, ContainerFilename
, SectionName
, Line
, LineNo
= -1):
646 if CheckFilename
!= '' and CheckFilename
!= None:
647 CheckFile
= WorkspaceFile(WorkspaceDir
, CheckFilename
)
648 if not os
.path
.isfile(CheckFile
):
649 ContainerFile
= open(ContainerFilename
, 'r').read()
651 LineNo
= GetLineNo(ContainerFile
, Line
)
652 ErrorMsg
= "Can't find file '%s' defined in section '%s'" % (CheckFile
, SectionName
)
653 EdkLogger
.error("Parser", PARSER_ERROR
, ErrorMsg
,
654 File
=ContainerFilename
, Line
=LineNo
, RaiseError
=EdkLogger
.IsRaiseError
)
660 # Find the index of a line in a file
662 # @param FileContent: Search scope
663 # @param Line: Search key
665 # @retval int Index of the line
666 # @retval -1 The line is not found
668 def GetLineNo(FileContent
, Line
, IsIgnoreComment
=True):
669 LineList
= FileContent
.splitlines()
670 for Index
in range(len(LineList
)):
671 if LineList
[Index
].find(Line
) > -1:
673 # Ignore statement in comment
676 if LineList
[Index
].strip()[0] == DataType
.TAB_COMMENT_SPLIT
:
684 # Raise a parser error
686 # @param Line: String which has error
687 # @param Section: Used for error report
688 # @param File: File which has the string
689 # @param Format: Correct format
691 def RaiseParserError(Line
, Section
, File
, Format
='', LineNo
= -1):
693 LineNo
= GetLineNo(open(os
.path
.normpath(File
), 'r').read(), Line
)
694 ErrorMsg
= "Invalid statement '%s' is found in section '%s'" % (Line
, Section
)
696 Format
= "Correct format is " + Format
697 EdkLogger
.error("Parser", PARSER_ERROR
, ErrorMsg
, File
=File
, Line
=LineNo
, ExtraData
=Format
, RaiseError
=EdkLogger
.IsRaiseError
)
701 # Return a full path with workspace dir
703 # @param WorkspaceDir: Workspace dir
704 # @param Filename: Relative file name
706 # @retval string A full path
708 def WorkspaceFile(WorkspaceDir
, Filename
):
709 return os
.path
.join(NormPath(WorkspaceDir
), NormPath(Filename
))
713 # Revmove '"' which startswith and endswith string
715 # @param String: The string need to be splited
717 # @retval String: The string after removed '""'
719 def SplitString(String
):
720 if String
.startswith('\"'):
722 if String
.endswith('\"'):
727 ## Convert To Sql String
729 # 1. Replace "'" with "''" in each item of StringList
731 # @param StringList: A list for strings to be converted
733 def ConvertToSqlString(StringList
):
734 return map(lambda s
: s
.replace("'", "''") , StringList
)
736 ## Convert To Sql String
738 # 1. Replace "'" with "''" in the String
740 # @param String: A String to be converted
742 def ConvertToSqlString2(String
):
743 return String
.replace("'", "''")
746 # Remove comment block
748 def RemoveBlockComment(Lines
):
749 IsFindBlockComment
= False
750 IsFindBlockCode
= False
757 # Remove comment block
759 if Line
.find(DataType
.TAB_COMMENT_EDK_START
) > -1:
760 ReservedLine
= GetSplitList(Line
, DataType
.TAB_COMMENT_EDK_START
, 1)[0]
761 IsFindBlockComment
= True
762 if Line
.find(DataType
.TAB_COMMENT_EDK_END
) > -1:
763 Line
= ReservedLine
+ GetSplitList(Line
, DataType
.TAB_COMMENT_EDK_END
, 1)[1]
765 IsFindBlockComment
= False
766 if IsFindBlockComment
:
770 NewLines
.append(Line
)
774 # Get String of a List
776 def GetStringOfList(List
, Split
=' '):
777 if type(List
) != type([]):
781 Str
= Str
+ Item
+ Split
786 # Get HelpTextList from HelpTextClassList
788 def GetHelpTextList(HelpTextClassList
):
790 if HelpTextClassList
:
791 for HelpText
in HelpTextClassList
:
792 if HelpText
.String
.endswith('\n'):
793 HelpText
.String
= HelpText
.String
[0: len(HelpText
.String
) - len('\n')]
794 List
.extend(HelpText
.String
.split('\n'))
798 def StringToArray(String
):
799 if isinstance(String
, unicode):
800 if len(unicode) == 0:
801 return "{0x00, 0x00}"
802 return "{%s, 0x00, 0x00}" % ", ".join(["0x%02x, 0x00" % ord(C
) for C
in String
])
803 elif String
.startswith('L"'):
804 if String
== "L\"\"":
805 return "{0x00, 0x00}"
807 return "{%s, 0x00, 0x00}" % ", ".join(["0x%02x, 0x00" % ord(C
) for C
in String
[2:-1]])
808 elif String
.startswith('"'):
812 return "{%s, 0x00}" % ", ".join(["0x%02x" % ord(C
) for C
in String
[1:-1]])
814 return '{%s, 0}' % ', '.join(String
.split())
816 def StringArrayLength(String
):
817 if isinstance(String
, unicode):
818 return (len(String
) + 1) * 2 + 1;
819 elif String
.startswith('L"'):
820 return (len(String
) - 3 + 1) * 2
821 elif String
.startswith('"'):
822 return (len(String
) - 2 + 1)
824 return len(String
.split()) + 1
826 def RemoveDupOption(OptionString
, Which
="/I", Against
=None):
827 OptionList
= OptionString
.split()
831 for Index
in range(len(OptionList
)):
832 Opt
= OptionList
[Index
]
833 if not Opt
.startswith(Which
):
835 if len(Opt
) > len(Which
):
836 Val
= Opt
[len(Which
):]
840 OptionList
[Index
] = ""
842 ValueList
.append(Val
)
843 return " ".join(OptionList
)
847 # This acts like the main() function for the script, unless it is 'import'ed into another
850 if __name__
== '__main__':