// Supply operator methods for converting the UTFString to a string
// or char*, making it easy to pass UTFString 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 UTFString represents
char* mUtfChars; // Pointer to the data returned by GetStringUTFChars
string mString; // string buffer for holding the "value" of this instance
};
我将它改了改:
class JNIString {
private:
JNIString (); // Default ctor - disallowed
public:
// Create a new instance from the specified jstring
JNIString(JNIEnv* env, const jstring& str) :
mEnv (env) {
const jchar* w_buffer = env->GetStringChars (str, 0);
mJstr = env->NewString (w_buffer,