findLineNumberAndColumn() public static method

Computes the number of the line and column given an absolute position.
public static findLineNumberAndColumn ( array $lines, integer $pos ) : array
$lines array The starting position of each line.
$pos integer The absolute position
return array
Beispiel #1
0
 /**
  * Test for Linter::findLineNumberAndColumn
  *
  * @return void
  */
 public function testFindLineNumberAndColumn()
 {
     // Let the analyzed string be:
     //      ^abc$
     //      ^de$
     //      ^$
     //
     // Where `^` is the beginning of the line and `$` the end of the line.
     //
     // Positions of each character (by line):
     //      ( a, 0), ( b, 1), ( c, 2), (\n, 3),
     //      ( d, 4), ( e, 5), (\n, 6),
     //      (\n, 7).
     $this->assertEquals(array(1, 0), Linter::findLineNumberAndColumn(array(0, 4, 7), 4));
     $this->assertEquals(array(1, 1), Linter::findLineNumberAndColumn(array(0, 4, 7), 5));
     $this->assertEquals(array(1, 2), Linter::findLineNumberAndColumn(array(0, 4, 7), 6));
     $this->assertEquals(array(2, 0), Linter::findLineNumberAndColumn(array(0, 4, 7), 7));
 }