X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FAutoGen%2FUniClassObject.py;h=5a3c2547783b3ff38b4bb41c8536672ae93beb3c;hb=b1aff264bf6a007a27d0ebadcce96b72b727c3c8;hp=242402dfaeeb511f7bbf4420cbd7feafc8fe4d6f;hpb=4231a8193ec0d52df7e0a101d96c51b1a2b7a996;p=mirror_edk2.git diff --git a/BaseTools/Source/Python/AutoGen/UniClassObject.py b/BaseTools/Source/Python/AutoGen/UniClassObject.py index 242402dfae..5a3c254778 100644 --- a/BaseTools/Source/Python/AutoGen/UniClassObject.py +++ b/BaseTools/Source/Python/AutoGen/UniClassObject.py @@ -21,7 +21,7 @@ import distutils.util import Common.EdkLogger as EdkLogger import StringIO from Common.BuildToolError import * -from Common.String import GetLineNo +from Common.StringUtils import GetLineNo from Common.Misc import PathClass from Common.LongFilePathSupport import LongFilePath from Common.GlobalData import * @@ -118,8 +118,6 @@ LangConvTable = {'eng':'en', 'fra':'fr', \ # @retval LangName: Valid lanugage code in RFC 4646 format or None # def GetLanguageCode(LangName, IsCompatibleMode, File): - global LangConvTable - length = len(LangName) if IsCompatibleMode: if length == 3 and LangName.isalpha(): @@ -218,6 +216,19 @@ class StringDefClassObject(object): self.StringValueByteList = UniToHexList(self.StringValue) self.Length = len(self.StringValueByteList) +def StripComments(Line): + Comment = u'//' + CommentPos = Line.find(Comment) + while CommentPos >= 0: + # if there are non matched quotes before the comment header + # then we are in the middle of a string + # but we need to ignore the escaped quotes and backslashes. + if ((Line.count(u'"', 0, CommentPos) - Line.count(u'\\"', 0, CommentPos)) & 1) == 1: + CommentPos = Line.find (Comment, CommentPos + 1) + else: + return Line[:CommentPos].strip() + return Line.strip() + ## UniFileClassObject # # A structure for .uni file definition @@ -242,7 +253,7 @@ class UniFileClassObject(object): Lang = distutils.util.split_quoted((Line.split(u"//")[0])) if len(Lang) != 3: try: - FileIn = self.OpenUniFile(LongFilePath(File.Path)) + FileIn = UniFileClassObject.OpenUniFile(LongFilePath(File.Path)) except UnicodeError, X: EdkLogger.error("build", FILE_READ_FAILURE, "File read failure: %s" % str(X), ExtraData=File); except: @@ -286,7 +297,8 @@ class UniFileClassObject(object): self.OrderedStringDict[LangName][Item.StringName] = len(self.OrderedStringList[LangName]) - 1 return True - def OpenUniFile(self, FileName): + @staticmethod + def OpenUniFile(FileName): # # Read file # @@ -305,14 +317,15 @@ class UniFileClassObject(object): FileIn.startswith(codecs.BOM_UTF16_LE)): Encoding = 'utf-16' - self.VerifyUcs2Data(FileIn, FileName, Encoding) + UniFileClassObject.VerifyUcs2Data(FileIn, FileName, Encoding) UniFile = StringIO.StringIO(FileIn) Info = codecs.lookup(Encoding) (Reader, Writer) = (Info.streamreader, Info.streamwriter) return codecs.StreamReaderWriter(UniFile, Reader, Writer) - def VerifyUcs2Data(self, FileIn, FileName, Encoding): + @staticmethod + def VerifyUcs2Data(FileIn, FileName, Encoding): Ucs2Info = codecs.lookup('ucs-2') # # Convert to unicode @@ -351,8 +364,8 @@ class UniFileClassObject(object): Name = Item.split()[1] # Check the string name if Name != '': - MatchString = re.match('^[a-zA-Z][a-zA-Z0-9_]*$', Name, re.UNICODE) - if MatchString is None or MatchString.end(0) != len(Name): + MatchString = gIdentifierPattern.match(Name) + if MatchString is None: EdkLogger.error('Unicode File Parser', FORMAT_INVALID, 'The string token name %s defined in UNI file %s contains the invalid character.' % (Name, self.File)) LanguageList = Item.split(u'#language ') for IndexI in range(len(LanguageList)): @@ -371,20 +384,6 @@ class UniFileClassObject(object): FileName = Item[Item.find(u'#include ') + len(u'#include ') :Item.find(u' ', len(u'#include '))][1:-1] self.LoadUniFile(FileName) - def StripComments(self, Line): - Comment = u'//' - CommentPos = Line.find(Comment) - while CommentPos >= 0: - # if there are non matched quotes before the comment header - # then we are in the middle of a string - # but we need to ignore the escaped quotes and backslashes. - if ((Line.count(u'"', 0, CommentPos) - Line.count(u'\\"', 0, CommentPos)) & 1) == 1: - CommentPos = Line.find (Comment, CommentPos + 1) - else: - return Line[:CommentPos].strip() - return Line.strip() - - # # Pre-process before parse .uni file # @@ -393,7 +392,7 @@ class UniFileClassObject(object): EdkLogger.error("Unicode File Parser", FILE_NOT_FOUND, ExtraData=File.Path) try: - FileIn = self.OpenUniFile(LongFilePath(File.Path)) + FileIn = UniFileClassObject.OpenUniFile(LongFilePath(File.Path)) except UnicodeError, X: EdkLogger.error("build", FILE_READ_FAILURE, "File read failure: %s" % str(X), ExtraData=File.Path); except: @@ -406,7 +405,7 @@ class UniFileClassObject(object): for Line in FileIn: Line = Line.strip() Line = Line.replace(u'\\\\', BACK_SLASH_PLACEHOLDER) - Line = self.StripComments(Line) + Line = StripComments(Line) # # Ignore empty line @@ -521,8 +520,8 @@ class UniFileClassObject(object): Language = GetLanguageCode(Language, self.IsCompatibleMode, self.File) # Check the string name if not self.IsCompatibleMode and Name != '': - MatchString = re.match('^[a-zA-Z][a-zA-Z0-9_]*$', Name, re.UNICODE) - if MatchString is None or MatchString.end(0) != len(Name): + MatchString = gIdentifierPattern.match(Name) + if MatchString is None: EdkLogger.error('Unicode File Parser', FORMAT_INVALID, 'The string token name %s defined in UNI file %s contains the invalid character.' % (Name, self.File)) self.AddStringToList(Name, Language, Value) continue