"""Parse link title"""from..common.utilsimportunescapeAll,charCodeAt,stripEscapeclass_Result:__slots__=("ok","pos","lines","str")def__init__(self):self.ok=Falseself.pos=0self.lines=0self.str=""def__str__(self):returnself.str
[文档]defparseLinkTitle(string:str,pos:int,maximum:int)->_Result:lines=0start=posresult=_Result()ifpos>=maximum:returnresultmarker=charCodeAt(string,pos)# /* " */ /* ' */ /* ( */ifmarker!=0x22andmarker!=0x27andmarker!=0x28:returnresultpos+=1# if opening marker is "(", switch it to closing marker ")"ifmarker==0x28:marker=0x29whilepos<maximum:code=charCodeAt(string,pos)ifcode==marker:title=string[start+1:pos]title=unescapeAll(stripEscape(title))result.pos=pos+1result.lines=linesresult.str=titleresult.ok=Truereturnresultelifcode==0x28andmarker==0x29:# /* ( */ /* ) */returnresultelifcode==0x0A:lines+=1elifcode==0x5Candpos+1<maximum:# /* \ */pos+=1ifcharCodeAt(string,pos)==0x0A:lines+=1pos+=1returnresult