LazUtils: Deprecate IsNumber(), rename to IsNumeric() for better clarity. Check for empty input string, issue #40935, patch by Ph B.

This commit is contained in:
wp_xyz 2024-05-01 12:10:49 +02:00
parent 746d25dbe9
commit 4186cfe014
4 changed files with 21 additions and 11 deletions

View File

@ -1373,7 +1373,7 @@ begin
if (ptprfPointer in PTReq.Result.Flags) and
( ( s = 'char') or (s = 'character') or (s = 'wchar') or (s = 'widechar') )
then begin
if IsNumber(IdxPart.GetPlainText)
if IsNumeric(IdxPart.GetPlainText)
then begin
FMaybeString := True;
end
@ -1389,7 +1389,7 @@ begin
if (PTReq.Result.Kind = ptprkSimple)
then begin
ResultList := TGDBMINameValueList.Create(PTReq.Result.GdbDescription);
FMaybeString := IsNumber(ResultList.Values['value']);
FMaybeString := IsNumeric(ResultList.Values['value']);
ResultList.Free;
end;
end;

View File

@ -42,7 +42,8 @@ function LazEndsStr(const ASubText, AText: string): Boolean;
function LazStartsText(const ASubText, AText: string): Boolean;
function LazEndsText(const ASubText, AText: string): Boolean;
function PosI(const SubStr, S: string): integer;
function IsNumber(s: String): Boolean;
function IsNumeric(s: String): Boolean;
function IsNumber(s: String): Boolean; deprecated 'Use IsNumeric; to be removed in v4.99';
// Functions for line endings
function LineEndingCount(const Txt: string; var LengthOfLastLine: integer): integer;
@ -204,14 +205,23 @@ begin
end;
end;
function IsNumber(s: String): Boolean;
function IsNumeric(s: String): Boolean;
var
i: Integer;
begin
i := Length(s);
while (i >= 1) and (s[i] in ['0'..'9']) do
dec(i);
Result := i = 0;
if i > 0 then
begin
while (i >= 1) and (s[i] in ['0'..'9']) do
dec(i);
Result := i = 0;
end else
Result := false;
end;
function IsNumber(s: String): Boolean;
begin
Result := IsNumeric(s);
end;
function LineEndingCount(const Txt: string; var LengthOfLastLine: integer): integer;

View File

@ -446,7 +446,7 @@ begin
LCLObject := TObject(data);
if (widget <> nil) and (LCLObject is TCustomEdit) then
{ NumbersOnly: stop signal if inserted text is not a number }
if TCustomEdit(LCLObject).NumbersOnly and not IsNumber(ANewText) then
if TCustomEdit(LCLObject).NumbersOnly and not IsNumeric(ANewText) then
begin
gtk_entry_set_text(PGtkEntry(widget), EntryText);
g_signal_stop_emission_by_name(Widget, 'insert-text');
@ -535,7 +535,7 @@ begin
FClip := gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
if (FClip <> nil) and gtk_clipboard_wait_is_text_available(FClip) then
FClipText := gtk_clipboard_wait_for_text(FClip);
if Assigned(FClip) and not IsNumber(FClipText) then
if Assigned(FClip) and not IsNumeric(FClipText) then
g_signal_stop_emission_by_name(Widget, 'paste-clipboard');
end;
end;

View File

@ -1114,7 +1114,7 @@ var
begin
if not WSCheckHandleAllocated(AWinControl, 'SetText') then
Exit;
if TCustomEdit(AWinControl).NumbersOnly and not IsNumber(AText) then
if TCustomEdit(AWinControl).NumbersOnly and not IsNumeric(AText) then
Exit;
{$IFDEF VerboseTWinControlRealText}
DebugLn(['TGtkWSCustomEdit.SetText START ',DbgSName(AWinControl),' AText="',AText,'"']);
@ -1156,7 +1156,7 @@ var
begin
if not WSCheckHandleAllocated(ACustomEdit, 'SetSelText') then
Exit;
if ACustomEdit.NumbersOnly and not IsNumber(NewSelText) then
if ACustomEdit.NumbersOnly and not IsNumeric(NewSelText) then
Exit;
Widget:={%H-}PGtkWidget(ACustomEdit.Handle);
if GTK_IS_SPIN_BUTTON(Widget) then