From 08dd311f5dc735c595d39faf2e6f7e2810bb79a9 Mon Sep 17 00:00:00 2001 From: lgao4 Date: Mon, 11 Oct 2010 06:26:52 +0000 Subject: Sync EDKII BaseTools to BaseTools project r2065. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10915 6f19259b-4bc3-4df7-8a09-765794883524 --- BaseTools/Source/Python/Common/String.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 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 283e913b3b..195fa5c6ca 100644 --- a/BaseTools/Source/Python/Common/String.py +++ b/BaseTools/Source/Python/Common/String.py @@ -23,6 +23,9 @@ import EdkLogger as EdkLogger from GlobalData import * from BuildToolError import * +gHexVerPatt = re.compile('0x[a-f0-9]{4}[a-f0-9]{4}$',re.IGNORECASE) +gHumanReadableVerPatt = re.compile(r'([1-9][0-9]*|0)\.[0-9]{1,2}$') + ## GetSplitValueList # # Get a value list from a string with multiple values splited with SplitTag @@ -377,6 +380,34 @@ def GetDefineValue(String, Key, CommentCharacter): String = CleanString(String) return String[String.find(Key + ' ') + len(Key + ' ') : ] +## GetHexVerValue +# +# Get a Hex Version Value +# +# @param VerString: The version string to be parsed +# +# +# @retval: If VerString is incorrectly formatted, return "None" which will break the build. +# If VerString is correctly formatted, return a Hex value of the Version Number (0xmmmmnnnn) +# where mmmm is the major number and nnnn is the adjusted minor number. +# +def GetHexVerValue(VerString): + VerString = CleanString(VerString) + + if gHumanReadableVerPatt.match(VerString): + ValueList = VerString.split('.') + Major = ValueList[0] + Minor = ValueList[1] + if len(Minor) == 1: + Minor += '0' + DeciValue = (int(Major) << 16) + int(Minor); + return "0x%08x"%DeciValue + elif gHexVerPatt.match(VerString): + return VerString + else: + return None + + ## GetSingleValueOfKeyFromLines # # Parse multiple strings as below to get value of each definition line -- cgit v1.2.3