boolean isIndexInTable(int startBytePos, int endBytePos) { for (TextPiece tp : _textPiecesFCOrder) { int pieceStart = tp.getPieceDescriptor().getFilePosition(); if (startBytePos >= pieceStart + tp.bytesLength()) { continue; } int left = Math.max(startBytePos, pieceStart); int right = Math.min(endBytePos, pieceStart + tp.bytesLength()); if (left >= right) return false; return true; } return false; }
public int lookIndexBackward(final int startBytePos) { int bytePos = startBytePos; int lastEnd = 0; for (TextPiece tp : _textPiecesFCOrder) { int pieceStart = tp.getPieceDescriptor().getFilePosition(); if (bytePos > pieceStart + tp.bytesLength()) { lastEnd = pieceStart + tp.bytesLength(); continue; } if (pieceStart > bytePos) { bytePos = lastEnd; } break; } return bytePos; }
boolean isIndexInTable( int startBytePos, int endBytePos ) { for ( TextPiece tp : _textPiecesFCOrder ) { int pieceStart = tp.getPieceDescriptor().getFilePosition(); if ( startBytePos >= pieceStart + tp.bytesLength() ) { continue; } int left = Math.max( startBytePos, pieceStart ); int right = Math.min( endBytePos, pieceStart + tp.bytesLength() ); if ( left >= right ) return false; return true; } return false; }
public int lookIndexBackward( final int startBytePos ) { int bytePos = startBytePos; int lastEnd = 0; for ( TextPiece tp : _textPiecesFCOrder ) { int pieceStart = tp.getPieceDescriptor().getFilePosition(); if ( bytePos > pieceStart + tp.bytesLength() ) { lastEnd = pieceStart + tp.bytesLength(); continue; } if ( pieceStart > bytePos ) { bytePos = lastEnd; } break; } return bytePos; }
public boolean isIndexInTable(int bytePos) { for (TextPiece tp : _textPiecesFCOrder) { int pieceStart = tp.getPieceDescriptor().getFilePosition(); if (bytePos > pieceStart + tp.bytesLength()) { continue; } if (pieceStart > bytePos) { return false; } return true; } return false; }
public boolean isIndexInTable( int bytePos ) { for ( TextPiece tp : _textPiecesFCOrder ) { int pieceStart = tp.getPieceDescriptor().getFilePosition(); if ( bytePos > pieceStart + tp.bytesLength() ) { continue; } if ( pieceStart > bytePos ) { return false; } return true; } return false; }
@Override public int[][] getCharIndexRanges(int startBytePosInclusive, int endBytePosExclusive) { List<int[]> result = new LinkedList<>(); for (TextPiece textPiece : _textPiecesFCOrder) { final int tpStart = textPiece.getPieceDescriptor() .getFilePosition(); final int tpEnd = textPiece.getPieceDescriptor().getFilePosition() + textPiece.bytesLength(); if (startBytePosInclusive > tpEnd) continue; if (endBytePosExclusive <= tpStart) break; final int rangeStartBytes = Math.max(tpStart, startBytePosInclusive); final int rangeEndBytes = Math.min(tpEnd, endBytePosExclusive); final int rangeLengthBytes = rangeEndBytes - rangeStartBytes; if (rangeStartBytes > rangeEndBytes) continue; final int encodingMultiplier = getEncodingMultiplier(textPiece); final int rangeStartCp = textPiece.getStart() + (rangeStartBytes - tpStart) / encodingMultiplier; final int rangeEndCp = rangeStartCp + rangeLengthBytes / encodingMultiplier; result.add(new int[]{rangeStartCp, rangeEndCp}); } return result.toArray(new int[result.size()][]); }
public int[][] getCharIndexRanges( int startBytePosInclusive, int endBytePosExclusive ) { List<int[]> result = new LinkedList<int[]>(); for ( TextPiece textPiece : _textPiecesFCOrder ) { final int tpStart = textPiece.getPieceDescriptor() .getFilePosition(); final int tpEnd = textPiece.getPieceDescriptor().getFilePosition() + textPiece.bytesLength(); if ( startBytePosInclusive > tpEnd ) continue; if ( endBytePosExclusive < tpStart ) break; final int rangeStartBytes = Math.max( tpStart, startBytePosInclusive ); final int rangeEndBytes = Math.min( tpEnd, endBytePosExclusive ); final int rangeLengthBytes = rangeEndBytes - rangeStartBytes; if ( rangeStartBytes > rangeEndBytes ) continue; final int encodingMultiplier = textPiece.isUnicode() ? 2 : 1; final int rangeStartCp = textPiece.getStart() + ( rangeStartBytes - tpStart ) / encodingMultiplier; final int rangeEndCp = rangeStartCp + rangeLengthBytes / encodingMultiplier; result.add( new int[] { rangeStartCp, rangeEndCp } ); } return result.toArray( new int[result.size()][] ); }
@Deprecated public int getCharIndex(int startBytePos, int startCP) { int charCount = 0; int bytePos = lookIndexForward(startBytePos); for (TextPiece tp : _textPieces) { int pieceStart = tp.getPieceDescriptor().getFilePosition(); int bytesLength = tp.bytesLength(); int pieceEnd = pieceStart + bytesLength; int toAdd; if (bytePos < pieceStart || bytePos > pieceEnd) { toAdd = bytesLength; } else if (bytePos > pieceStart && bytePos < pieceEnd) { toAdd = (bytePos - pieceStart); } else { toAdd = bytesLength - (pieceEnd - bytePos); } if (tp.isUnicode()) { charCount += toAdd / 2; } else { charCount += toAdd; } if (bytePos >= pieceStart && bytePos <= pieceEnd && charCount >= startCP) { break; } } return charCount; }
int bytesLength = tp.bytesLength(); int pieceEnd = pieceStart + bytesLength;