Merge "Add skipPtNode to DictDecoders."

main
Ken Wakasa 2013-10-01 09:06:39 +00:00 committed by Android (Google) Code Review
commit cc81a93b01
4 changed files with 50 additions and 0 deletions

View File

@ -288,6 +288,8 @@ public final class BinaryDictIOUtils {
return BinaryDictEncoderUtils.getByteSize(value); return BinaryDictEncoderUtils.getByteSize(value);
} }
// TODO: Remove this method.
@Deprecated
static void skipPtNode(final DictBuffer dictBuffer, final FormatOptions formatOptions) { static void skipPtNode(final DictBuffer dictBuffer, final FormatOptions formatOptions) {
final int flags = dictBuffer.readUnsignedByte(); final int flags = dictBuffer.readUnsignedByte();
BinaryDictDecoderUtils.readParentAddress(dictBuffer, formatOptions); BinaryDictDecoderUtils.readParentAddress(dictBuffer, formatOptions);

View File

@ -391,4 +391,6 @@ public abstract class DictDecoder {
return readLength; return readLength;
} }
} }
public abstract void skipPtNode(final FormatOptions formatOptions);
} }

View File

@ -231,4 +231,40 @@ public class Ver3DictDecoder extends DictDecoder {
public boolean hasNextPtNodeArray() { public boolean hasNextPtNodeArray() {
return mDictBuffer.position() != FormatSpec.NO_FORWARD_LINK_ADDRESS; return mDictBuffer.position() != FormatSpec.NO_FORWARD_LINK_ADDRESS;
} }
@Override
public void skipPtNode(final FormatOptions formatOptions) {
final int flags = PtNodeReader.readPtNodeOptionFlags(mDictBuffer);
PtNodeReader.readParentAddress(mDictBuffer, formatOptions);
BinaryDictIOUtils.skipString(mDictBuffer,
(flags & FormatSpec.FLAG_HAS_MULTIPLE_CHARS) != 0);
PtNodeReader.readChildrenAddress(mDictBuffer, flags, formatOptions);
if ((flags & FormatSpec.FLAG_IS_TERMINAL) != 0) PtNodeReader.readFrequency(mDictBuffer);
if ((flags & FormatSpec.FLAG_HAS_SHORTCUT_TARGETS) != 0) {
final int shortcutsSize = mDictBuffer.readUnsignedShort();
mDictBuffer.position(mDictBuffer.position() + shortcutsSize
- FormatSpec.PTNODE_SHORTCUT_LIST_SIZE_SIZE);
}
if ((flags & FormatSpec.FLAG_HAS_BIGRAMS) != 0) {
int bigramCount = 0;
while (bigramCount++ < FormatSpec.MAX_BIGRAMS_IN_A_PTNODE) {
final int bigramFlags = mDictBuffer.readUnsignedByte();
switch (bigramFlags & FormatSpec.MASK_BIGRAM_ATTR_ADDRESS_TYPE) {
case FormatSpec.FLAG_BIGRAM_ATTR_ADDRESS_TYPE_ONEBYTE:
mDictBuffer.readUnsignedByte();
break;
case FormatSpec.FLAG_BIGRAM_ATTR_ADDRESS_TYPE_TWOBYTES:
mDictBuffer.readUnsignedShort();
break;
case FormatSpec.FLAG_BIGRAM_ATTR_ADDRESS_TYPE_THREEBYTES:
mDictBuffer.readUnsignedInt24();
break;
}
if ((bigramFlags & FormatSpec.FLAG_BIGRAM_SHORTCUT_ATTR_HAS_NEXT) == 0) break;
}
if (bigramCount >= FormatSpec.MAX_BIGRAMS_IN_A_PTNODE) {
throw new RuntimeException("Too many bigrams in a PtNode.");
}
}
}
} }

View File

@ -293,4 +293,14 @@ public class Ver4DictDecoder extends DictDecoder {
public boolean hasNextPtNodeArray() { public boolean hasNextPtNodeArray() {
return mDictBuffer.position() != FormatSpec.NO_FORWARD_LINK_ADDRESS; return mDictBuffer.position() != FormatSpec.NO_FORWARD_LINK_ADDRESS;
} }
@Override
public void skipPtNode(final FormatOptions formatOptions) {
final int flags = PtNodeReader.readPtNodeOptionFlags(mDictBuffer);
PtNodeReader.readParentAddress(mDictBuffer, formatOptions);
BinaryDictIOUtils.skipString(mDictBuffer,
(flags & FormatSpec.FLAG_HAS_MULTIPLE_CHARS) != 0);
if ((flags & FormatSpec.FLAG_IS_TERMINAL) != 0) PtNodeReader.readTerminalId(mDictBuffer);
PtNodeReader.readChildrenAddress(mDictBuffer, flags, formatOptions);
}
} }