aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
authorYuichiro Hanada <yhanada@google.com>2012-09-26 13:21:29 +0900
committerYuichiro Hanada <yhanada@google.com>2012-09-26 17:18:01 +0900
commit2aea34fb31f1a8a5fe24cccd1b9aab4908f2f8e2 (patch)
tree1f411f0c9dcea10db67c8d6f16a94488ce610271 /java/src
parent2ee70804e92b17016a2f042c4f6b0e94b5d23e88 (diff)
downloadlatinime-2aea34fb31f1a8a5fe24cccd1b9aab4908f2f8e2.tar.gz
latinime-2aea34fb31f1a8a5fe24cccd1b9aab4908f2f8e2.tar.xz
latinime-2aea34fb31f1a8a5fe24cccd1b9aab4908f2f8e2.zip
Add updateParentAddress.
bug: 6669677 Change-Id: I353f8ae53720cdf7a809271a28cb703709609f53
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java30
1 files changed, 30 insertions, 0 deletions
diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java
index e2c1254ce..b97be0543 100644
--- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java
+++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java
@@ -246,4 +246,34 @@ public class BinaryDictIOUtils {
buffer.position(wordPosition);
buffer.put((byte)newFlags);
}
+
+ private static void putSInt24(final FusionDictionaryBufferInterface buffer,
+ final int value) {
+ final int absValue = Math.abs(value);
+ buffer.put((byte)(((value < 0 ? 0x80 : 0) | (absValue >> 16)) & 0xFF));
+ buffer.put((byte)((absValue >> 8) & 0xFF));
+ buffer.put((byte)(absValue & 0xFF));
+ }
+
+ /**
+ * Update a parent address in a CharGroup that is addressed by groupOriginAddress.
+ *
+ * @param buffer the buffer to write.
+ * @param groupOriginAddress the address of the group.
+ * @param newParentAddress the absolute address of the parent.
+ * @param formatOptions file format options.
+ */
+ public static void updateParentAddress(final FusionDictionaryBufferInterface buffer,
+ final int groupOriginAddress, final int newParentAddress,
+ final FormatOptions formatOptions) {
+ final int originalPosition = buffer.position();
+ buffer.position(groupOriginAddress);
+ if (!formatOptions.mSupportsDynamicUpdate) {
+ throw new RuntimeException("this file format does not support parent addresses");
+ }
+ final int flags = buffer.readUnsignedByte();
+ final int parentOffset = newParentAddress - groupOriginAddress;
+ putSInt24(buffer, parentOffset);
+ buffer.position(originalPosition);
+ }
}