Home Help Center

Mutilanguage problem

febfeb Member
My demo is below :

Printer.ice
...
nonmutating string testMutiLang(string s);
...

PrinterI.cpp
string PrinterI::testMutiLang(const string & s, const Ice::Current&) const
{
cout << "receive " << s << endl;

string sRet;

sRet="Iam’†•¶chinese" ; // middle part is represent chinese language in my real code

return sRet ;
....

the client code in c

string sRet = twoway->testMutiLang(sOut);
cout << "client get from server : " << sRet << endl;

when run I get the right output

the client in java

String sRet = twoway.testMutiLang(sOut);

System.out.println("client get from server ") ;
System.out.println(" ¥•s¥’†•¶ ") ;
System.out.println( sRet );

when run I get Iam????chinese

by the way I use linux slackware gcc 3.2.3 jdk 1.4.2
and if use java to output chinese , is right .

env set LC_ALL=zh_CN

how can I resolve this problem?
expect your help . thx.

Comments

  • marcmarc FloridaAdministrators, ZeroC Staff Marc LaukienOrganization: ZeroC, Inc.Project: The Internet Communications Engine ZeroC Staff
    It's not exactly clear to me in your example which process is sending what and which process is printing the string. However, did you make sure that your string is Unicode? For C++, you must use Unicode in UTF-8 format. There are conversion functions between UTF-16 std::wstring and UTF-8 std::string in src/IceUtil/Unicode.cpp. In Java, strings are alway Unicode. Ice does not convert between Unicode and whatever local character set you are using, so if your editor or terminal window doesn't use Unicode, you must convert between your local character set and Unicode in your application code.
  • febfeb Member
    I know futher , but problem still exist

    Thank marc , I read some articles about java encoding , then I try test my program again , and problem still exist . This time I upload the whole test program zipped in tar.gz .

    My Action in turn is :

    1 - icepacknode --Ice.Config=config --warn

    2 - ./client

    this step , I get the right string return by PrinterI::testMultiLang
    and at the same time server side get right input :

    receive string is : Äã

    3 - java -cp ./classes/:/usr/local/data/icej/lib/Ice.jar M4.client

    this step I can not get the right string returned by PrinterI::testMultiLang and at the same time
    client side get
    char of sRet is
    0 - fffd
    1 - fffd
    byte of sRet is
    0 - 3f
    1 - 3f

    server side get input string in unicode
    src line : cout << " -" << i << " - "<< hex << (int)ws << endl ;
    work and output : -0 - 4f60


    by the way :

    the code in PrinterI.cpp
    ....
    char sTmp[3] ;
    memset(sTmp,0,sizeof(sTmp)) ;

    sTmp[0] = 0xc4 ;
    sTmp[1] = 0xe3 ;
    sReturnString = sTmp ; //here return chinese string
    ....

    and the code in cient.java
    byte b[]={(byte)'\u00c4',(byte)'\u00e3'};
    String strInput ="" ;
    try {
    strInput = new String (b,"GBK") ;
    System.out.print( " strInput composed" ) ;
    System.out.print( strInput ) ;
    System.out.print( " \r\n " ) ;
    }
    catch ( java.io.UnsupportedEncodingException ex )
    {
    System.out.println("catch UnsupportedEncodingException") ;
    }

    are both equal to
    sReturnString = "Äã" ; // string composed by one chinese letter


    May you see the source code and provide some advice .

    thx .
  • marcmarc FloridaAdministrators, ZeroC Staff Marc LaukienOrganization: ZeroC, Inc.Project: The Internet Communications Engine ZeroC Staff
    Re: I know futher , but problem still exist
    Originally posted by feb

    strInput = new String (b,"GBK") ;

    Try this instead:

    strInput = new String(b, 0, 2, "UTF8");
  • febfeb Member
    Problem solved

    I solved this problem by calling iconv in c ;

    this function help me transfer gbk to utf8 , then java receive the string in right coding format.

    very appreciate your answers , and ICE is a good and useful thing .
Sign In or Register to comment.