*/
private void replace(OperationRequest operation, Document doc, ApiView view,
DocumentHitIterator hitIterator, DocumentModifyAction modifyAction)
throws InvalidRequestException {
int valueIndex = 0;
Range range = hitIterator.next();
while (range != null) {
int replaceAt = range.getStart();
int numInserted = insertInto(operation, doc, view, replaceAt, modifyAction, valueIndex);
// Remove the text after what was inserted (so it looks like it has been
// replaced).
view.delete(replaceAt + numInserted, range.getEnd() + numInserted);
// Shift the iterator from the start of the replacement with the amount of
// characters that have been added.
int numRemoved = Math.min(0, range.getStart() - range.getEnd());
hitIterator.shift(replaceAt, numInserted + numRemoved);
valueIndex++;
range = hitIterator.next();
}