summaryrefslogtreecommitdiff
path: root/plugins/Utils.pas/common.pas
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Utils.pas/common.pas')
-rw-r--r--plugins/Utils.pas/common.pas90
1 files changed, 65 insertions, 25 deletions
diff --git a/plugins/Utils.pas/common.pas b/plugins/Utils.pas/common.pas
index cd321cbcb7..d36ecad588 100644
--- a/plugins/Utils.pas/common.pas
+++ b/plugins/Utils.pas/common.pas
@@ -90,6 +90,8 @@ procedure mFreeMem(var ptr);
function mReallocMem(var dst; size:integer):pointer;
// String processing
+function FormatStrW(fmt:pWideChar; arr:array of pWideChar):pWideChar;
+
function WideToCombo(src:PWideChar;var dst;cp:integer=CP_ACP):integer;
function ChangeUnicode(str:PWideChar):PWideChar;
@@ -124,8 +126,8 @@ function StrReplace (src,SubStr,NewStr:PAnsiChar):PAnsiChar;
function StrReplaceW(src,SubStr,NewStr:pWideChar):PWideChar;
function CharReplace (dst:pAnsiChar;old,new:AnsiChar):PAnsiChar;
function CharReplaceW(dst:pWideChar;old,new:WideChar):PWideChar;
-function StrCmp (a,b:PAnsiChar;n:cardinal=0):integer;
-function StrCmpW(a,b:PWideChar;n:cardinal=0):integer;
+function StrCmp (a,b:PAnsiChar;n:integer=0):integer;
+function StrCmpW(a,b:PWideChar;n:integer=0):integer;
function StrEnd (const a:PAnsiChar):PAnsiChar;
function StrEndW(const a:PWideChar):PWideChar;
function StrScan (src:PAnsiChar;c:AnsiChar):PAnsiChar;
@@ -904,6 +906,8 @@ begin
result:=dst;
end;
+//----- Memory work -----
+
procedure FillWord(var buf;count:cardinal;value:word); register;
{$IFNDEF WIN64}assembler;
{
@@ -968,6 +972,7 @@ asm
POP ESI
end;
}
+
{$IFNDEF WIN64}
// Delphi 2009 realization
function CompareMem(P1, P2: Pointer; Length: Integer): Boolean; assembler;
@@ -1035,10 +1040,6 @@ asm
end;
{$ELSE}
function CompareMem(P1, P2: Pointer; Length: Integer): Boolean;
- {$IFNDEF COMPILER_16_UP}
-begin
- result:=CompareByte(P1,P2,Length)=0;
- {$ELSE}
var
i:integer;
begin
@@ -1053,26 +1054,9 @@ begin
inc(pbyte(p2));
end;
result:=true;
- {$ENDIF}
end;
{$ENDIF}
-function Min(a,b:integer):integer;
-begin
- if a>b then
- result:=b
- else
- result:=a;
-end;
-
-function Max(a,b:integer):integer;
-begin
- if a<b then
- result:=b
- else
- result:=a;
-end;
-
function mGetMem(var dst;size:integer):pointer;
begin
{$IFDEF Use_MMI}
@@ -1106,6 +1090,22 @@ begin
result:=pointer(dst);
end;
+function Min(a,b:integer):integer;
+begin
+ if a>b then
+ result:=b
+ else
+ result:=a;
+end;
+
+function Max(a,b:integer):integer;
+begin
+ if a<b then
+ result:=b
+ else
+ result:=a;
+end;
+
function UnEscape(buf:PAnsiChar):PAnsiChar;
begin
if (buf<>nil) and (buf^<>#0) then
@@ -1198,6 +1198,46 @@ begin
end;
end;
+function FormatStrW(fmt:pWideChar; arr:array of pWideChar):pWideChar;
+var
+ i,len:integer;
+ pc:pWideChar;
+ number:integer;
+begin
+ result:=nil;
+ if (fmt=nil) or (fmt^=#0) then
+ exit;
+
+ // calculate length
+ len:=StrLenW(fmt); // -2*Length(arr)
+ for i:=0 to HIGH(arr) do
+ inc(len,StrLenW(arr[i]));
+
+ // format
+ mGetMem(result,(len+1)*SizeOf(WideChar));
+ pc:=result;
+ number:=0;
+ while fmt^<>#0 do
+ begin
+ if (fmt^='%') and ((fmt+1)^='s') then
+ begin
+ if number<=HIGH(arr) then
+ begin
+ pc:=StrCopyEW(pc,arr[number]);
+ inc(number);
+ end;
+ inc(fmt,2);
+ end
+ else
+ begin
+ pc^:=fmt^;
+ inc(pc);
+ inc(fmt);
+ end;
+ end;
+ pc^:=#0;
+end;
+
// ----- base string functions -----
function StrDup(var dst:PAnsiChar;src:PAnsiChar;len:cardinal=0):PAnsiChar;
var
@@ -1510,7 +1550,7 @@ begin
end;
end;
-function StrCmp(a,b:PAnsiChar;n:cardinal=0):integer; // CompareString
+function StrCmp(a,b:PAnsiChar;n:integer=0):integer; // CompareString
begin
result:=0;
if (a=nil) and (b=nil) then
@@ -1530,7 +1570,7 @@ begin
until n=0;
end;
-function StrCmpW(a,b:PWideChar;n:cardinal=0):integer;
+function StrCmpW(a,b:PWideChar;n:integer=0):integer;
begin
result:=0;
if (a=nil) and (b=nil) then