fpspreadsheet: Fix usage of html entities in ExcelXML format.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4581 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2016-03-20 09:51:49 +00:00
parent e886dec4de
commit 279a8cf1e7

View File

@ -16,6 +16,7 @@ type
function CleanHTMLString(AText: String): String; function CleanHTMLString(AText: String): String;
function IsHTMLEntity(AText: PChar; out AEntity: TsHTMLEntity): Boolean; function IsHTMLEntity(AText: PChar; out AEntity: TsHTMLEntity): Boolean;
function RemoveHTMLEntities(const AText: String): String;
type type
TsHTMLAttr = class TsHTMLAttr = class
@ -440,7 +441,8 @@ begin
Continue; Continue;
end; end;
end; end;
else Result := Result + ch; else
Result := Result + ch;
end; end;
inc(P); inc(P);
end; end;
@ -450,6 +452,34 @@ begin
if hasEndSpace then Result := Result + ' '; if hasEndSpace then Result := Result + ' ';
end; end;
function RemoveHTMLEntities(const AText: String): String;
var
ent: TsHTMLEntity;
P: PChar;
ch: AnsiChar;
begin
Result := '';
P := @AText[1];
while (P^ <> #0) do begin
ch := P^;
case ch of
'&': begin
inc(P);
if (P <> nil) and IsHTMLEntity(P, ent) then
begin
Result := Result + ent.Ch;
inc(P, Length(ent.E));
end else
begin
Result := Result + '&';
Continue;
end;
end;
else Result := Result + ch;
end;
inc(P);
end;
end;
{==============================================================================} {==============================================================================}
{ TsHTMLAttr } { TsHTMLAttr }
@ -886,7 +916,8 @@ end;
procedure TsHTMLAnalyzer.TextFoundHandler(AText: String); procedure TsHTMLAnalyzer.TextFoundHandler(AText: String);
begin begin
if not FPreserveSpaces then if not FPreserveSpaces then
AText := CleanHTMLString(AText); AText := CleanHTMLString(AText) else
AText := RemoveHTMLEntities(AText);
if AText <> '' then if AText <> '' then
begin begin
if FPlainText = '' then if FPlainText = '' then