diff options
author | 2013-09-03 11:42:23 +0000 | |
---|---|---|
committer | 2013-09-03 11:42:24 +0000 | |
commit | 64621cf49b609ec5c8081cce202ae2f016be20bd (patch) | |
tree | 0ed5ac70fbef3bc121b381948e1b5b9e5f4b3a41 | |
parent | 648088aa9ee9971ec08d6720cd383f555d18b93c (diff) | |
parent | 9e3082e0168ff40ec532d5fef162d93426b550a1 (diff) | |
download | latinime-64621cf49b609ec5c8081cce202ae2f016be20bd.tar.gz latinime-64621cf49b609ec5c8081cce202ae2f016be20bd.tar.xz latinime-64621cf49b609ec5c8081cce202ae2f016be20bd.zip |
Merge "Add DynamicShortcutListPolicy::copyAllShortcuts()."
-rw-r--r-- | native/jni/src/suggest/policyimpl/dictionary/shortcut/dynamic_shortcut_list_policy.h | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/native/jni/src/suggest/policyimpl/dictionary/shortcut/dynamic_shortcut_list_policy.h b/native/jni/src/suggest/policyimpl/dictionary/shortcut/dynamic_shortcut_list_policy.h index 4bf745fa3..5e9c52950 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/shortcut/dynamic_shortcut_list_policy.h +++ b/native/jni/src/suggest/policyimpl/dictionary/shortcut/dynamic_shortcut_list_policy.h @@ -31,7 +31,7 @@ namespace latinime { */ class DynamicShortcutListPolicy : public DictionaryShortcutsStructurePolicy { public: - explicit DynamicShortcutListPolicy(const BufferWithExtendableBuffer *const buffer) + explicit DynamicShortcutListPolicy(BufferWithExtendableBuffer *const buffer) : mBuffer(buffer) {} ~DynamicShortcutListPolicy() {} @@ -82,10 +82,33 @@ class DynamicShortcutListPolicy : public DictionaryShortcutsStructurePolicy { } } + // Copy shortcuts from the shortcut list that starts at fromPos to toPos and advance these + // positions after the shortcut lists. + void copyAllShortcuts(int *const fromPos, int *const toPos) { + const bool usesAdditionalBuffer = mBuffer->isInAdditionalBuffer(*fromPos); + const uint8_t *const buffer = mBuffer->getBuffer(usesAdditionalBuffer); + if (usesAdditionalBuffer) { + *fromPos -= mBuffer->getOriginalBufferSize(); + } + const int shortcutListSize = ShortcutListReadingUtils + ::getShortcutListSizeAndForwardPointer(buffer, fromPos); + // Copy shortcut list size. + mBuffer->writeUintAndAdvancePosition( + shortcutListSize + ShortcutListReadingUtils::getShortcutListSizeFieldSize(), + ShortcutListReadingUtils::getShortcutListSizeFieldSize(), toPos); + for (int i = 0; i < shortcutListSize; ++i) { + const uint8_t data = ByteArrayUtils::readUint8AndAdvancePosition(buffer, fromPos); + mBuffer->writeUintAndAdvancePosition(data, 1 /* size */, toPos); + } + if (usesAdditionalBuffer) { + *fromPos += mBuffer->getOriginalBufferSize(); + } + } + private: DISALLOW_IMPLICIT_CONSTRUCTORS(DynamicShortcutListPolicy); - const BufferWithExtendableBuffer *const mBuffer; + BufferWithExtendableBuffer *const mBuffer; }; } // namespace latinime #endif // LATINIME_DYNAMIC_SHORTCUT_LIST_POLICY_H |