You've already forked lazarus-ccr
fpspreadsheet: Simplify ValidXMLText().
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8573 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@@ -47,7 +47,7 @@ function GetNodeValue(ANode: TDOMNode): String;
|
|||||||
function LineEndingToBR(const AText: String): String;
|
function LineEndingToBR(const AText: String): String;
|
||||||
function UTF8TextToXMLText(AText: string; ProcessLineEndings: Boolean = false): string;
|
function UTF8TextToXMLText(AText: string; ProcessLineEndings: Boolean = false): string;
|
||||||
function ValidXMLText(var AText: string; ReplaceSpecialChars: Boolean = true;
|
function ValidXMLText(var AText: string; ReplaceSpecialChars: Boolean = true;
|
||||||
ProcessLineEndings: Boolean = false): Boolean;
|
ProcessLineEndings: Boolean = false; InvalidUTF8Replacement: String = #$E2#$8E#$95): Boolean;
|
||||||
function XMLQuote(AText: String): String;
|
function XMLQuote(AText: String): String;
|
||||||
|
|
||||||
procedure UnzipFile(AZipFileName, AZippedFile, ADestFolder: String);
|
procedure UnzipFile(AZipFileName, AZippedFile, ADestFolder: String);
|
||||||
@@ -202,30 +202,15 @@ end;
|
|||||||
codes (e.g. '>' --> '>')
|
codes (e.g. '>' --> '>')
|
||||||
@param ProcessLineEndings If TRUE line ending characters are replaced by
|
@param ProcessLineEndings If TRUE line ending characters are replaced by
|
||||||
their HTML entities.
|
their HTML entities.
|
||||||
|
@param InvalidUTF8Replacement UTF8-character inserted for a malformed UTF8 codepoint.
|
||||||
@return FALSE if characters < #32 were replaced, TRUE otherwise.
|
@return FALSE if characters < #32 were replaced, TRUE otherwise.
|
||||||
-------------------------------------------------------------------------------}
|
-------------------------------------------------------------------------------}
|
||||||
function ValidXMLText(var AText: string;
|
function ValidXMLText(var AText: string;
|
||||||
ReplaceSpecialChars: Boolean = true;
|
ReplaceSpecialChars: Boolean = true;
|
||||||
ProcessLineEndings: Boolean = false): Boolean;
|
ProcessLineEndings: Boolean = false;
|
||||||
const
|
InvalidUTF8Replacement: String = #$E2#$8E#$95): Boolean;
|
||||||
BOX = #$E2#$8E#$95;
|
|
||||||
var
|
|
||||||
i: Integer;
|
|
||||||
P: PChar;
|
|
||||||
begin
|
begin
|
||||||
Result := true;
|
Result := ValidUTF8Text(AText, InvalidUTF8Replacement);
|
||||||
|
|
||||||
repeat
|
|
||||||
P := PChar(AText);
|
|
||||||
i := FindInvalidUTF8CodePoint(P, Length(AText), true);
|
|
||||||
if i >= 0 then
|
|
||||||
begin
|
|
||||||
Delete(AText, i+1, 1);
|
|
||||||
Insert(BOX, AText, i+1);
|
|
||||||
Result := false;
|
|
||||||
end;
|
|
||||||
until (i < 0);
|
|
||||||
|
|
||||||
if ReplaceSpecialChars then
|
if ReplaceSpecialChars then
|
||||||
AText := UTF8TextToXMLText(AText, ProcessLineEndings);
|
AText := UTF8TextToXMLText(AText, ProcessLineEndings);
|
||||||
end;
|
end;
|
||||||
|
Reference in New Issue
Block a user