mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-16 16:49:12 +02:00
LCL-GTK2: Use function DeleteAmpersands from unit LCLProc. Already handles a trailing &.
git-svn-id: trunk@62440 -
This commit is contained in:
parent
73224dc28f
commit
315a844105
@ -9283,49 +9283,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
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;
|
function Ampersands2Underscore(Src: PChar) : PChar;
|
||||||
|
|
||||||
|
@ -599,7 +599,6 @@ procedure ConnectInternalWidgetsSignals(AWidget: PGtkWidget;
|
|||||||
//--
|
//--
|
||||||
|
|
||||||
// accelerators
|
// accelerators
|
||||||
function DeleteAmpersands(var Str: String): Longint;
|
|
||||||
function Ampersands2Underscore(Src: PChar): PChar;
|
function Ampersands2Underscore(Src: PChar): PChar;
|
||||||
function Ampersands2Underscore(const ASource: String): String;
|
function Ampersands2Underscore(const ASource: String): String;
|
||||||
function RemoveAmpersands(Src: PChar; LineLength: Longint): PChar;
|
function RemoveAmpersands(Src: PChar; LineLength: Longint): PChar;
|
||||||
|
@ -3084,11 +3084,7 @@ begin
|
|||||||
AStr := StringReplace(AStr, #9, TabString, [rfReplaceAll]);
|
AStr := StringReplace(AStr, #9, TabString, [rfReplaceAll]);
|
||||||
|
|
||||||
if (Flags and DT_NOPREFIX) <> DT_NOPREFIX then
|
if (Flags and DT_NOPREFIX) <> DT_NOPREFIX then
|
||||||
begin
|
pIndex := DeleteAmpersands(AStr)
|
||||||
pIndex := DeleteAmpersands(AStr);
|
|
||||||
if pIndex > Length(AStr) then
|
|
||||||
pIndex := -1; // String ended in '&', which was deleted
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
pIndex := -1;
|
pIndex := -1;
|
||||||
|
|
||||||
|
@ -8992,49 +8992,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
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;
|
function Ampersands2Underscore(Src: PChar) : PChar;
|
||||||
|
|
||||||
|
@ -586,7 +586,6 @@ procedure ConnectInternalWidgetsSignals(AWidget: PGtkWidget;
|
|||||||
//--
|
//--
|
||||||
|
|
||||||
// accelerators
|
// accelerators
|
||||||
function DeleteAmpersands(var Str: String): Longint;
|
|
||||||
function Ampersands2Underscore(Src: PChar): PChar;
|
function Ampersands2Underscore(Src: PChar): PChar;
|
||||||
function Ampersands2Underscore(const ASource: String): String;
|
function Ampersands2Underscore(const ASource: String): String;
|
||||||
function EscapeUnderscores(const Str: String): String; inline;
|
function EscapeUnderscores(const Str: String): String; inline;
|
||||||
|
@ -2730,11 +2730,7 @@ begin
|
|||||||
AStr := StringReplace(AStr, #9, TabString, [rfReplaceAll]);
|
AStr := StringReplace(AStr, #9, TabString, [rfReplaceAll]);
|
||||||
|
|
||||||
if (Flags and DT_NOPREFIX) <> DT_NOPREFIX then
|
if (Flags and DT_NOPREFIX) <> DT_NOPREFIX then
|
||||||
begin
|
pIndex := DeleteAmpersands(AStr)
|
||||||
pIndex := DeleteAmpersands(AStr);
|
|
||||||
if pIndex > Length(AStr) then
|
|
||||||
pIndex := -1; // String ended in '&', which was deleted
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
pIndex := -1;
|
pIndex := -1;
|
||||||
|
|
||||||
|
@ -130,7 +130,8 @@ procedure MakeMinMax(var i1, i2: integer);
|
|||||||
procedure CalculateLeftTopWidthHeight(X1,Y1,X2,Y2: integer;
|
procedure CalculateLeftTopWidthHeight(X1,Y1,X2,Y2: integer;
|
||||||
out Left,Top,Width,Height: 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 ComparePointers(p1, p2: Pointer): integer; inline;
|
||||||
function CompareHandles(h1, h2: THandle): integer;
|
function CompareHandles(h1, h2: THandle): integer;
|
||||||
@ -344,10 +345,10 @@ var
|
|||||||
DebugNestAtBOL: Boolean;
|
DebugNestAtBOL: Boolean;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
function DeleteAmpersands(var Str : String) : Longint;
|
function DeleteAmpersands(var Str : String) : Integer;
|
||||||
// Replace all &x with x
|
// Replace all &x with x and return the position of the first accelerator letter in
|
||||||
// and return the position of the first ampersand letter in the resulting Str.
|
// the resulting Str, meaning the letter following the first & in the original Str.
|
||||||
// double ampersands && are converted to a single & and are ignored.
|
// Double ampersands && are converted to a single & and ignored.
|
||||||
var
|
var
|
||||||
SrcPos, DestPos, SrcLen: Integer;
|
SrcPos, DestPos, SrcLen: Integer;
|
||||||
begin
|
begin
|
||||||
@ -359,7 +360,7 @@ begin
|
|||||||
if (Str[SrcPos]='&') and (SrcPos<SrcLen) then begin
|
if (Str[SrcPos]='&') and (SrcPos<SrcLen) then begin
|
||||||
// & found
|
// & found
|
||||||
inc(SrcPos); // skip &
|
inc(SrcPos); // skip &
|
||||||
if (Str[SrcPos]<>'&') and (Result<1) then
|
if (Str[SrcPos]<>'&') and (Result<1) then // Ignore && as accelerator
|
||||||
Result:=DestPos;
|
Result:=DestPos;
|
||||||
end;
|
end;
|
||||||
if DestPos<SrcPos then
|
if DestPos<SrcPos then
|
||||||
|
Loading…
Reference in New Issue
Block a user