Skip to content

Commit

Permalink
GH-75: added a note.
Browse files Browse the repository at this point in the history
  • Loading branch information
dweiss committed Feb 18, 2016
1 parent 1cb9b2d commit 270a95c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,9 @@ private void findRepl(final int depth, final int node, final byte[] prevBytes, f
byteBuffer.flip();
decoder.reset();
// FIXME: this isn't correct -- no checks for overflows, no decoder flush. I don't think this should be in here
// too, the decoder should run once on the input charsequence, then the decoded byte array should be used for
// suggestions. Reallocating buffers and decoding over and over doesn't make much sense.
// too, the decoder should run once on accumulated temporary byte buffer (current path) only when there's
// a potential that this buffer can become a replacement candidate (isEndOfCandidate). Because we assume candidates
// are valid input strings (this is verified when building the dictionary), it's save a lot of conversions.
final CoderResult c = decoder.decode(byteBuffer, charBuffer, true);
if (c.isMalformed()) { // assume that only valid
// encodings are there
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ public static String toString(ByteBuffer buffer, Charset charset) {
return new String(buf, charset);
}

public static String toString(CharBuffer buffer) {
buffer = buffer.slice();
char [] buf = new char [buffer.remaining()];
buffer.get(buf);
return new String(buf);
}

/**
* @param buffer The buffer to read from.
* @return Returns the remaining bytes from the buffer copied to an array.
Expand Down

0 comments on commit 270a95c

Please sign in to comment.