jvalue JPStringType::convertToJava(HostRef* obj) { TRACE_IN("JPStringType::convertToJava"); JPCleaner cleaner; jvalue v; if (JPEnv::getHost()->isNone(obj)) { v.l = NULL; return v; } if (JPEnv::getHost()->isWrapper(obj)) { return JPEnv::getHost()->getWrapperValue(obj); } if (JPEnv::getHost()->isObject(obj)) { JPObject* o = JPEnv::getHost()->asObject(obj); JPClass* oc = o->getClass(); if (oc->getName().getSimpleName() == "java.lang.String") { v.l = o->getObject(); return v; } } JCharString wstr = JPEnv::getHost()->stringAsJCharString(obj); jchar* jstr = new jchar[wstr.length()+1]; jstr[wstr.length()] = 0; for (size_t i = 0; i < wstr.length(); i++) { jstr[i] = (jchar)wstr[i]; } jstring res = JPEnv::getJava()->NewString(jstr, (jint)wstr.length()); delete[] jstr; v.l = res; return v; TRACE_OUT; }
jstring javaStringFromJCharString(JCharString& wstr) { jstring result = JPEnv::getJava()->NewString(wstr.c_str(), (jint)wstr.length()); return result; }