Ejemplo n.º 1
0
 /**
  * Advance the position in the post-translation file. e.g. (1, 3) ->
  * advanceByTextSize(blah\nblah\nblah) -> (3, 4) NB: slower than specifying directly using
  * advanceInLine or advanceToNewLine
  */
 public void advanceByTextSize(String text) {
   TextPosition eofPos = LengthScanner.getLength(text);
   if (eofPos.getLine() == 1) {
     advanceInLine(eofPos.getColumn() - 1);
   } else {
     advanceToNewLine(eofPos.getLine() - 1, eofPos.getColumn());
   }
 }
Ejemplo n.º 2
0
 /** Record a change to the cumulative offset, beginning at the current position. */
 public void recordOffsetChange(String text, int startPos, boolean insert) {
   TextPosition eofPos = LengthScanner.getLength(text);
   int lineOffsetChange = -1;
   int colOffsetChange = -1;
   if (eofPos.getLine() == 1) {
     lineOffsetChange = 0;
     colOffsetChange = eofPos.getColumn() - 1;
   } else {
     lineOffsetChange = eofPos.getLine() - 1;
     colOffsetChange = eofPos.getColumn() - startPos;
   }
   if (insert) {
     recordOffsetChange(-1 * lineOffsetChange, -1 * colOffsetChange);
   } else {
     recordOffsetChange(lineOffsetChange, colOffsetChange);
   }
 }
Ejemplo n.º 3
0
 TextPosition reverseOffset(TextPosition original) {
   return new TextPosition(original.getLine() - lineOffset, original.getColumn() - colOffset);
 }
Ejemplo n.º 4
0
 /**
  * Advance the position in the post-translation file. e.g. (1, 3) -> advanceInLine(2) -> (1, 5)
  */
 public void advanceInLine(int numCols) {
   if (numCols < 0) {
     throw new IllegalArgumentException("Attempted to move backwards in line: " + numCols);
   }
   currPos = new TextPosition(currPos.getLine(), currPos.getColumn() + numCols);
 }
Ejemplo n.º 5
0
 TextPosition forwardOffset(TextPosition original) {
   return new TextPosition(original.getLine() + lineOffset, original.getColumn() + colOffset);
 }