def line_number_for_offset(self, offset):
        """The line number of a position relative to the current position.
        
        @param offset: Offset to the current position for which to determine the line position. It may be negative.

        @return: The line number for the specified position.

        @raise IndexError: If the offset places the position outside of the valid range for the underlying byte
            range."""
        line_num = 1
        target_pos = self.__pos + offset
        x = self.__start_pos

        self.__check_index(target_pos)
 
        while x < target_pos:
            b = self.__buffer[x]
            x += 1
            if b == '\n':
                line_num += 1
            elif b == '\r':
                line_num += 1
                # If this CR is the first half of a CRLF sequence, 
                # skip the LF; otherwise we'd double-count CRLF line breaks.
                if x < target_pos and self.__buffer[x] == '\n':
                    x += 1
        return line_num
dataset/ETHPy150Open scalyr/scalyr-agent-2/scalyr_agent/json_lib/parser.py/ByteScanner.line_number_for_offset/original