LCL-GTK2: Use function DeleteAmpersands from unit LCLProc. Already handles a trailing &.

git-svn-id: trunk@62440 -
This commit is contained in:
juha 2019-12-23 21:01:06 +00:00
parent 73224dc28f
commit 315a844105
7 changed files with 9 additions and 104 deletions

View File

@ -9283,49 +9283,6 @@ begin
end;
end;
function DeleteAmpersands(var Str : String) : Longint;
// convert double ampersands to single & and delete single &
// return the position of the letter after the first deleted single ampersand
// in the new string
var
Tmp : String;
SrcPos, DestPos, SrcLen: integer;
begin
Result := -1;
// for speedup reasons check if Str must be changed
SrcLen:=length(Str);
SrcPos:=SrcLen;
while (SrcPos>=1) and (Str[SrcPos]<>'&') do dec(SrcPos);
if SrcPos<1 then exit;
// copy Str to Tmp and convert ampersands on the fly
SetLength(Tmp,SrcLen);
SrcPos:=1;
DestPos:=1;
while (SrcPos<=SrcLen) do begin
if Str[SrcPos]<>'&' then begin
// copy normal char
Tmp[DestPos]:=Str[SrcPos];
inc(SrcPos);
inc(DestPos);
end else begin
inc(SrcPos);
if (SrcPos<=SrcLen) and (Str[SrcPos]='&') then begin
// double ampersand
Tmp[DestPos]:='&';
inc(DestPos);
inc(SrcPos);
end else begin
// single ampersand
if Result<1 then Result:=DestPos;
end;
end;
end;
SetLength(Tmp,DestPos-1);
Str:=Tmp;
end;
{-------------------------------------------------------------------------------
function Ampersands2Underscore(Src: PChar) : PChar;

View File

@ -599,7 +599,6 @@ procedure ConnectInternalWidgetsSignals(AWidget: PGtkWidget;
//--
// accelerators
function DeleteAmpersands(var Str: String): Longint;
function Ampersands2Underscore(Src: PChar): PChar;
function Ampersands2Underscore(const ASource: String): String;
function RemoveAmpersands(Src: PChar; LineLength: Longint): PChar;

View File

@ -3084,11 +3084,7 @@ begin
AStr := StringReplace(AStr, #9, TabString, [rfReplaceAll]);
if (Flags and DT_NOPREFIX) <> DT_NOPREFIX then
begin
pIndex := DeleteAmpersands(AStr);
if pIndex > Length(AStr) then
pIndex := -1; // String ended in '&', which was deleted
end
pIndex := DeleteAmpersands(AStr)
else
pIndex := -1;

View File

@ -8992,49 +8992,6 @@ begin
end;
end;
function DeleteAmpersands(var Str : String) : Longint;
// convert double ampersands to single & and delete single &
// return the position of the letter after the first deleted single ampersand
// in the new string
var
Tmp : String;
SrcPos, DestPos, SrcLen: integer;
begin
Result := -1;
// for speedup reasons check if Str must be changed
SrcLen:=length(Str);
SrcPos:=SrcLen;
while (SrcPos>=1) and (Str[SrcPos]<>'&') do dec(SrcPos);
if SrcPos<1 then exit;
// copy Str to Tmp and convert ampersands on the fly
SetLength(Tmp,SrcLen);
SrcPos:=1;
DestPos:=1;
while (SrcPos<=SrcLen) do begin
if Str[SrcPos]<>'&' then begin
// copy normal char
Tmp[DestPos]:=Str[SrcPos];
inc(SrcPos);
inc(DestPos);
end else begin
inc(SrcPos);
if (SrcPos<=SrcLen) and (Str[SrcPos]='&') then begin
// double ampersand
Tmp[DestPos]:='&';
inc(DestPos);
inc(SrcPos);
end else begin
// single ampersand
if Result<1 then Result:=DestPos;
end;
end;
end;
SetLength(Tmp,DestPos-1);
Str:=Tmp;
end;
{-------------------------------------------------------------------------------
function Ampersands2Underscore(Src: PChar) : PChar;

View File

@ -586,7 +586,6 @@ procedure ConnectInternalWidgetsSignals(AWidget: PGtkWidget;
//--
// accelerators
function DeleteAmpersands(var Str: String): Longint;
function Ampersands2Underscore(Src: PChar): PChar;
function Ampersands2Underscore(const ASource: String): String;
function EscapeUnderscores(const Str: String): String; inline;

View File

@ -2730,11 +2730,7 @@ begin
AStr := StringReplace(AStr, #9, TabString, [rfReplaceAll]);
if (Flags and DT_NOPREFIX) <> DT_NOPREFIX then
begin
pIndex := DeleteAmpersands(AStr);
if pIndex > Length(AStr) then
pIndex := -1; // String ended in '&', which was deleted
end
pIndex := DeleteAmpersands(AStr)
else
pIndex := -1;

View File

@ -130,7 +130,8 @@ procedure MakeMinMax(var i1, i2: integer);
procedure CalculateLeftTopWidthHeight(X1,Y1,X2,Y2: integer;
out Left,Top,Width,Height: integer);
function DeleteAmpersands(var Str : String) : Longint;
// Ampersands
function DeleteAmpersands(var Str : String) : Integer;
function ComparePointers(p1, p2: Pointer): integer; inline;
function CompareHandles(h1, h2: THandle): integer;
@ -344,10 +345,10 @@ var
DebugNestAtBOL: Boolean;
{$ENDIF}
function DeleteAmpersands(var Str : String) : Longint;
// Replace all &x with x
// and return the position of the first ampersand letter in the resulting Str.
// double ampersands && are converted to a single & and are ignored.
function DeleteAmpersands(var Str : String) : Integer;
// Replace all &x with x and return the position of the first accelerator letter in
// the resulting Str, meaning the letter following the first & in the original Str.
// Double ampersands && are converted to a single & and ignored.
var
SrcPos, DestPos, SrcLen: Integer;
begin
@ -359,7 +360,7 @@ begin
if (Str[SrcPos]='&') and (SrcPos<SrcLen) then begin
// & found
inc(SrcPos); // skip &
if (Str[SrcPos]<>'&') and (Result<1) then
if (Str[SrcPos]<>'&') and (Result<1) then // Ignore && as accelerator
Result:=DestPos;
end;
if DestPos<SrcPos then