From 520f612849fcf6909e83b9d82b91b01d44039488 Mon Sep 17 00:00:00 2001 From: Yuichiro Hanada Date: Fri, 4 Oct 2013 15:33:25 +0900 Subject: (1/2) Implement insertWord in Ver4DictUpdater. Change-Id: Ia3079d5ef00ca7d831c91fb9220ad9c17038c5a3 --- .../latin/makedict/BinaryDictDecoderUtils.java | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java') 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. * @@ -247,6 +255,40 @@ public final class BinaryDictDecoderUtils { return written; } + /** + * 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. */ -- cgit v1.2.3-83-g751a