diff options
author | 2013-10-18 08:00:04 +0000 | |
---|---|---|
committer | 2013-10-18 08:00:04 +0000 | |
commit | 7e7fe6057a61bd5d35529f19a2537e37f612ad31 (patch) | |
tree | c5d0a12b832780270afae256199115fc77893a8f /java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java | |
parent | a62dc28121d72978d527eec2791d1caf43b563b8 (diff) | |
parent | 520f612849fcf6909e83b9d82b91b01d44039488 (diff) | |
download | latinime-7e7fe6057a61bd5d35529f19a2537e37f612ad31.tar.gz latinime-7e7fe6057a61bd5d35529f19a2537e37f612ad31.tar.xz latinime-7e7fe6057a61bd5d35529f19a2537e37f612ad31.zip |
Merge "(1/2) Implement insertWord in Ver4DictUpdater."
Diffstat (limited to 'java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java index 8109321b6..9f1af0192 100644 --- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java +++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java @@ -169,6 +169,14 @@ public final class BinaryDictDecoderUtils { return size; } + static int getCharArraySize(final int[] chars, final int start, final int end) { + int size = 0; + for (int i = start; i < end; ++i) { + size += getCharSize(chars[i]); + } + return size; + } + /** * Writes a char array to a byte buffer. * @@ -248,6 +256,40 @@ public final class BinaryDictDecoderUtils { } /** + * Writes an array of code points with our character format to an OutputStream. + * + * This will also write the terminator byte. + * + * @param stream the OutputStream to write to. + * @param codePoints the array of code points + * @return the size written, in bytes. + */ + // TODO: Merge this method with writeCharArray and rename the various write* methods to + // make the difference clear. + static int writeCodePoints(final OutputStream stream, final int[] codePoints, + final int startIndex, final int endIndex) + throws IOException { + int written = 0; + for (int i = startIndex; i < endIndex; ++i) { + final int codePoint = codePoints[i]; + final int charSize = getCharSize(codePoint); + if (1 == charSize) { + stream.write((byte) codePoint); + } else { + stream.write((byte) (0xFF & (codePoint >> 16))); + stream.write((byte) (0xFF & (codePoint >> 8))); + stream.write((byte) (0xFF & codePoint)); + } + written += charSize; + } + if (endIndex - startIndex > 1) { + stream.write(FormatSpec.PTNODE_CHARACTERS_TERMINATOR); + written += FormatSpec.PTNODE_TERMINATOR_SIZE; + } + return written; + } + + /** * Reads a string from a DictBuffer. This is the converse of the above method. */ static String readString(final DictBuffer dictBuffer) { |