am 361881b8: Merge "Separate JniDataUtils::constructAttributeMap()."
* commit '361881b82b387345ca8ddfad401feb71c21bee55': Separate JniDataUtils::constructAttributeMap().main
commit
1f5d2f6746
|
@ -24,6 +24,7 @@
|
||||||
#include "suggest/policyimpl/dictionary/utils/dict_file_writing_utils.h"
|
#include "suggest/policyimpl/dictionary/utils/dict_file_writing_utils.h"
|
||||||
#include "utils/autocorrection_threshold_utils.h"
|
#include "utils/autocorrection_threshold_utils.h"
|
||||||
#include "utils/char_utils.h"
|
#include "utils/char_utils.h"
|
||||||
|
#include "utils/jni_data_utils.h"
|
||||||
#include "utils/time_keeper.h"
|
#include "utils/time_keeper.h"
|
||||||
|
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
|
@ -43,29 +44,9 @@ static jboolean latinime_BinaryDictionaryUtils_createEmptyDictFile(JNIEnv *env,
|
||||||
if (keyCount != valueCount) {
|
if (keyCount != valueCount) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
DictionaryHeaderStructurePolicy::AttributeMap attributeMap =
|
||||||
DictionaryHeaderStructurePolicy::AttributeMap attributeMap;
|
JniDataUtils::constructAttributeMap(env, attributeKeyStringArray,
|
||||||
for (int i = 0; i < keyCount; i++) {
|
attributeValueStringArray);
|
||||||
jstring keyString = static_cast<jstring>(
|
|
||||||
env->GetObjectArrayElement(attributeKeyStringArray, i));
|
|
||||||
const jsize keyUtf8Length = env->GetStringUTFLength(keyString);
|
|
||||||
char keyChars[keyUtf8Length + 1];
|
|
||||||
env->GetStringUTFRegion(keyString, 0, env->GetStringLength(keyString), keyChars);
|
|
||||||
keyChars[keyUtf8Length] = '\0';
|
|
||||||
DictionaryHeaderStructurePolicy::AttributeMap::key_type key;
|
|
||||||
HeaderReadWriteUtils::insertCharactersIntoVector(keyChars, &key);
|
|
||||||
|
|
||||||
jstring valueString = static_cast<jstring>(
|
|
||||||
env->GetObjectArrayElement(attributeValueStringArray, i));
|
|
||||||
const jsize valueUtf8Length = env->GetStringUTFLength(valueString);
|
|
||||||
char valueChars[valueUtf8Length + 1];
|
|
||||||
env->GetStringUTFRegion(valueString, 0, env->GetStringLength(valueString), valueChars);
|
|
||||||
valueChars[valueUtf8Length] = '\0';
|
|
||||||
DictionaryHeaderStructurePolicy::AttributeMap::mapped_type value;
|
|
||||||
HeaderReadWriteUtils::insertCharactersIntoVector(valueChars, &value);
|
|
||||||
attributeMap[key] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return DictFileWritingUtils::createEmptyDictFile(filePathChars, static_cast<int>(dictVersion),
|
return DictFileWritingUtils::createEmptyDictFile(filePathChars, static_cast<int>(dictVersion),
|
||||||
CharUtils::convertShortArrayToIntVector(localeCodePoints, localeLength), &attributeMap);
|
CharUtils::convertShortArrayToIntVector(localeCodePoints, localeLength), &attributeMap);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "jni.h"
|
#include "jni.h"
|
||||||
|
#include "suggest/core/policy/dictionary_header_structure_policy.h"
|
||||||
|
#include "suggest/policyimpl/dictionary/header/header_read_write_utils.h"
|
||||||
|
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
|
|
||||||
|
@ -36,6 +38,33 @@ class JniDataUtils {
|
||||||
env->GetIntArrayRegion(array, 0 /* start */, arrayLength, outVector->data());
|
env->GetIntArrayRegion(array, 0 /* start */, arrayLength, outVector->data());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static DictionaryHeaderStructurePolicy::AttributeMap constructAttributeMap(JNIEnv *env,
|
||||||
|
jobjectArray attributeKeyStringArray, jobjectArray attributeValueStringArray) {
|
||||||
|
DictionaryHeaderStructurePolicy::AttributeMap attributeMap;
|
||||||
|
const int keyCount = env->GetArrayLength(attributeKeyStringArray);
|
||||||
|
for (int i = 0; i < keyCount; i++) {
|
||||||
|
jstring keyString = static_cast<jstring>(
|
||||||
|
env->GetObjectArrayElement(attributeKeyStringArray, i));
|
||||||
|
const jsize keyUtf8Length = env->GetStringUTFLength(keyString);
|
||||||
|
char keyChars[keyUtf8Length + 1];
|
||||||
|
env->GetStringUTFRegion(keyString, 0, env->GetStringLength(keyString), keyChars);
|
||||||
|
keyChars[keyUtf8Length] = '\0';
|
||||||
|
DictionaryHeaderStructurePolicy::AttributeMap::key_type key;
|
||||||
|
HeaderReadWriteUtils::insertCharactersIntoVector(keyChars, &key);
|
||||||
|
|
||||||
|
jstring valueString = static_cast<jstring>(
|
||||||
|
env->GetObjectArrayElement(attributeValueStringArray, i));
|
||||||
|
const jsize valueUtf8Length = env->GetStringUTFLength(valueString);
|
||||||
|
char valueChars[valueUtf8Length + 1];
|
||||||
|
env->GetStringUTFRegion(valueString, 0, env->GetStringLength(valueString), valueChars);
|
||||||
|
valueChars[valueUtf8Length] = '\0';
|
||||||
|
DictionaryHeaderStructurePolicy::AttributeMap::mapped_type value;
|
||||||
|
HeaderReadWriteUtils::insertCharactersIntoVector(valueChars, &value);
|
||||||
|
attributeMap[key] = value;
|
||||||
|
}
|
||||||
|
return attributeMap;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DISALLOW_IMPLICIT_CONSTRUCTORS(JniDataUtils);
|
DISALLOW_IMPLICIT_CONSTRUCTORS(JniDataUtils);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue