mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-26 16:11:04 +02:00
fcl-css: fixed ~= searching only words separated by whitespace
This commit is contained in:
parent
3e9fd9073f
commit
a6dd77e32a
@ -202,9 +202,7 @@ type
|
|||||||
function SelectorArrayMatches(anArray: TCSSArrayElement; const TestNode: TCSSNode): TCSSSpecifity; virtual;
|
function SelectorArrayMatches(anArray: TCSSArrayElement; const TestNode: TCSSNode): TCSSSpecifity; virtual;
|
||||||
function SelectorArrayBinaryMatches(aBinary: TCSSBinaryElement; const TestNode: TCSSNode): TCSSSpecifity; virtual;
|
function SelectorArrayBinaryMatches(aBinary: TCSSBinaryElement; const TestNode: TCSSNode): TCSSSpecifity; virtual;
|
||||||
function ComputeValue(El: TCSSElement): TCSSString; virtual;
|
function ComputeValue(El: TCSSElement): TCSSString; virtual;
|
||||||
function IsWordBegin(const s: TCSSString; p: integer): boolean; virtual;
|
function PosWord(const SearchWord, Words: TCSSString): integer; virtual;
|
||||||
function IsWordEnd(const s: TCSSString; p: integer): boolean; virtual;
|
|
||||||
function PosWord(const aSearch, aText: TCSSString): integer; virtual;
|
|
||||||
procedure MergeProperty(El: TCSSElement; Specifity: TCSSSpecifity); virtual;
|
procedure MergeProperty(El: TCSSElement; Specifity: TCSSSpecifity); virtual;
|
||||||
function ResolveIdentifier(El: TCSSIdentifierElement; Kind: TCSSNumericalIDKind): TCSSNumericalID; virtual;
|
function ResolveIdentifier(El: TCSSIdentifierElement; Kind: TCSSNumericalIDKind): TCSSNumericalID; virtual;
|
||||||
procedure AddElData(El: TCSSElement; ElData: TCSSElResolverData); virtual;
|
procedure AddElData(El: TCSSElement; ElData: TCSSElResolverData); virtual;
|
||||||
@ -693,42 +691,32 @@ begin
|
|||||||
DoError(20220910235106,'TCSSResolver.ComputeValue not supported',El);
|
DoError(20220910235106,'TCSSResolver.ComputeValue not supported',El);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TCSSResolver.PosWord(const SearchWord, Words: TCSSString): integer;
|
||||||
|
// attribute selector ~=
|
||||||
const
|
const
|
||||||
WordChar = ['a'..'z','A'..'Z','0'..'9',#192..#255];
|
Whitespace = [#9,#10,#12,#13,' '];
|
||||||
|
var
|
||||||
function TCSSResolver.IsWordBegin(const s: TCSSString; p: integer): boolean;
|
WordsLen, SearchLen: SizeInt;
|
||||||
|
p, WordStart: Integer;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
if SearchWord='' then exit(0);
|
||||||
if p<1 then exit;
|
if Words='' then exit(0);
|
||||||
if p>length(s) then exit;
|
WordsLen:=length(Words);
|
||||||
// simple check. ToDo: check unicode
|
SearchLen:=length(SearchWord);
|
||||||
if (p>1) and (s[p-1] in WordChar) then exit;
|
p:=1;
|
||||||
if not (s[p] in WordChar) then exit;
|
repeat
|
||||||
Result:=true;
|
repeat
|
||||||
end;
|
if p>WordsLen then
|
||||||
|
exit(0);
|
||||||
function TCSSResolver.IsWordEnd(const s: TCSSString; p: integer): boolean;
|
if not (Words[p] in Whitespace) then break;
|
||||||
begin
|
inc(p);
|
||||||
Result:=false;
|
until false;
|
||||||
if p<=1 then exit;
|
WordStart:=p;
|
||||||
if p>length(s)+1 then exit;
|
while (p<=WordsLen) and not (Words[p] in Whitespace) do
|
||||||
// simple check. ToDo: check unicode
|
inc(p);
|
||||||
if (p>1) and not (s[p-1] in WordChar) then exit;
|
if (p-WordStart=SearchLen) and CompareMem(@SearchWord[1],@Words[WordStart],SearchLen) then
|
||||||
if (s[p] in WordChar) then exit;
|
exit(WordStart);
|
||||||
Result:=true;
|
until p>WordsLen;
|
||||||
end;
|
|
||||||
|
|
||||||
function TCSSResolver.PosWord(const aSearch, aText: TCSSString): integer;
|
|
||||||
begin
|
|
||||||
if aSearch='' then exit(0);
|
|
||||||
if aText='' then exit(0);
|
|
||||||
Result:=Pos(aSearch,aText);
|
|
||||||
while Result>0 do
|
|
||||||
begin
|
|
||||||
if IsWordBegin(aText,Result) and IsWordEnd(aText,Result+length(aSearch)) then
|
|
||||||
exit;
|
|
||||||
Result:=PosEx(aSearch,aText,Result+1);
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCSSResolver.MergeProperty(El: TCSSElement; Specifity: TCSSSpecifity);
|
procedure TCSSResolver.MergeProperty(El: TCSSElement; Specifity: TCSSSpecifity);
|
||||||
|
Loading…
Reference in New Issue
Block a user