Results 1 to 5 of 5

Thread: Mutilanguage problem

  1. #1
    feb
    feb is offline Registered User
    Join Date
    Nov 2004
    Posts
    5

    Mutilanguage problem

    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(" 是不是中文 ") ;
    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.
    FEB Son Of Mz
    Husband Of Medea

  2. #2
    marc's Avatar
    marc is offline ZeroC Staff
    Name: Marc Laukien
    Organization: ZeroC, Inc.
    Project: The Internet Communications Engine
    Join Date
    Feb 2003
    Location
    Florida
    Posts
    1,860
    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.

  3. #3
    feb
    feb is offline Registered User
    Join Date
    Nov 2004
    Posts
    5

    Smile 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[i] << 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 .
    Attached Files Attached Files
    FEB Son Of Mz
    Husband Of Medea

  4. #4
    marc's Avatar
    marc is offline ZeroC Staff
    Name: Marc Laukien
    Organization: ZeroC, Inc.
    Project: The Internet Communications Engine
    Join Date
    Feb 2003
    Location
    Florida
    Posts
    1,860

    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");

  5. #5
    feb
    feb is offline Registered User
    Join Date
    Nov 2004
    Posts
    5

    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 .
    FEB Son Of Mz
    Husband Of Medea

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •