summaryrefslogtreecommitdiffstats
path: root/BaseTools
diff options
context:
space:
mode:
authorCarsey, Jaben </o=Intel/ou=Americas01/cn=Workers/cn=Carsey, Jaben>2018-03-30 08:19:30 +0800
committerYonghong Zhu <yonghong.zhu@intel.com>2018-04-03 17:37:33 +0800
commitcfbe3c3500a64e218e7d357dacb18d8b95eddfec (patch)
treefb5e71b59316627e6bc8362902b8ffc697cf3372 /BaseTools
parent147a656b3414667aeafdad0a8fd5504ddad96367 (diff)
downloadedk2-cfbe3c3500a64e218e7d357dacb18d8b95eddfec.tar.gz
edk2-cfbe3c3500a64e218e7d357dacb18d8b95eddfec.tar.bz2
edk2-cfbe3c3500a64e218e7d357dacb18d8b95eddfec.zip
BaseTools: change hex parsing to use built in
use <char> in string.hexdigits instead of custom functions. Cc: Yonghong Zhu <yonghong.zhu@intel.com> Cc: Liming Gao <liming.gao@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jaben Carsey <jaben.carsey@intel.com> Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
Diffstat (limited to 'BaseTools')
-rw-r--r--BaseTools/Source/Python/Common/FdfParserLite.py26
-rw-r--r--BaseTools/Source/Python/GenFds/FdfParser.py26
2 files changed, 8 insertions, 44 deletions
diff --git a/BaseTools/Source/Python/Common/FdfParserLite.py b/BaseTools/Source/Python/Common/FdfParserLite.py
index 255ca9633a..0e35eb484b 100644
--- a/BaseTools/Source/Python/Common/FdfParserLite.py
+++ b/BaseTools/Source/Python/Common/FdfParserLite.py
@@ -23,6 +23,7 @@ from Common.LongFilePathSupport import OpenLongFilePath as open
from Common.MultipleWorkspace import MultipleWorkspace as mws
from Common.RangeExpression import RangeExpression
from Common.GlobalData import *
+import string
##define T_CHAR_SPACE ' '
##define T_CHAR_NULL '\0'
@@ -975,32 +976,13 @@ class FdfParser(object):
self.__GetOneChar()
- ## __HexDigit() method
- #
- # Whether char input is a Hex data bit
- #
- # @param self The object pointer
- # @param TempChar The char to test
- # @retval True The char is a Hex data bit
- # @retval False The char is NOT a Hex data bit
- #
- def __HexDigit(self, TempChar):
- if (TempChar >= 'a' and TempChar <= 'f') or (TempChar >= 'A' and TempChar <= 'F') \
- or (TempChar >= '0' and TempChar <= '9'):
- return True
- else:
- return False
-
def __IsHex(self, HexStr):
if not HexStr.upper().startswith("0X"):
return False
if len(self.__Token) <= 2:
return False
- charList = [c for c in HexStr[2 : ] if not self.__HexDigit( c)]
- if len(charList) == 0:
- return True
- else:
- return False
+ return True if all(x in string.hexdigits for x in HexStr[2:]) else False
+
## __GetNextHexNumber() method
#
# Get next HEX data before a seperator
@@ -3455,7 +3437,7 @@ class FdfParser(object):
raise Warning("expected Component type At Line ", self.FileName, self.CurrentLineNumber)
if self.__Token not in ("FIT", "PAL_B", "PAL_A", "OEM"):
if not self.__Token.startswith("0x") or len(self.__Token) < 3 or len(self.__Token) > 4 or \
- not self.__HexDigit(self.__Token[2]) or not self.__HexDigit(self.__Token[-1]):
+ not self.__Token[2] in string.hexdigits or not self.__Token[-1] in string.hexdigits:
raise Warning("Unknown location type At line ", self.FileName, self.CurrentLineNumber)
CompStatementObj.CompType = self.__Token
diff --git a/BaseTools/Source/Python/GenFds/FdfParser.py b/BaseTools/Source/Python/GenFds/FdfParser.py
index b3f83c072a..4183f318b7 100644
--- a/BaseTools/Source/Python/GenFds/FdfParser.py
+++ b/BaseTools/Source/Python/GenFds/FdfParser.py
@@ -42,6 +42,7 @@ import ComponentStatement
import OptionRom
import OptRomInfStatement
import OptRomFileStatement
+import string
from GenFdsGlobalVariable import GenFdsGlobalVariable
from Common.BuildToolError import *
@@ -1192,32 +1193,13 @@ class FdfParser:
self.__GetOneChar()
- ## __HexDigit() method
- #
- # Whether char input is a Hex data bit
- #
- # @param self The object pointer
- # @param TempChar The char to test
- # @retval True The char is a Hex data bit
- # @retval False The char is NOT a Hex data bit
- #
- def __HexDigit(self, TempChar):
- if (TempChar >= 'a' and TempChar <= 'f') or (TempChar >= 'A' and TempChar <= 'F') \
- or (TempChar >= '0' and TempChar <= '9'):
- return True
- else:
- return False
-
def __IsHex(self, HexStr):
if not HexStr.upper().startswith("0X"):
return False
if len(self.__Token) <= 2:
return False
- charList = [c for c in HexStr[2 : ] if not self.__HexDigit( c)]
- if len(charList) == 0:
- return True
- else:
- return False
+ return True if all(x in string.hexdigits for x in HexStr[2:]) else False
+
## __GetNextHexNumber() method
#
# Get next HEX data before a seperator
@@ -4294,7 +4276,7 @@ class FdfParser:
raise Warning("expected Component type", self.FileName, self.CurrentLineNumber)
if self.__Token not in ("FIT", "PAL_B", "PAL_A", "OEM"):
if not self.__Token.startswith("0x") or len(self.__Token) < 3 or len(self.__Token) > 4 or \
- not self.__HexDigit(self.__Token[2]) or not self.__HexDigit(self.__Token[-1]):
+ not self.__Token[2] in string.hexdigits or not self.__Token[-1] in string.hexdigits:
raise Warning("Unknown location type '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)
CompStatementObj.CompType = self.__Token