diff --git a/lcl/interfaces/gtk/gtkproc.inc b/lcl/interfaces/gtk/gtkproc.inc index e556560ebb..7c65fcdee6 100644 --- a/lcl/interfaces/gtk/gtkproc.inc +++ b/lcl/interfaces/gtk/gtkproc.inc @@ -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; diff --git a/lcl/interfaces/gtk/gtkproc.pp b/lcl/interfaces/gtk/gtkproc.pp index e35a74f473..13eb5667fd 100644 --- a/lcl/interfaces/gtk/gtkproc.pp +++ b/lcl/interfaces/gtk/gtkproc.pp @@ -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; diff --git a/lcl/interfaces/gtk/gtkwinapi.inc b/lcl/interfaces/gtk/gtkwinapi.inc index 80ddf49e73..dac77223b0 100644 --- a/lcl/interfaces/gtk/gtkwinapi.inc +++ b/lcl/interfaces/gtk/gtkwinapi.inc @@ -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; diff --git a/lcl/interfaces/gtk2/gtk2proc.inc b/lcl/interfaces/gtk2/gtk2proc.inc index fe270e70a2..5362b78cba 100644 --- a/lcl/interfaces/gtk2/gtk2proc.inc +++ b/lcl/interfaces/gtk2/gtk2proc.inc @@ -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; diff --git a/lcl/interfaces/gtk2/gtk2proc.pp b/lcl/interfaces/gtk2/gtk2proc.pp index 7e37fda227..e038016222 100644 --- a/lcl/interfaces/gtk2/gtk2proc.pp +++ b/lcl/interfaces/gtk2/gtk2proc.pp @@ -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; diff --git a/lcl/interfaces/gtk2/gtk2winapi.inc b/lcl/interfaces/gtk2/gtk2winapi.inc index e9ac749c65..6222c87248 100644 --- a/lcl/interfaces/gtk2/gtk2winapi.inc +++ b/lcl/interfaces/gtk2/gtk2winapi.inc @@ -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; diff --git a/lcl/lclproc.pas b/lcl/lclproc.pas index e32cf3e33d..947280f018 100644 --- a/lcl/lclproc.pas +++ b/lcl/lclproc.pas @@ -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'&') and (Result<1) then + if (Str[SrcPos]<>'&') and (Result<1) then // Ignore && as accelerator Result:=DestPos; end; if DestPos