Add updateChildrenAddress.

Change-Id: Ic06a755d85612476e719e580469dc1cd9447286c
main
Yuichiro Hanada 2012-09-28 16:47:33 +09:00
parent 14295a2efa
commit f3aed3ea26
2 changed files with 39 additions and 4 deletions

View File

@ -17,6 +17,7 @@
package com.android.inputmethod.latin.makedict;
import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.makedict.BinaryDictInputOutput.CharEncoding;
import com.android.inputmethod.latin.makedict.BinaryDictInputOutput.FusionDictionaryBufferInterface;
import com.android.inputmethod.latin.makedict.FormatSpec.FileHeader;
import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions;
@ -279,4 +280,39 @@ public final class BinaryDictIOUtils {
putSInt24(buffer, parentOffset);
buffer.position(originalPosition);
}
private static void skipString(final FusionDictionaryBufferInterface buffer,
final boolean hasMultipleChars) {
if (hasMultipleChars) {
int character = CharEncoding.readChar(buffer);
while (character != FormatSpec.INVALID_CHARACTER) {
character = CharEncoding.readChar(buffer);
}
} else {
CharEncoding.readChar(buffer);
}
}
/**
* Update a children address in a CharGroup that is addressed by groupOriginAddress.
*
* @param buffer the buffer to write.
* @param groupOriginAddress the address of the group.
* @param newChildrenAddress the absolute address of the child.
* @param formatOptions file format options.
*/
public static void updateChildrenAddress(final FusionDictionaryBufferInterface buffer,
final int groupOriginAddress, final int newChildrenAddress,
final FormatOptions formatOptions) {
final int originalPosition = buffer.position();
buffer.position(groupOriginAddress);
final int flags = buffer.readUnsignedByte();
final int parentAddress = BinaryDictInputOutput.readParentAddress(buffer, formatOptions);
skipString(buffer, (flags & FormatSpec.FLAG_HAS_MULTIPLE_CHARS) != 0);
if ((FormatSpec.FLAG_IS_TERMINAL) != 0) buffer.readUnsignedByte();
final int childrenOffset = newChildrenAddress == FormatSpec.NO_CHILDREN_ADDRESS
? FormatSpec.NO_CHILDREN_ADDRESS : newChildrenAddress - buffer.position();
putSInt24(buffer, childrenOffset);
buffer.position(originalPosition);
}
}

View File

@ -124,8 +124,7 @@ public final class BinaryDictInputOutput {
/**
* A class grouping utility function for our specific character encoding.
*/
private static final class CharEncoding {
static final class CharEncoding {
private static final int MINIMAL_ONE_BYTE_CHARACTER_VALUE = 0x20;
private static final int MAXIMAL_ONE_BYTE_CHARACTER_VALUE = 0xFF;
@ -263,7 +262,7 @@ public final class BinaryDictInputOutput {
* @param buffer the buffer, positioned over an encoded character.
* @return the character code.
*/
private static int readChar(final FusionDictionaryBufferInterface buffer) {
static int readChar(final FusionDictionaryBufferInterface buffer) {
int character = buffer.readUnsignedByte();
if (!fitsOnOneByte(character)) {
if (FormatSpec.GROUP_CHARACTERS_TERMINATOR == character) {
@ -1219,7 +1218,7 @@ public final class BinaryDictInputOutput {
}
}
private static int readParentAddress(final FusionDictionaryBufferInterface buffer,
static int readParentAddress(final FusionDictionaryBufferInterface buffer,
final FormatOptions formatOptions) {
if (supportsDynamicUpdate(formatOptions)) {
final int parentAddress = buffer.readUnsignedInt24();