LCL-GTK2: Move function ComparePChar to LazStringUtils as SamePChar.

git-svn-id: trunk@62464 -
This commit is contained in:
juha 2019-12-29 23:18:51 +00:00
parent a6e4bb8d92
commit ec99bd95e2
5 changed files with 37 additions and 88 deletions

View File

@ -93,7 +93,10 @@ function SwapCase(Const S: String): String;
function StringCase(const AString: String; const ACase: array of String {; const AIgnoreCase = False, APartial = false: Boolean}): Integer; overload; function StringCase(const AString: String; const ACase: array of String {; const AIgnoreCase = False, APartial = false: Boolean}): Integer; overload;
function StringCase(const AString: String; const ACase: array of String; const AIgnoreCase, APartial: Boolean): Integer; overload; function StringCase(const AString: String; const ACase: array of String; const AIgnoreCase, APartial: Boolean): Integer; overload;
// Test over a string // PChar
function SamePChar(P1, P2: PChar): boolean;
// Like IsValidIdent() in FPC 3.1.
function LazIsValidIdent(const Ident: string; AllowDots: Boolean = False; function LazIsValidIdent(const Ident: string; AllowDots: Boolean = False;
StrictDots: Boolean = False): Boolean; StrictDots: Boolean = False): Boolean;
@ -1238,6 +1241,20 @@ begin
Result := -1; Result := -1;
end; end;
function SamePChar(P1, P2: PChar): boolean;
// Return True if P1 and P2 have the same contents.
begin
if (P1=P2) then Exit(True);
if (P1=nil) or (P2=nil) then Exit(False);
while P1^=P2^ do
begin
if P1^=#0 then Exit(True);
inc(P1);
inc(P2);
end;
Result:=False;
end;
function LazIsValidIdent(const Ident: string; AllowDots: Boolean = False; function LazIsValidIdent(const Ident: string; AllowDots: Boolean = False;
StrictDots: Boolean = False): Boolean; StrictDots: Boolean = False): Boolean;
// This is a copy of IsValidIdent from FPC 3.1. // This is a copy of IsValidIdent from FPC 3.1.

View File

@ -293,44 +293,14 @@ end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
function CreatePChar(const s: string): PChar;
Allocates a new PChar Allocates a new PChar
------------------------------------------------------------------------------} ------------------------------------------------------------------------------
function CreatePChar(const s: string): PChar; function CreatePChar(const s: string): PChar;
begin begin
Result:=StrAlloc(length(s) + 1); Result:=StrAlloc(length(s) + 1);
StrPCopy(Result, s); StrPCopy(Result, s);
end; end;
}
{------------------------------------------------------------------------------
function ComparePChar(P1, P2: PChar): boolean;
Checks if P1 and P2 have the same content.
------------------------------------------------------------------------------}
function ComparePChar(P1, P2: PChar): boolean;
begin
if (P1<>P2) then begin
if (P1<>nil) and (P2<>nil) then begin
while (P1^=P2^) do begin
if P1^<>#0 then begin
inc(P1);
inc(P2);
end else begin
Result:=true;
exit;
end;
end;
end;
Result:=false;
end else begin
Result:=true;
end;
end;
{------------------------------------------------------------------------------
function FindChar(c: char; p:PChar; Max: integer): integer;
------------------------------------------------------------------------------}
function FindChar(c: char; p:PChar; Max: integer): integer; function FindChar(c: char; p:PChar; Max: integer): integer;
begin begin
Result:=0; Result:=0;
@ -4973,7 +4943,7 @@ end;
function DesignSignalNameToType(Name: PChar; After: boolean): TDesignSignalType; function DesignSignalNameToType(Name: PChar; After: boolean): TDesignSignalType;
begin begin
for Result:=Low(TDesignSignalType) to High(TDesignSignalType) do for Result:=Low(TDesignSignalType) to High(TDesignSignalType) do
if ComparePChar(DesignSignalNames[Result],Name) if SamePChar(DesignSignalNames[Result],Name)
and (DesignSignalAfter[Result]=After) then exit; and (DesignSignalAfter[Result]=After) then exit;
Result:=dstUnknown; Result:=dstUnknown;
end; end;

View File

@ -47,9 +47,10 @@ uses
glib, gdk, gtk, gdkpixbuf, glib, gdk, gtk, gdkpixbuf,
{$ENDIF} {$ENDIF}
Math, // Math after gtk to get the correct Float type Math, // Math after gtk to get the correct Float type
LazUTF8, LMessages, LCLMessageGlue, LCLProc, LCLStrConsts, LCLIntf, LCLType, Masks, LazUTF8, FileUtil, LazFileUtils, LazStringUtils, DynHashArray,
DynHashArray, Masks, GraphType, GraphMath, Graphics, Controls, Forms, Menus, LMessages, LCLMessageGlue, LCLProc, LCLStrConsts, LCLIntf, LCLType,
StdCtrls, ComCtrls, ExtCtrls, Dialogs, ExtDlgs, FileUtil, LazFileUtils, GraphType, GraphMath, Graphics, Controls, Forms, Menus,
StdCtrls, ComCtrls, ExtCtrls, Dialogs, ExtDlgs,
ImgList, GtkFontCache, GTKGlobals, GtkDef, GtkExtra, GtkDebug; ImgList, GtkFontCache, GTKGlobals, GtkDef, GtkExtra, GtkDebug;
const const
@ -301,7 +302,6 @@ procedure BeginGDKErrorTrap;
procedure EndGDKErrorTrap; procedure EndGDKErrorTrap;
function dbgGRect(const ARect: PGDKRectangle): string; overload; function dbgGRect(const ARect: PGDKRectangle): string; overload;
// gtk resources // gtk resources
procedure Set_RC_Name(Sender: TObject; AWidget: PGtkWidget); procedure Set_RC_Name(Sender: TObject; AWidget: PGtkWidget);
@ -310,8 +310,7 @@ function DeliverPostMessage(const Target: Pointer; var TheMessage): GBoolean;
function DeliverMessage(const Target: Pointer; var AMessage): PtrInt; function DeliverMessage(const Target: Pointer; var AMessage): PtrInt;
// PChar // PChar
function CreatePChar(const s: string): PChar; //function CreatePChar(const s: string): PChar;
function ComparePChar(P1, P2: PChar): boolean;
function FindChar(c: char; p:PChar; Max: integer): integer; function FindChar(c: char; p:PChar; Max: integer): integer;
function FindLineLen(p:PChar; Max: integer): integer; function FindLineLen(p:PChar; Max: integer): integer;

View File

@ -269,69 +269,33 @@ end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
function CreatePChar(const s: string): PChar;
Allocates a new PChar Allocates a new PChar
------------------------------------------------------------------------------} ------------------------------------------------------------------------------
function CreatePChar(const s: string): PChar; function CreatePChar(const s: string): PChar;
begin begin
Result:=StrAlloc(length(s) + 1); Result:=StrAlloc(length(s) + 1);
StrPCopy(Result, s); StrPCopy(Result, s);
end; end;
}
{------------------------------------------------------------------------------
function ComparePChar(P1, P2: PChar): boolean;
Checks if P1 and P2 have the same content.
------------------------------------------------------------------------------}
function ComparePChar(P1, P2: PChar): boolean;
begin
if (P1<>P2) then begin
if (P1<>nil) and (P2<>nil) then begin
while (P1^=P2^) do begin
if P1^<>#0 then begin
inc(P1);
inc(P2);
end else begin
Result:=true;
exit;
end;
end;
end;
Result:=false;
end else begin
Result:=true;
end;
end;
{------------------------------------------------------------------------------
function FindChar(c: char; p:PChar; Max: integer): integer;
------------------------------------------------------------------------------}
function FindChar(c: char; p:PChar; Max: integer): integer; function FindChar(c: char; p:PChar; Max: integer): integer;
begin begin
Result:=0; Result:=0;
while (Result<Max) do begin while Result<Max do begin
if p[Result]<>c then if p[Result]=c then exit;
inc(Result) inc(Result);
else
exit;
end; end;
Result:=-1; Result:=-1;
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
function FindLineLen(p: PChar; Max: integer): integer;
Find line end Find line end
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
function FindLineLen(p: PChar; Max: integer): integer; function FindLineLen(p: PChar; Max: integer): integer;
begin begin
Result:=0; Result:=0;
while (Result<Max) do begin while Result<Max do begin
if not (p[Result] in [#10,#13]) then if p[Result] in [#10,#13] then exit;
inc(Result) inc(Result);
else
exit;
end; end;
Result:=-1; Result:=-1;
end; end;
@ -4987,7 +4951,7 @@ end;
function DesignSignalNameToType(Name: PChar; After: boolean): TDesignSignalType; function DesignSignalNameToType(Name: PChar; After: boolean): TDesignSignalType;
begin begin
for Result:=Low(TDesignSignalType) to High(TDesignSignalType) do for Result:=Low(TDesignSignalType) to High(TDesignSignalType) do
if ComparePChar(DesignSignalNames[Result],Name) if SamePChar(DesignSignalNames[Result],Name)
and (DesignSignalAfter[Result]=After) then exit; and (DesignSignalAfter[Result]=After) then exit;
Result:=dstUnknown; Result:=dstUnknown;
end; end;

View File

@ -49,7 +49,7 @@ uses
LResources, Controls, Forms, Buttons, Menus, StdCtrls, ComCtrls, ExtCtrls, LResources, Controls, Forms, Buttons, Menus, StdCtrls, ComCtrls, ExtCtrls,
Dialogs, ExtDlgs, ImgList, LCLMessageGlue, Dialogs, ExtDlgs, ImgList, LCLMessageGlue,
// LazUtils // LazUtils
Masks, FileUtil, LazFileUtils, LazLoggerBase, LazUTF8, DynHashArray, Masks, FileUtil, LazFileUtils, LazStringUtils, LazLoggerBase, LazUTF8, DynHashArray,
// Gtk2 // Gtk2
Gtk2FontCache, Gtk2Globals, Gtk2Def, Gtk2Extra, {%H-}Gtk2Debug; Gtk2FontCache, Gtk2Globals, Gtk2Def, Gtk2Extra, {%H-}Gtk2Debug;
@ -311,8 +311,7 @@ function DeliverPostMessage(const Target: Pointer; var TheMessage): GBoolean;
function DeliverMessage(const Target: Pointer; var AMessage): PtrInt; function DeliverMessage(const Target: Pointer; var AMessage): PtrInt;
// PChar // PChar
function CreatePChar(const s: string): PChar; //function CreatePChar(const s: string): PChar;
function ComparePChar(P1, P2: PChar): boolean;
function FindChar(c: char; p:PChar; Max: integer): integer; function FindChar(c: char; p:PChar; Max: integer): integer;
function FindLineLen(p:PChar; Max: integer): integer; function FindLineLen(p:PChar; Max: integer): integer;