/** * For given content the list with shrink position information is searched and on the * corresponding positions the correct repositioning information is calculated and generated. */ public void addRepositioningInfo(String content, int pos, int extractedPos) { int contentLength = content.length(); // wrong way (without correction and analysing) // reposInfo.addPositionInfo(pos, contentLength, extractedPos, contentLength); RepositioningInfo.PositionInfo pi = null; long startPos = pos; long correction = 0; long substituteStart; long remainingLen; long offsetInExtracted; for (int i = 0; i < ampCodingInfo.size(); ++i) { pi = ampCodingInfo.get(i); substituteStart = pi.getOriginalPosition(); if (substituteStart >= startPos) { if (substituteStart > pos + contentLength + correction) { break; // outside the current text } // if // should create two repositioning information records remainingLen = substituteStart - (startPos + correction); offsetInExtracted = startPos - pos; if (remainingLen > 0) { reposInfo.addPositionInfo( startPos + correction, remainingLen, extractedPos + offsetInExtracted, remainingLen); } // if // record for shrank text reposInfo.addPositionInfo( substituteStart, pi.getOriginalLength(), extractedPos + offsetInExtracted + remainingLen, pi.getCurrentLength()); startPos = startPos + remainingLen + pi.getCurrentLength(); correction += pi.getOriginalLength() - pi.getCurrentLength(); } // if } // for // there is some text remaining for repositioning offsetInExtracted = startPos - pos; remainingLen = contentLength - offsetInExtracted; if (remainingLen > 0) { reposInfo.addPositionInfo( startPos + correction, remainingLen, extractedPos + offsetInExtracted, remainingLen); } // if } // addRepositioningInfo