Przeglądaj źródła

* modified patch by LacaK2 to add overloaded versions of string handling routines, which works with WideChar null terminated strings, resolves #19989

git-svn-id: trunk@19337 -
florian 14 lat temu
rodzic
commit
77c3477b91

+ 2 - 2
rtl/i386/strings.inc

@@ -18,7 +18,7 @@
 
 {$ifndef FPC_UNIT_HAS_STRCOPY}
 {$define FPC_UNIT_HAS_STRCOPY}
-function strcopy(dest,source : pchar) : pchar;assembler;
+function strcopy(dest,source : pchar) : pchar;assembler;overload;
 var
   saveeax,saveesi,saveedi : longint;
 asm
@@ -131,7 +131,7 @@ end;
 
 {$ifndef FPC_UNIT_HAS_STRLCOPY}
 {$define FPC_UNIT_HAS_STRLCOPY}
-function strlcopy(dest,source : pchar;maxlen : sizeint) : pchar;assembler;
+function strlcopy(dest,source : pchar;maxlen : sizeint) : pchar;assembler;overload;
 var
   savedest,
   saveesi,saveedi : longint;

+ 2 - 2
rtl/inc/genstr.inc

@@ -26,7 +26,7 @@
 
 
 {$ifndef FPC_UNIT_HAS_STRCOPY}
- Function StrCopy(Dest, Source:PChar): PChar;
+ Function StrCopy(Dest, Source:PChar): PChar;overload;
  var
    counter : SizeInt;
  Begin
@@ -217,7 +217,7 @@
 
 
 {$ifndef FPC_UNIT_HAS_STRLCOPY}
- Function StrLCopy(Dest,Source: PChar; MaxLen: SizeInt): PChar;
+ Function StrLCopy(Dest,Source: PChar; MaxLen: SizeInt): PChar;overload;
   var
    counter: SizeInt;
  Begin

+ 2 - 2
rtl/objpas/sysutils/syspch.inc

@@ -73,7 +73,7 @@ end;
 
 {  StrPCopy copies the pascal string Source to Dest and returns Dest  }
 
-function StrPCopy(Dest: PChar; Source: string): PChar;
+function StrPCopy(Dest: PChar; Source: string): PChar;overload;
 begin
   result := StrMove(Dest, PChar(Source), length(Source)+1);
 end ;
@@ -81,7 +81,7 @@ end ;
 {  StrPLCopy copies MaxLen or less characters from the pascal string
    Source to Dest and returns Dest  }
 
-function StrPLCopy(Dest: PChar; Source: string; MaxLen: SizeUInt): PChar;
+function StrPLCopy(Dest: PChar; Source: string; MaxLen: SizeUInt): PChar;overload;
 var Count: SizeUInt;
 begin
 result := Dest;

+ 5 - 5
rtl/objpas/sysutils/syspchh.inc

@@ -21,9 +21,9 @@
 }
 
 { shared with strings unit }
-function strlen(p:pchar):sizeint;external name 'FPC_PCHAR_LENGTH';
-function strcopy(dest,source : pchar) : pchar;
-function strlcopy(dest,source : pchar;maxlen : SizeInt) : pchar;
+function strlen(p:pchar):sizeint;external name 'FPC_PCHAR_LENGTH';overload;
+function strcopy(dest,source : pchar) : pchar;overload;
+function strlcopy(dest,source : pchar;maxlen : SizeInt) : pchar;overload;
 function strecopy(dest,source : pchar) : pchar;
 function strend(p : pchar) : pchar;
 function strcat(dest,source : pchar) : pchar;
@@ -42,8 +42,8 @@ function strnew(p : pchar) : pchar;
 
 { Different from strings unit - ansistrings or different behaviour }
 function StrPas(Str: PChar): string;
-function StrPCopy(Dest: PChar; Source: string): PChar;
-function StrPLCopy(Dest: PChar; Source: string; MaxLen: SizeUInt): PChar;
+function StrPCopy(Dest: PChar; Source: string): PChar;overload;
+function StrPLCopy(Dest: PChar; Source: string; MaxLen: SizeUInt): PChar;overload;
 function StrAlloc(Size: cardinal): PChar;
 function StrBufSize(Str: PChar): SizeUInt;
 procedure StrDispose(Str: PChar);

+ 16 - 0
rtl/objpas/sysutils/sysuni.inc

@@ -151,3 +151,19 @@ begin
 end;
 
 
+function StrPLCopy(Dest: PWideChar; const Source: UnicodeString; MaxLen: SizeInt): PWideChar; overload;
+var Len: SizeInt;
+begin
+  Len := length(Source);
+  if Len > MaxLen then
+    Len := MaxLen;
+  Move(Source[1], Dest^, Len*sizeof(WideChar));
+  Dest[Len] := #0;
+  StrPLCopy := Dest;
+end;
+
+
+function StrPCopy(Dest: PWideChar; const Source: UnicodeString): PWideChar; overload;
+begin
+  StrPCopy := StrPLCopy(Dest, Source, length(Source));
+end;

+ 4 - 0
rtl/objpas/sysutils/sysunih.inc

@@ -38,3 +38,7 @@ Function UnicodeFormatBuf (Var Buffer; BufLen : Cardinal; Const Fmt; fmtLen : Ca
 Function UnicodeFormatBuf (Var Buffer; BufLen : Cardinal; Const Fmt; fmtLen : Cardinal; Const Args : Array of const; Const FormatSettings: TFormatSettings) : Cardinal;
 Procedure UnicodeFmtStr(Var Res: UnicodeString; Const Fmt : UnicodeString; Const args: Array of const);
 Procedure UnicodeFmtStr(Var Res: UnicodeString; Const Fmt : UnicodeString; Const args: Array of const; Const FormatSettings: TFormatSettings);
+
+function StrPLCopy(Dest: PWideChar; const Source: UnicodeString; MaxLen: SizeInt): PWideChar; overload;
+function StrPCopy(Dest: PWideChar; const Source: UnicodeString): PWideChar; overload;
+

+ 29 - 0
rtl/objpas/sysutils/syswide.inc

@@ -152,4 +152,33 @@ begin
   WideFmtStr(Res,Fmt,Args,DefaultFormatSettings);
 end;
 
+function StrCopy(Dest, Source: PWideChar): PWideChar; overload;
+var
+  counter : SizeInt;
+begin
+  counter := 0;
+  while Source[counter] <> #0 do
+  begin
+    Dest[counter] := widechar(Source[counter]);
+    Inc(counter);
+  end;
+  { terminate the string }
+  Dest[counter] := #0;
+  StrCopy := Dest;
+end;
+
+function StrLCopy(Dest,Source: PWideChar; MaxLen: SizeInt): PWideChar; overload;
+var
+  counter: SizeInt;
+begin
+  counter := 0;
+  while (Source[counter] <> #0) and (counter < MaxLen) do
+  begin
+    Dest[counter] := widechar(Source[counter]);
+    Inc(counter);
+  end;
+  { terminate the string }
+  Dest[counter] := #0;
+  StrLCopy := Dest;
+end;
 

+ 6 - 0
rtl/objpas/sysutils/syswideh.inc

@@ -35,3 +35,9 @@ Function WideFormatBuf (Var Buffer; BufLen : Cardinal; Const Fmt; fmtLen : Cardi
 Function WideFormatBuf (Var Buffer; BufLen : Cardinal; Const Fmt; fmtLen : Cardinal; Const Args : Array of const; Const FormatSettings: TFormatSettings) : Cardinal;
 Procedure WideFmtStr(Var Res: WideString; Const Fmt : WideString; Const args: Array of const);
 Procedure WideFmtStr(Var Res: WideString; Const Fmt : WideString; Const args: Array of const; Const FormatSettings: TFormatSettings);
+
+function StrLen(p: pwidechar): sizeint; external name 'FPC_PWIDECHAR_LENGTH'; overload;
+
+function StrCopy(Dest, Source: PWideChar): PWideChar; overload;
+function StrLCopy(Dest,Source: PWideChar; MaxLen: SizeInt): PWideChar; overload;
+