line = $line; $this->column = $column; } /** * Count the number of lines and columns in the specified string, and * create an IndexMapOffset representing the corresponding size. * * @param string $text * @return self */ public static function newFromText( string $text ) { $lines = substr_count( $text, "\n" ); $lastBreakPos = strrpos( $text, "\n" ); if ( $lastBreakPos === false ) { $columns = Utils::getJsLength( $text ); } else { $columns = Utils::getJsLength( substr( $text, $lastBreakPos + 1 ) ); } return new self( $lines, $columns ); } /** * Restore an IndexMapOffset which was serialized with toArray(). * * @param array $data * @return self */ public static function newFromArray( array $data ) { return new self( $data[0], $data[1] ); } /** * Convert the object to plain data. * * @return array */ public function toArray(): array { return [ $this->line, $this->column ]; } /** * Advance the offset, assuming a file of the specified size was added * to the combined file. * * @param IndexMapOffset $nextSize * @return void */ public function add( self $nextSize ) { if ( $nextSize->line > 0 ) { $this->line += $nextSize->line; $this->column = $nextSize->column; } else { $this->column += $nextSize->column; } } }