diff options
Diffstat (limited to 'native/jni')
10 files changed, 33 insertions, 40 deletions
diff --git a/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp b/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp index 3a896dbad..716bda5a7 100644 --- a/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp +++ b/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp @@ -87,7 +87,7 @@ static jlong latinime_BinaryDictionary_open(JNIEnv *env, jclass clazz, jstring s char sourceDirChars[sourceDirUtf8Length + 1]; env->GetStringUTFRegion(sourceDir, 0, env->GetStringLength(sourceDir), sourceDirChars); sourceDirChars[sourceDirUtf8Length] = '\0'; - DictionaryStructureWithBufferPolicy::StructurePoilcyPtr dictionaryStructureWithBufferPolicy = + DictionaryStructureWithBufferPolicy::StructurePolicyPtr dictionaryStructureWithBufferPolicy = DictionaryStructureWithBufferPolicyFactory::newDictionaryStructureWithBufferPolicy( sourceDirChars, static_cast<int>(dictOffset), static_cast<int>(dictSize), isUpdatable == JNI_TRUE); @@ -136,14 +136,6 @@ static void latinime_BinaryDictionary_close(JNIEnv *env, jclass clazz, jlong dic delete dictionary; } -static bool latinime_BinaryDictionary_hasValidContents(JNIEnv *env, jclass clazz, - jlong dict) { - Dictionary *dictionary = reinterpret_cast<Dictionary *>(dict); - if (!dictionary) return false; - // TODO: check format version - return true; -} - static int latinime_BinaryDictionary_getFormatVersion(JNIEnv *env, jclass clazz, jlong dict) { Dictionary *dictionary = reinterpret_cast<Dictionary *>(dict); if (!dictionary) return 0; @@ -482,11 +474,6 @@ static const JNINativeMethod sMethods[] = { reinterpret_cast<void *>(latinime_BinaryDictionary_close) }, { - const_cast<char *>("hasValidContentsNative"), - const_cast<char *>("(J)Z"), - reinterpret_cast<void *>(latinime_BinaryDictionary_hasValidContents) - }, - { const_cast<char *>("getFormatVersionNative"), const_cast<char *>("(J)I"), reinterpret_cast<void *>(latinime_BinaryDictionary_getFormatVersion) diff --git a/native/jni/src/suggest/core/dictionary/dictionary.cpp b/native/jni/src/suggest/core/dictionary/dictionary.cpp index 07da8da87..e68c0a6d8 100644 --- a/native/jni/src/suggest/core/dictionary/dictionary.cpp +++ b/native/jni/src/suggest/core/dictionary/dictionary.cpp @@ -34,7 +34,7 @@ namespace latinime { const int Dictionary::HEADER_ATTRIBUTE_BUFFER_SIZE = 32; -Dictionary::Dictionary(JNIEnv *env, const DictionaryStructureWithBufferPolicy::StructurePoilcyPtr +Dictionary::Dictionary(JNIEnv *env, const DictionaryStructureWithBufferPolicy::StructurePolicyPtr &dictionaryStructureWithBufferPolicy) : mDictionaryStructureWithBufferPolicy(dictionaryStructureWithBufferPolicy), mBigramDictionary(new BigramDictionary(mDictionaryStructureWithBufferPolicy.get())), diff --git a/native/jni/src/suggest/core/dictionary/dictionary.h b/native/jni/src/suggest/core/dictionary/dictionary.h index 556b4c9db..b37b4aa18 100644 --- a/native/jni/src/suggest/core/dictionary/dictionary.h +++ b/native/jni/src/suggest/core/dictionary/dictionary.h @@ -58,8 +58,8 @@ class Dictionary { static const int KIND_FLAG_POSSIBLY_OFFENSIVE = 0x80000000; static const int KIND_FLAG_EXACT_MATCH = 0x40000000; - Dictionary(JNIEnv *env, const DictionaryStructureWithBufferPolicy::StructurePoilcyPtr - &dictionaryStructureWithBufferPoilcy); + Dictionary(JNIEnv *env, const DictionaryStructureWithBufferPolicy::StructurePolicyPtr + &dictionaryStructureWithBufferPolicy); int getSuggestions(ProximityInfo *proximityInfo, DicTraverseSession *traverseSession, int *xcoordinates, int *ycoordinates, int *times, int *pointerIds, int *inputCodePoints, @@ -113,7 +113,7 @@ class Dictionary { static const int HEADER_ATTRIBUTE_BUFFER_SIZE; - const DictionaryStructureWithBufferPolicy::StructurePoilcyPtr + const DictionaryStructureWithBufferPolicy::StructurePolicyPtr mDictionaryStructureWithBufferPolicy; const BigramDictionaryPtr mBigramDictionary; const SuggestInterfacePtr mGestureSuggest; diff --git a/native/jni/src/suggest/core/policy/dictionary_structure_with_buffer_policy.h b/native/jni/src/suggest/core/policy/dictionary_structure_with_buffer_policy.h index 07bc74fa4..c74a4ebbe 100644 --- a/native/jni/src/suggest/core/policy/dictionary_structure_with_buffer_policy.h +++ b/native/jni/src/suggest/core/policy/dictionary_structure_with_buffer_policy.h @@ -30,12 +30,12 @@ class DictionaryHeaderStructurePolicy; class DictionaryShortcutsStructurePolicy; /* - * This class abstracts structure of dictionaries. + * This class abstracts the structure of dictionaries. * Implement this policy to support additional dictionaries. */ class DictionaryStructureWithBufferPolicy { public: - typedef ExclusiveOwnershipPointer<DictionaryStructureWithBufferPolicy> StructurePoilcyPtr; + typedef ExclusiveOwnershipPointer<DictionaryStructureWithBufferPolicy> StructurePolicyPtr; virtual ~DictionaryStructureWithBufferPolicy() {} diff --git a/native/jni/src/suggest/policyimpl/dictionary/header/header_policy.h b/native/jni/src/suggest/policyimpl/dictionary/header/header_policy.h index fa5d5fa5a..29e937b3a 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/header/header_policy.h +++ b/native/jni/src/suggest/policyimpl/dictionary/header/header_policy.h @@ -78,15 +78,18 @@ class HeaderPolicy : public DictionaryHeaderStructurePolicy { ~HeaderPolicy() {} virtual int getFormatVersionNumber() const { + // Conceptually this converts the symbolic value we use in the code into the + // hardcoded of the bytes in the file. But we want the constants to be the + // same so we use them for both here. switch (mDictFormatVersion) { case FormatUtils::VERSION_2: - return 2; + return FormatUtils::VERSION_2; case FormatUtils::VERSION_3: - return 3; + return FormatUtils::VERSION_3; case FormatUtils::VERSION_4: - return 4; + return FormatUtils::VERSION_4; default: - return 0; + return FormatUtils::UNKNOWN_VERSION; } } diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/dictionary_structure_with_buffer_policy_factory.cpp b/native/jni/src/suggest/policyimpl/dictionary/structure/dictionary_structure_with_buffer_policy_factory.cpp index f3d90f81c..f1b733a9c 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/structure/dictionary_structure_with_buffer_policy_factory.cpp +++ b/native/jni/src/suggest/policyimpl/dictionary/structure/dictionary_structure_with_buffer_policy_factory.cpp @@ -28,7 +28,7 @@ namespace latinime { -/* static */ DictionaryStructureWithBufferPolicy::StructurePoilcyPtr +/* static */ DictionaryStructureWithBufferPolicy::StructurePolicyPtr DictionaryStructureWithBufferPolicyFactory ::newDictionaryStructureWithBufferPolicy(const char *const path, const int bufOffset, const int size, const bool isUpdatable) { @@ -37,12 +37,12 @@ namespace latinime { MmappedBuffer::MmappedBufferPtr mmappedBuffer = MmappedBuffer::openBuffer(path, bufOffset, size, isUpdatable); if (!mmappedBuffer.get()) { - return DictionaryStructureWithBufferPolicy::StructurePoilcyPtr(0); + return DictionaryStructureWithBufferPolicy::StructurePolicyPtr(0); } switch (FormatUtils::detectFormatVersion(mmappedBuffer.get()->getBuffer(), mmappedBuffer.get()->getBufferSize())) { case FormatUtils::VERSION_2: - return DictionaryStructureWithBufferPolicy::StructurePoilcyPtr( + return DictionaryStructureWithBufferPolicy::StructurePolicyPtr( new PatriciaTriePolicy(mmappedBuffer)); case FormatUtils::VERSION_4: { const int dictDirPathBufSize = strlen(path) + 1 /* terminator */; @@ -50,22 +50,22 @@ namespace latinime { if (!FileUtils::getFilePathWithoutSuffix(path, Ver4DictConstants::TRIE_FILE_EXTENSION, dictDirPathBufSize, dictDirPath)) { // Dictionary file name is not valid as a version 4 dictionary. - return DictionaryStructureWithBufferPolicy::StructurePoilcyPtr(0); + return DictionaryStructureWithBufferPolicy::StructurePolicyPtr(0); } const Ver4DictBuffers::Ver4DictBuffersPtr dictBuffers = Ver4DictBuffers::openVer4DictBuffers(dictDirPath, mmappedBuffer); if (!dictBuffers.get()->isValid()) { AKLOGE("DICT: The dictionary doesn't satisfy ver4 format requirements."); ASSERT(false); - return DictionaryStructureWithBufferPolicy::StructurePoilcyPtr(0); + return DictionaryStructureWithBufferPolicy::StructurePolicyPtr(0); } - return DictionaryStructureWithBufferPolicy::StructurePoilcyPtr( + return DictionaryStructureWithBufferPolicy::StructurePolicyPtr( new Ver4PatriciaTriePolicy(dictBuffers)); } default: AKLOGE("DICT: dictionary format is unknown, bad magic number"); ASSERT(false); - return DictionaryStructureWithBufferPolicy::StructurePoilcyPtr(0); + return DictionaryStructureWithBufferPolicy::StructurePolicyPtr(0); } } diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/dictionary_structure_with_buffer_policy_factory.h b/native/jni/src/suggest/policyimpl/dictionary/structure/dictionary_structure_with_buffer_policy_factory.h index 1359575f1..45237e4aa 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/structure/dictionary_structure_with_buffer_policy_factory.h +++ b/native/jni/src/suggest/policyimpl/dictionary/structure/dictionary_structure_with_buffer_policy_factory.h @@ -27,7 +27,7 @@ namespace latinime { class DictionaryStructureWithBufferPolicyFactory { public: - static DictionaryStructureWithBufferPolicy::StructurePoilcyPtr + static DictionaryStructureWithBufferPolicy::StructurePolicyPtr newDictionaryStructureWithBufferPolicy(const char *const path, const int bufOffset, const int size, const bool isUpdatable); diff --git a/native/jni/src/suggest/policyimpl/dictionary/utils/dict_file_writing_utils.cpp b/native/jni/src/suggest/policyimpl/dictionary/utils/dict_file_writing_utils.cpp index ce9223158..b463d4149 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/utils/dict_file_writing_utils.cpp +++ b/native/jni/src/suggest/policyimpl/dictionary/utils/dict_file_writing_utils.cpp @@ -34,7 +34,7 @@ const char *const DictFileWritingUtils::TEMP_FILE_SUFFIX_FOR_WRITING_DICT_FILE = const int dictVersion, const HeaderReadWriteUtils::AttributeMap *const attributeMap) { TimeKeeper::setCurrentTime(); switch (dictVersion) { - case 4: + case FormatUtils::VERSION_4: return createEmptyV4DictFile(filePath, attributeMap); default: AKLOGE("Cannot create dictionary %s because format version %d is not supported.", diff --git a/native/jni/src/suggest/policyimpl/dictionary/utils/format_utils.cpp b/native/jni/src/suggest/policyimpl/dictionary/utils/format_utils.cpp index 4843650ad..e3d783835 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/utils/format_utils.cpp +++ b/native/jni/src/suggest/policyimpl/dictionary/utils/format_utils.cpp @@ -41,11 +41,14 @@ const int FormatUtils::DICTIONARY_MINIMUM_SIZE = 12; // Dictionary format version number (2 bytes) // Options (2 bytes) // Header size (4 bytes) : integer, big endian - if (ByteArrayUtils::readUint16(dict, 4) == 2) { + // Conceptually this converts the hardcoded value of the bytes in the file into + // the symbolic value we use in the code. But we want the constants to be the + // same so we use them for both here. + if (ByteArrayUtils::readUint16(dict, 4) == VERSION_2) { return VERSION_2; - } else if (ByteArrayUtils::readUint16(dict, 4) == 3) { + } else if (ByteArrayUtils::readUint16(dict, 4) == VERSION_3) { return VERSION_3; - } else if (ByteArrayUtils::readUint16(dict, 4) == 4) { + } else if (ByteArrayUtils::readUint16(dict, 4) == VERSION_4) { return VERSION_4; } else { return UNKNOWN_VERSION; diff --git a/native/jni/src/suggest/policyimpl/dictionary/utils/format_utils.h b/native/jni/src/suggest/policyimpl/dictionary/utils/format_utils.h index b90393a53..3d14d2607 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/utils/format_utils.h +++ b/native/jni/src/suggest/policyimpl/dictionary/utils/format_utils.h @@ -29,10 +29,10 @@ namespace latinime { class FormatUtils { public: enum FORMAT_VERSION { - VERSION_2, - VERSION_3, - VERSION_4, - UNKNOWN_VERSION + VERSION_2 = 2, + VERSION_3 = 3, + VERSION_4 = 4, + UNKNOWN_VERSION = -1 }; // 32 bit magic number is stored at the beginning of the dictionary header to reject |