Explorar o código

+ pchar -> short/ansi/unicodestring support

git-svn-id: branches/jvmbackend@18767 -
Jonas Maebe %!s(int64=14) %!d(string=hai) anos
pai
achega
27f2edea57
Modificáronse 4 ficheiros con 42 adicións e 27 borrados
  1. 12 11
      rtl/java/astrings.inc
  2. 1 4
      rtl/java/compproc.inc
  3. 14 12
      rtl/java/ustrings.inc
  4. 15 0
      rtl/jvm/jvm.inc

+ 12 - 11
rtl/java/astrings.inc

@@ -268,20 +268,21 @@ begin
   result:=ansistring(AnsistringClass.Create(c));
 end;
 
-(*
+
 Function fpc_PChar_To_AnsiStr(const p : pchar): ansistring; compilerproc;
-Var
-  L : SizeInt;
-begin
-  if (not assigned(p)) or (p[0]=#0) Then
-    L := 0
+var
+  i, len: longint;
+  arr: TAnsiCharArray;
+begin
+  arr:=TAnsiCharArray(p);
+  i:=0;
+  while arr[i]<>#0 do
+    inc(i);
+  if i<>0 then
+    result:=ansistring(AnsiStringClass.create(arr,i))
   else
-    l:=IndexChar(p^,-1,#0);
-  SetLength(fpc_PChar_To_AnsiStr,L);
-  if L > 0 then
-    Move (P[0],Pointer(fpc_PChar_To_AnsiStr)^,L)
+    result:=''
 end;
-*)
 
 
 Function fpc_CharArray_To_AnsiStr(const arr: array of ansichar; zerobased: boolean = true): ansistring; compilerproc;

+ 1 - 4
rtl/java/compproc.inc

@@ -45,13 +45,12 @@ procedure fpc_shortstr_append_shortstr(var s1:shortstring;const s2:shortstring);
 function fpc_shortstr_compare(const left,right:shortstring) : longint; compilerproc;
 function fpc_shortstr_compare_equal(const left,right:shortstring) : longint; compilerproc;
 
-(*
 {$ifndef FPC_STRTOSHORTSTRINGPROC}
 function fpc_pchar_to_shortstr(p:pchar):shortstring; compilerproc;
 {$else FPC_STRTOSHORTSTRINGPROC}
 procedure fpc_pchar_to_shortstr(out res : shortstring;p:pchar); compilerproc;
 {$endif FPC_STRTOSHORTSTRINGPROC}
-
+(*
 function fpc_pchar_length(p:pchar):longint; compilerproc;
 function fpc_pwidechar_length(p:pwidechar):longint; compilerproc;
 *)
@@ -256,9 +255,7 @@ Function fpc_ShortStr_To_AnsiStr (Const S2 : ShortString): ansistring; compilerp
 {$ifndef nounsupported}
 Function fpc_Char_To_AnsiStr(const c : AnsiChar): AnsiString; compilerproc;
 {$endif}
-(*
 Function fpc_PChar_To_AnsiStr(const p : pchar): ansistring; compilerproc;
-*)
 {$ifndef nounsupported}
 Function fpc_CharArray_To_AnsiStr(const arr: array of AnsiChar; zerobased: boolean = true): ansistring; compilerproc;
 procedure fpc_ansistr_to_chararray(out res: array of AnsiChar; const src: ansistring)compilerproc;

+ 14 - 12
rtl/java/ustrings.inc

@@ -262,20 +262,22 @@ begin
   result:=u;
 end;
 
-(*
+
 Function fpc_PChar_To_UnicodeStr(const p : pchar): UnicodeString; compilerproc;
-Var
-  L : SizeInt;
-begin
-  if (not assigned(p)) or (p[0]=#0) Then
-  begin
-    fpc_pchar_to_unicodestr := '';
-    exit;
-  end;
-  l:=IndexChar(p^,-1,#0);
-  widestringmanager.Ansi2UnicodeMoveProc(P,fpc_PChar_To_UnicodeStr,l);
+var
+  i, len: longint;
+  arr: TAnsiCharArray;
+begin
+  arr:=TAnsiCharArray(p);
+  i:=0;
+  while arr[i]<>#0 do
+    inc(i);
+  if i<>0 then
+    result:=JLString.create(TJByteArray(arr),0,i)
+  else
+    result:=''
 end;
-*)
+
 
 Function fpc_CharArray_To_UnicodeStr(const arr: array of ansichar; zerobased: boolean = true): UnicodeString; compilerproc;
 var

+ 15 - 0
rtl/jvm/jvm.inc

@@ -97,7 +97,22 @@ function Sptr:Pointer;
 {$define FPC_STRTOSHORTSTRINGPROC}
 {$define FPC_SYSTEM_HAS_FPC_PCHAR_LENGTH}
 {$define FPC_SYSTEM_HAS_FPC_PWIDECHAR_LENGTH}
+
 {$define FPC_SYSTEM_HAS_FPC_PCHAR_TO_SHORTSTR}
+procedure fpc_pchar_to_shortstr(out res : shortstring;p:pchar); compilerproc;
+var
+  i, len: longint;
+  arr: TAnsiCharArray;
+begin
+  arr:=TAnsiCharArray(p);
+  i:=0;
+  while arr[i]<>#0 do
+    inc(i);
+  if i<>0 then
+    res:=pshortstring(ShortStringClass.create(arr,min(i,high(res))))^
+  else
+    res:=''
+end;
 
 {$define FPC_SYSTEM_HAS_FPC_SHORTSTR_ASSIGN}
 procedure fpc_shortstr_to_shortstr(out res:shortstring; const sstr: shortstring); compilerproc;