Quellcode durchsuchen

Merged revisions 9487,9517-9518 via svnmerge from
svn+ssh://[email protected]/FPC/svn/fpc/trunk

........
r9487 | jonas | 2007-12-17 16:36:11 +0100 (Mon, 17 Dec 2007) | 3 lines

* don't rely on #32 (space, which replaces #0 in strings when comparing)
being considered as smaller than any other character

........
r9517 | florian | 2007-12-22 19:43:29 +0100 (Sat, 22 Dec 2007) | 1 line

* setlength in utf16/widestringtoutf32 fixed, resolves #10462
........
r9518 | jonas | 2007-12-23 19:40:15 +0100 (Sun, 23 Dec 2007) | 3 lines

* don't convert terminating #0 of UCS4Strings to widestring
* fixed length check in twide5.pp

........

git-svn-id: branches/fixes_2_2@9529 -

Jonas Maebe vor 17 Jahren
Ursprung
Commit
f4e6e9caa2
4 geänderte Dateien mit 18 neuen und 15 gelöschten Zeilen
  1. 7 5
      rtl/inc/wustrings.inc
  2. 6 6
      rtl/unix/cwstring.pp
  3. 3 2
      tests/test/twide5.pp
  4. 2 2
      tests/test/units/sysutils/tastrcmp.pp

+ 7 - 5
rtl/inc/wustrings.inc

@@ -1868,9 +1868,10 @@ function WideStringToUCS4String(const s : WideString) : UCS4String;
         inc(destindex);
         inc(i,len);
       end;
-    result[destindex]:=UCS4Char(0);
-    { destindex <= slen }
-    setlength(result,destindex);
+    { destindex <= slen (surrogate pairs may have been merged) }
+    { destindex+1 for terminating #0 (dynamic arrays are       }
+    { implicitely filled with zero)                            }
+    setlength(result,destindex+1);
   end;
 
 
@@ -1913,9 +1914,10 @@ function UCS4StringToWideString(const s : UCS4String) : WideString;
     resindex : SizeInt;
     len      : longint;
   begin
-    SetLength(result,length(s));
+    { skip terminating #0 }
+    SetLength(result,length(s)-1);
     resindex:=1;
-    for i:=0 to high(s) do
+    for i:=0 to high(s)-1 do
       ConcatUTF32ToWideStr(s[i],result,resindex);
     { adjust result length (may be too big due to growing }
     { for surrogate pairs)                                }

+ 6 - 6
rtl/unix/cwstring.pp

@@ -103,7 +103,7 @@ const
 { unicode encoding name }
 {$ifdef FPC_LITTLE_ENDIAN}
   unicode_encoding2 = 'UTF-16LE';
-  unicode_encoding4 = 'UCS-4LE'; 
+  unicode_encoding4 = 'UCS-4LE';
 {$else  FPC_LITTLE_ENDIAN}
   unicode_encoding2 = 'UTF-16BE';
   unicode_encoding4 = 'UCS-4BE';
@@ -140,11 +140,11 @@ procedure fpc_rangeerror; [external name 'FPC_RANGEERROR'];
 threadvar
   iconv_ansi2wide,
   iconv_wide2ansi : iconv_t;
- 
+
 {$ifdef beos}
 function nl_langinfo(__item:nl_item):pchar;
 begin
-  {$warning TODO BeOS nl_langinfo or more uptodate port of iconv...}  
+  {$warning TODO BeOS nl_langinfo or more uptodate port of iconv...}
   // Now implement the minimum required to correctly initialize WideString support
   case __item of
     CODESET : Result := 'UTF-8'; // BeOS use UTF-8
@@ -152,7 +152,7 @@ begin
     begin
       Assert(False, 'nl_langinfo was called with an unknown nl_item value');
       Result := '';
-    end;    
+    end;
   end;
 end;
 {$endif}
@@ -439,7 +439,7 @@ function UpperAnsiString(const s : AnsiString) : AnsiString;
             mblen:= 1;
           end
         else
-{$ifndef beos}          
+{$ifndef beos}
           mblen:=mbrtowc(@wc, pchar(@s[i]), slen-i+1, @ombstate);
 {$else not beos}
           mblen:=mbtowc(@wc, pchar(@s[i]), slen-i+1);
@@ -503,7 +503,7 @@ function WideStringToUCS4StringNoNulls(const s : WideString) : UCS4String;
       end;
     result[destindex]:=UCS4Char(0);
     { destindex <= slen }
-    setlength(result,destindex);
+    setlength(result,destindex+1);
   end;
 
 

+ 3 - 2
tests/test/twide5.pp

@@ -21,14 +21,15 @@ begin
      (ws[8]<>#$dc04) then
     halt(1);
   us:=WideStringToUCS4String(ws);
-  if (length(us)<>7) or
+  if (length(us)<>8) or
      (us[0]<>UCS4Char(widechar('é'))) or
      (us[1]<>UCS4Char(widechar('ł'))) or
      (us[2]<>UCS4Char(widechar('Ł'))) or
      (us[3]<>UCS4Char(widechar('ć'))) or
      (us[4]<>UCS4Char(widechar('ç'))) or
      (us[5]<>UCS4Char(widechar('Ź'))) or
-     (us[6]<>UCS4Char($2F804)) then
+     (us[6]<>UCS4Char($2F804)) or
+     (us[7]<>UCS4Char(0)) then
     halt(2);
   ws:=UCS4StringToWideString(us);
   if (length(ws)<>8) or

+ 2 - 2
tests/test/units/sysutils/tastrcmp.pp

@@ -137,8 +137,8 @@ begin
   check(ansistrlicomp('c', 'b', 1) > 0, 5);
   check(ansistrlicomp('abc', 'AbC', 3) = 0, 6);
   check(ansistrlicomp('0123456789', '0123456789', 10) = 0, 7);
-  check(ansistrlicomp(#0'123456789', '0123456789', 10) < 0, 8);
-  check(ansistrlicomp('AbC', #0'bC', 3) > 0, 9);
+  check(ansistrlicomp(#0'123456789', #0'123456799', 10) < 0, 8);
+  check(ansistrlicomp(#0'bD', #0'bC', 3) > 0, 9);
   check(ansistrlicomp('AbC', 'A'#0#0,3) > 0, 10);
   check(ansistrlicomp('AbC', 'Ab'#0, 3) > 0, 11);
   check(ansistrlicomp('AbC', 'ab'#0, 3) > 0, 12);