diff --git a/native/jni/src/binary_format.h b/native/jni/src/binary_format.h index 16d57a6ce..f59302460 100644 --- a/native/jni/src/binary_format.h +++ b/native/jni/src/binary_format.h @@ -45,6 +45,7 @@ class BinaryFormat { static int detectFormat(const uint8_t* const dict); static unsigned int getHeaderSize(const uint8_t* const dict); + static unsigned int getFlags(const uint8_t* const dict); static int getGroupCountAndForwardPointer(const uint8_t* const dict, int* pos); static uint8_t getFlagsAndForwardPointer(const uint8_t* const dict, int* pos); static int32_t getCharCodeAndForwardPointer(const uint8_t* const dict, int* pos); @@ -65,6 +66,15 @@ class BinaryFormat { const int length); static int getWordAtAddress(const uint8_t* const root, const int address, const int maxDepth, uint16_t* outWord); + + // Flags for special processing + // Those *must* match the flags in makedict (BinaryDictInputOutput#*_PROCESSING_FLAG) or + // something very bad (like, the apocalypse) will happen. Please update both at the same time. + enum { + REQUIRES_GERMAN_UMLAUT_PROCESSING = 0x1, + REQUIRES_FRENCH_LIGATURES_PROCESSING = 0x4 + }; + const static unsigned int NO_FLAGS = 0; }; inline int BinaryFormat::detectFormat(const uint8_t* const dict) { @@ -89,6 +99,15 @@ inline int BinaryFormat::detectFormat(const uint8_t* const dict) { } } +inline unsigned int BinaryFormat::getFlags(const uint8_t* const dict) { + switch (detectFormat(dict)) { + case 1: + return NO_FLAGS; + default: + return (dict[6] << 8) + dict[7]; + } +} + inline unsigned int BinaryFormat::getHeaderSize(const uint8_t* const dict) { switch (detectFormat(dict)) { case 1: diff --git a/native/jni/src/unigram_dictionary.cpp b/native/jni/src/unigram_dictionary.cpp index ea10e58a7..06a2a6b5b 100644 --- a/native/jni/src/unigram_dictionary.cpp +++ b/native/jni/src/unigram_dictionary.cpp @@ -171,7 +171,7 @@ int UnigramDictionary::getSuggestions(ProximityInfo *proximityInfo, queuePool->clearAll(); Correction* masterCorrection = correction; - if (REQUIRES_GERMAN_UMLAUT_PROCESSING & flags) + if (BinaryFormat::REQUIRES_GERMAN_UMLAUT_PROCESSING & flags) { // Incrementally tune the word and try all possibilities int codesBuffer[getCodesBufferSize(codes, codesSize)]; int xCoordinatesBuffer[codesSize]; @@ -181,7 +181,7 @@ int UnigramDictionary::getSuggestions(ProximityInfo *proximityInfo, codesSize, flags, codes, codesSize, 0, codesBuffer, masterCorrection, queuePool, GERMAN_UMLAUT_DIGRAPHS, sizeof(GERMAN_UMLAUT_DIGRAPHS) / sizeof(GERMAN_UMLAUT_DIGRAPHS[0])); - } else if (REQUIRES_FRENCH_LIGATURES_PROCESSING & flags) { + } else if (BinaryFormat::REQUIRES_FRENCH_LIGATURES_PROCESSING & flags) { int codesBuffer[getCodesBufferSize(codes, codesSize)]; int xCoordinatesBuffer[codesSize]; int yCoordinatesBuffer[codesSize]; diff --git a/native/jni/src/unigram_dictionary.h b/native/jni/src/unigram_dictionary.h index c61b02620..e2ff6ad66 100644 --- a/native/jni/src/unigram_dictionary.h +++ b/native/jni/src/unigram_dictionary.h @@ -149,9 +149,7 @@ class UnigramDictionary { // or something very bad (like, the apocalypse) will happen. // Please update both at the same time. enum { - REQUIRES_GERMAN_UMLAUT_PROCESSING = 0x1, USE_FULL_EDIT_DISTANCE = 0x2, - REQUIRES_FRENCH_LIGATURES_PROCESSING = 0x4 }; static const digraph_t GERMAN_UMLAUT_DIGRAPHS[]; static const digraph_t FRENCH_LIGATURES_DIGRAPHS[];