mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-17 07:29:21 +02:00
LazUtf8: implement Utf8ReverseString and Utf8RPos. Patch by Bernard Marcelly. Issue #0029817.
git-svn-id: trunk@51927 -
This commit is contained in:
parent
ad8ba1d824
commit
23f36140b5
@ -122,6 +122,9 @@ function UTF8QuotedStr(const S, Quote: string): string;
|
|||||||
//Utf8 version of MidStr is just Utf8Copy with same parameters, so it is not implemented here
|
//Utf8 version of MidStr is just Utf8Copy with same parameters, so it is not implemented here
|
||||||
function Utf8StartsText(const ASubText, AText: string): Boolean;
|
function Utf8StartsText(const ASubText, AText: string): Boolean;
|
||||||
function Utf8EndsText(const ASubText, AText: string): Boolean;
|
function Utf8EndsText(const ASubText, AText: string): Boolean;
|
||||||
|
function Utf8ReverseString(p: PChar; const ByteCount: LongInt): string;
|
||||||
|
function Utf8ReverseString(const AText: string): string; inline;
|
||||||
|
function Utf8RPos(const Substr, Source: string): integer;
|
||||||
|
|
||||||
function UTF8WrapText(S, BreakStr :string; BreakChars :TSysCharSet; MaxCol: integer): string; overload;
|
function UTF8WrapText(S, BreakStr :string; BreakChars :TSysCharSet; MaxCol: integer): string; overload;
|
||||||
function UTF8WrapText(S :string; MaxCol :integer) :string; overload;
|
function UTF8WrapText(S :string; MaxCol :integer) :string; overload;
|
||||||
@ -2839,6 +2842,42 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function Utf8ReverseString(p: PChar; const ByteCount: LongInt): string;
|
||||||
|
var
|
||||||
|
CharLen, rBytePos: LongInt;
|
||||||
|
begin
|
||||||
|
SetLength(Result, ByteCount);
|
||||||
|
rBytePos := ByteCount + 1;
|
||||||
|
while (rBytePos > 1) do
|
||||||
|
begin
|
||||||
|
CharLen:=UTF8CharacterLength(p);
|
||||||
|
Dec(rBytePos, CharLen);
|
||||||
|
Move(p^, Result[rBytePos], CharLen);
|
||||||
|
Inc(p, CharLen);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function Utf8ReverseString(const AText: string): string; inline;
|
||||||
|
begin
|
||||||
|
Result := UTF8ReverseString(PChar(AText), length(AText));
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
function Utf8RPos(const Substr, Source: string): integer;
|
||||||
|
var
|
||||||
|
RevSubstr, RevSource: string; pRev: integer;
|
||||||
|
begin
|
||||||
|
if (Pos(Substr, Source) = 0) then
|
||||||
|
Result := 0
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
RevSubstr := UTF8ReverseString(Substr);
|
||||||
|
RevSource := UTF8ReverseString(Source);
|
||||||
|
pRev := UTF8Pos(RevSubstr, RevSource);
|
||||||
|
Result := UTF8Length(Source) -pRev -UTF8Length(Substr) +2;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
function UTF8WrapText(S, BreakStr :string; BreakChars :TSysCharSet; MaxCol: integer): string;
|
function UTF8WrapText(S, BreakStr :string; BreakChars :TSysCharSet; MaxCol: integer): string;
|
||||||
var
|
var
|
||||||
P :PChar;
|
P :PChar;
|
||||||
|
Loading…
Reference in New Issue
Block a user