瀏覽代碼

rtl: fpwidestring - fix length of UnicodeStrings after UTF8ToUnicode. UTF8ToUnicode returns length + 1 for zero byte which is not needed for UnicodeString.

git-svn-id: trunk@23800 -
paul 12 年之前
父節點
當前提交
032b241c6b
共有 1 個文件被更改,包括 8 次插入3 次删除
  1. 8 3
      rtl/objpas/fpwidestring.pp

+ 8 - 3
rtl/objpas/fpwidestring.pp

@@ -302,7 +302,10 @@ begin
   if (cp=CP_UTF8) then
     begin
       destLen:=Utf8ToUnicode(nil,source,len);
-      SetLength(dest,destLen);
+      if destLen > 0 then
+        SetLength(dest,destLen-1)
+      else
+        SetLength(dest,0);
       Utf8ToUnicode(@dest[1],source,len);
       exit;
     end;
@@ -486,7 +489,8 @@ begin
     begin
       //convert to UnicodeString,uppercase,convert back to utf8
       ulen:=Utf8ToUnicode(nil,@s[1],Length(s));
-      SetLength(us,ulen);
+      if ulen>0 then
+        SetLength(us,ulen-1);
       Utf8ToUnicode(@us[1],@s[1],Length(s));
       us:=UpperUnicodeString(us);
       
@@ -557,7 +561,8 @@ begin
     begin
       //convert to UnicodeString,lowercase,convert back to utf8
       ulen:=Utf8ToUnicode(nil,@s[1],Length(s));
-      SetLength(us,ulen);
+      if ulen>0 then
+        SetLength(us,ulen-1);
       Utf8ToUnicode(@us[1],@s[1],Length(s));
       us:=LowerUnicodeString(us);