Menu

#241 Utf8Encode and Utf8Decode doesn't work well on SChinese

build 0.1.0.31x
open-wont-fix
None
9
2004-02-23
2004-02-21
Turbo Han
No

Hi, All:

In the FMA , the programe use the utf8encode and
utf8decode function to encode the character to Unicode
and decode the Unicode to the character.

But on the Simplified Chinese Operation System ,
include : Simplified Chinese XP, 2000 and etc. , these
tow function can't work well, so , in the FMA that
always make some error in the follow function: Sync
PhoneBook, Upload a contact to the Phone , Add a
contact to a group , download pics , download sound
and download the theme ...

On the English Edtion OS , doesn't have the above
problem.

Problem Description:
1. Use the Delphi 6E and the Delphi 7E make a small test
program.
2. in the form, Draw two edit controls and two button
controls : Edit1, Edit2, Button1 and Button2.
3. Copy the follow code to the Unit1.pas

----------------------------------------------
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes,
Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
str : string;
str1 : UTF8String;
str2 : string;
pwchar : PWideChar;
begin
str := edit1.Text;
if str <> '' then
begin
GetMem(pwchar, length(str)*2+1);
//Edit2.Text := AnsiToUtf8(str);
StringToWideChar(str, pwchar, length(str)*2+1);
Edit2.Text := Utf8Encode(pwchar);
FreeMem(pwchar);
end;
end;

procedure TForm1.FormShow(Sender: TObject);
begin
Edit1.Text := '';
Edit2.Text := '';
end;

procedure TForm1.Button2Click(Sender: TObject);
var
wstr : WideString;
begin
//Edit2.Text := Utf8ToAnsi(Edit2.Text);
if Edit2.Text <> '' then
begin
wstr := Utf8Decode(Edit2.Text);
edit2.Text := WideCharToString(PWideChar(wstr));
end;

end;

end.
----------------------------------------------

4. Run the test program.
5. in the edit1, input a Chinese character "&#21704;" , and click
the Encode Button, Then we can get the Encoded
charcter "&#37725;" . copy the Encoded charcter "&#37725;" into the
edit1 , then click the Decode Button , but can't decode
the charcter.

--------------------------------------------
Encode and Decode Test Table
--------------------------------------------
Test Platform: Simplified Chinese XP
--------------------------------------------
&#21704; Encode-> &#37725;
&#37725; Decode-> NULL
&#21704;&#21704; Encode-> &#37725;&#22557;&#25649;
&#37725;&#22557;&#25649; Decode-> &#21704;&#21704;
&#21704;&#21704;&#21704; Encode-> &#37725;&#22557;&#25649;&#37725;
&#37725;&#22557;&#25649;&#37725; Decode-> NULL
&#21704;&#21704;&#21704;&#21704; Encode-> &#37725;&#22557;&#25649;&#37725;&#22557;&#25649;
&#37725;&#22557;&#25649;&#37725;&#22557;&#25649; Decode-> &#21704;&#21704;&#21704;&#21704;
--------------------------------------------
Notes: NULL Means Can't Decode the character.
--------------------------------------------

6. Follow the above test, We can get a result:
In the Simplified Chinese OS, when the character nums
is odd number, the encode and decode function will
make errors, but when the character nums is even
Number, the encode and decode function works well.

Discussion

  • Turbo Han

    Turbo Han - 2004-02-21
    • labels: 492782 -->
    • priority: 5 --> 9
    • assigned_to: nobody --> z_stoichev
    • status: open --> open-wont-fix
     
  • Turbo Han

    Turbo Han - 2004-02-21

    Logged In: YES
    user_id=933267

    Some Correctional Parts:

    5. in the edit1, input a Chinese character "" , and click the
    Encode Button, Then we can get the Encoded charcter "" .
    copy the Encoded charcter "" into the edit1 , then click the
    Decode Button , but can't decode the charcter.

    --------------------------------------------
    Encode and Decode Test Table
    --------------------------------------------
    Test Platform: Simplified Chinese XP
    --------------------------------------------
    Encode->
    Decode-> NULL
    Encode-> 哈哈
    哈哈 Decode->
    Encode-> 哈哈
    哈哈 Decode-> NULL
    Encode-> 哈哈哈哈
    哈哈哈哈 Decode->
    --------------------------------------------
    Notes: NULL Means Can't Decode the character.
    --------------------------------------------

     
  • Turbo Han

    Turbo Han - 2004-02-21

    Test Program GUI

     
  • Turbo Han

    Turbo Han - 2004-02-21

    Logged In: YES
    user_id=933267

    Because the above bugs, the OBEX Folder have some Error,
    Look at the follow attach file named OBEX_Folders_bugs.JPG.

     
  • Turbo Han

    Turbo Han - 2004-02-21

    OBEX_Folders_bugs.JPG

     
  • Zdravko Stoychev

    Logged In: YES
    user_id=880616

    Ok, you're now a part of the Team, so you can fix it in CVS
    three :)

     
  • Zdravko Stoychev

    • assigned_to: z_stoichev --> magicworm
     
  • Turbo Han

    Turbo Han - 2004-02-23

    Logged In: YES
    user_id=933267

    But Now I can't fix it.
    In the English Operation System , the problem isn't a problem,
    but in the Chinese Operation System, that is a problem, Now,
    i am finding out the method to solve the problem.

     

Log in to post a comment.