JNI中文处理问题小结[12]

[入库:2006年2月23日] [更新:2007年3月24日]

本文简介:

        strcpy (mChars, rhs.c_str ());

        mString = rhs.c_str ();

        return
 *this;
    }


    // Supply operator methods for converting the JNIString to a string
    // or char*, making it easy to pass JNIString arguments to functions
    // that require string or char* parameters.
    string & GetString() { return mString; }
    operator
 string() { return mString; }
    operator const
 char* () { return mString.c_str (); }
    operator
 jstring() { return mJstr; }

private
:

    JNIEnv* mEnv;   // The enviroment pointer for this native method.
    jstring mJstr;  // A copy of the jstring object that this JNIString represents
    char* mChars;   // Pointer to a ANSI code page char array
    string mString; // string buffer for holding the "value" of this instance (ANSI code page)
};
后者除了将面向UTF编码改成了面向ANSI编码外,还去掉了operator =(const char* ptr)的定义,因为operator =(const string& rhs)可以在需要的时候替代前者而无需任何额外编码。(因为按照C++规范,const reference可以自动转换,详见本人另一文章《关于const reference的几点说明》http://blog.vckbase.com/billdavid/archive/2004/11/11/1453.html)

本文关键:JNI中文处理问题小结
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top