|
3 | 3 | #include <opencc/SimpleConverter.hpp>
|
4 | 4 | #include <opencc/DictConverter.hpp>
|
5 | 5 | #include "rime_jni.h"
|
6 |
| -using namespace opencc; |
7 |
| -using std::string; |
| 6 | +#include "jni-utils.h" |
8 | 7 |
|
9 | 8 | // opencc
|
10 | 9 |
|
11 | 10 | extern "C"
|
12 | 11 | JNIEXPORT jstring JNICALL
|
13 |
| -Java_com_osfans_trime_core_Rime_get_1opencc_1version(JNIEnv *env, jclass thiz) { |
| 12 | +Java_com_osfans_trime_data_opencc_OpenCCDictManager_getOpenCCVersion(JNIEnv *env, jclass clazz) { |
14 | 13 | return env->NewStringUTF(OPENCC_VERSION);
|
15 | 14 | }
|
16 | 15 |
|
17 | 16 | extern "C"
|
18 | 17 | JNIEXPORT jstring JNICALL
|
19 |
| -Java_com_osfans_trime_core_Rime_opencc_1convert(JNIEnv *env, jclass thiz, jstring line, jstring name) { |
20 |
| - if (name == NULL) return line; |
21 |
| - const char* s = env->GetStringUTFChars(name, NULL); |
22 |
| - string str(s); |
23 |
| - SimpleConverter converter(str); |
24 |
| - env->ReleaseStringUTFChars(name, s); |
25 |
| - const char* input = env->GetStringUTFChars(line, NULL); |
26 |
| - const string& converted = converter.Convert(input); |
27 |
| - env->ReleaseStringUTFChars(line, input); |
28 |
| - s = converted.c_str(); |
29 |
| - return env->NewStringUTF(s); |
| 18 | +Java_com_osfans_trime_data_opencc_OpenCCDictManager_openCCLineConv(JNIEnv *env, jclass clazz, |
| 19 | + jstring input, |
| 20 | + jstring config_file_name) { |
| 21 | + opencc::SimpleConverter converter(CString(env, config_file_name)); |
| 22 | + return env->NewStringUTF(converter.Convert(*CString(env, input)).data()); |
30 | 23 | }
|
31 | 24 |
|
32 | 25 | extern "C"
|
33 | 26 | JNIEXPORT void JNICALL
|
34 |
| -Java_com_osfans_trime_data_opencc_OpenCCDictManager_openccDictConv(JNIEnv *env, jclass clazz, |
| 27 | +Java_com_osfans_trime_data_opencc_OpenCCDictManager_openCCDictConv(JNIEnv *env, jclass clazz, |
35 | 28 | jstring src, jstring dest,
|
36 | 29 | jboolean mode) {
|
37 |
| - using namespace opencc; |
38 |
| - const char *src_file = env->GetStringUTFChars(src, nullptr); |
39 |
| - const char *dest_file = env->GetStringUTFChars(dest, nullptr); |
| 30 | + auto src_file = CString(env, src); |
| 31 | + auto dest_file = CString(env, dest); |
40 | 32 | if (mode) {
|
41 |
| - std::string from = "ocd2"; |
42 |
| - std::string to = "text"; |
43 |
| - ConvertDictionary(src_file, dest_file, from, to); |
| 33 | + opencc::ConvertDictionary(src_file, dest_file, "ocd2", "text"); |
44 | 34 | } else {
|
45 |
| - std::string from = "text"; |
46 |
| - std::string to = "ocd2"; |
47 |
| - ConvertDictionary(src_file, dest_file, from, to); |
| 35 | + opencc::ConvertDictionary(src_file, dest_file, "text", "ocd2"); |
48 | 36 | }
|
49 |
| - env->ReleaseStringUTFChars(src, src_file); |
50 |
| - env->ReleaseStringUTFChars(dest, dest_file); |
51 | 37 | }
|
0 commit comments