<commit_before>/* This file is part of the KDE project
 *  Copyright (C) 2003-2005 <NAME> <<EMAIL>>
 *  Copyright (C) 2001-2005 <NAME> <<EMAIL>>
 *  Copyright (C) 2002 <NAME> <<EMAIL>>
 *  Copyright (C) 2001 <NAME> <<EMAIL>>
 *  Copyright (C) 1999 <NAME> <<EMAIL>>
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public License
 *  along with this library; see the file COPYING.LIB.  If not, write to
 *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA 02110-1301, USA.
 */

#ifndef KDELIBS_KTEXTEDITOR_RANGE_H
#define KDELIBS_KTEXTEDITOR_RANGE_H

#include <ktexteditor/ktexteditor_export.h>
#include <ktexteditor/cursor.h>

#include <QDebug>

namespace KTextEditor
{

/**
 * \short An object representing a section of text, from one Cursor to another.
 *
 * A Range is a basic class which represents a range of text with two Cursors,
 * from a start() position to an end() position.
 *
 * For simplicity and convenience, ranges always maintain their start position to
 * be before or equal to their end position.  Attempting to set either the
 * start or end of the range beyond the respective end or start will result in
 * both values being set to the specified position.  In the constructor, the
 * start and end will be swapped if necessary.
 *
 * If you want additional functionality such as the ability to maintain position
 * in a document, see MovingRange.
 *
 * \sa MovingRange
 *
 * \author <NAME> \<<EMAIL>\>
 */
class KTEXTEDITOR_EXPORT Range
{
  public:
    /**
     * Default constructor. Creates a valid range from position (0, 0) to
     * position (0, 0).
     */
    Range();

    /**
     * Constructor which creates a range from \e start to \e end.
     * If start is after end, they will be swapped.
     *
     * \param start start position
     * \param end end position
     */
    Range(const Cursor& start, const Cursor& end);

    /**
     * Constructor which creates a single-line range from \p start,
     * extending \p width characters along the same line.
     *
     * \param start start position
     * \param width width of this range in columns along the same line
     */
    Range(const Cursor& start, int width);

    /**
     * Constructor which creates a range from \p start, to \p endLine, \p endColumn.
     *
     * \param start start position
     * \param endLine end line
     * \param endColumn end column
     */
    Range(const Cursor& start, int endLine, int endColumn);

    /**
     * Constructor which creates a range from \e startLine, \e startColumn to \e endLine, \e endColumn.
     *
     * \param startLine start line
     * \param startColumn start column
     * \param endLine end line
     * \param endColumn end column
     */
    Range(int startLine, int startColumn, int endLine, int endColumn);

    /**
     * Validity check.  In the base class, returns true unless the range starts before (0,0).
     */
    bool isValid() const;

    /**
     * Returns an invalid range.
     */
    static Range invalid();

    /**
     * \name Position
     *
     * The following functions provide access to, and manipulation of, the range's position.
     * \{
     */

    /**
     * Get the start position of this range. This will always be <= end().
     *
     * \returns const reference to the start position of this range.
     */
    const Cursor &start () const
    {
      return m_start;
    }

    /**
     * Get the end position of this range. This will always be >= start().
     *
     * \returns const reference to the end position of this range.
     */
    const Cursor &end () const
    {
      return m_end;
    }

    /**
     * Convenience function.  Set the start and end lines to \p line.
     *
     * \param line the line number to assign to start() and end()
     */
    void setBothLines(int line);

    /**
     * Convenience function.  Set the start and end columns to \p column.
     *
     * \param column the column number to assign to start() and end()
     */
    void setBothColumns(int column);

    /**
     * Set the start and end cursors to \e range.start() and \e range.end() respectively.
     *
     * \param range range to assign to this range
     */
    void setRange(const Range& range);

    /**
     * \overload
     * \n \n
     * Set the start and end cursors to \e start and \e end respectively.
     *
     * \note If \e start is after \e end, they will be reversed.
     *
     * \param start start cursor
     * \param end end cursor
     */
    void setRange(const Cursor& start, const Cursor& end);

    /**
     * Set the start cursor to \e start.
     *
     * \note If \e start is after current end, they will be reversed.
     *
     * \param start new start cursor
     */
    void setStart (const Cursor& start)
    {
      setRange (start, end());
    }

    /**
     * Set the end cursor to \e end.
     *
     * \note If \e end is in front of current start, they will be reversed.
     *
     * \param end new end cursor
     */
    void setEnd (const Cursor& end)
    {
      setRange (start(), end);
    }

    /**
     * Expand this range if necessary to contain \p range.
     *
     * \param range range which this range should contain
     *<commit_msg>try to fix problem introduced by inventing setStart/End, back to old semantics<commit_after>/* This file is part of the KDE project
 *  Copyright (C) 2003-2005 <NAME> <<EMAIL>>
 *  Copyright (C) 2001-2005 <NAME> <<EMAIL>>
 *  Copyright (C) 2002 <NAME> <<EMAIL>>
 *  Copyright (C) 2001 <NAME> <<EMAIL>>
 *  Copyright (C) 1999 <NAME> <<EMAIL>>
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public License
 *  along with this library; see the file COPYING.LIB.  If not, write to
 *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA 02110-1301, USA.
 */

#ifndef KDELIBS_KTEXTEDITOR_RANGE_H
#define KDELIBS_KTEXTEDITOR_RANGE_H

#include <ktexteditor/ktexteditor_export.h>
#include <ktexteditor/cursor.h>

#include <QDebug>

namespace KTextEditor
{

/**
 * \short An object representing a section of text, from one Cursor to another.
 *
 * A Range is a basic class which represents a range of text with two Cursors,
 * from a start() position to an end() position.
 *
 * For simplicity and convenience, ranges always maintain their start position to
 * be before or equal to their end position.  Attempting to set either the
 * start or end of the range beyond the respective end or start will result in
 * both values being set to the specified position.  In the constructor, the
 * start and end will be swapped if necessary.
 *
 * If you want additional functionality such as the ability to maintain position
 * in a document, see MovingRange.
 *
 * \sa MovingRange
 *
 * \author <NAME> \<<EMAIL>\>
 */
class KTEXTEDITOR_EXPORT Range
{
  public:
    /**
     * Default constructor. Creates a valid range from position (0, 0) to
     * position (0, 0).
     */
    Range();

    /**
     * Constructor which creates a range from \e start to \e end.
     * If start is after end, they will be swapped.
     *
     * \param start start position
     * \param end end position
     */
    Range(const Cursor& start, const Cursor& end);

    /**
     * Constructor which creates a single-line range from \p start,
     * extending \p width characters along the same line.
     *
     * \param start start position
     * \param width width of this range in columns along the same line
     */
    Range(const Cursor& start, int width);

    /**
     * Constructor which creates a range from \p start, to \p endLine, \p endColumn.
     *
     * \param start start position
     * \param endLine end line
     * \param endColumn end column
     */
    Range(const Cursor& start, int endLine, int endColumn);

    /**
     * Constructor which creates a range from \e startLine, \e startColumn to \e endLine, \e endColumn.
     *
     * \param startLine start line
     * \param startColumn start column
     * \param endLine end line
     * \param endColumn end column
     */
    Range(int startLine, int startColumn, int endLine, int endColumn);

    /**
     * Validity check.  In the base class, returns true unless the range starts before (0,0).
     */
    bool isValid() const;

    /**
     * Returns an invalid range.
     */
    static Range invalid();

    /**
     * \name Position
     *
     * The following functions provide access to, and manipulation of, the range's position.
     * \{
     */

    /**
     * Get the start position of this range. This will always be <= end().
     *
     * \returns const reference to the start position of this range.
     */
    const Cursor &start () const
    {
      return m_start;
    }

    /**
     * Get the end position of this range. This will always be >= start().
     *
     * \returns const reference to the end position of this range.
     */
    const Cursor &end () const
    {
      return m_end;
    }

    /**
     * Convenience function.  Set the start and end lines to \p line.
     *
     * \param line the line number to assign to start() and end()
     */
    void setBothLines(int line);

    /**
     * Convenience function.  Set the start and end columns to \p column.
     *
     * \param column the column number to assign to start() and end()
     */
    void setBothColumns(int column);

    /**
     * Set the start and end cursors to \e range.start() and \e range.end() respectively.
     *
     * \param range range to assign to this range
     */
    void setRange(const Range& range);

    /**
     * \overload
     * \n \n
     * Set the start and end cursors to \e start and \e end respectively.
     *
     * \note If \e start is after \e end, they will be reversed.
     *
     * \param start start cursor
     * \param end end cursor
     */
    void setRange(const Cursor& start, const Cursor& end);

    /**
     * Set the start cursor to \e start.
     *
     * \note If \e start is after current end, start and end will be set to new start value.
     *
     * \param start new start cursor
     */
    void setStart (const Cursor& start)
    {
      if (start > end())
        setRange (start, start);
      else
        setRange (start, end());
    }

    /**
     * Set the end cursor to \e end.
     *
     * \note If \e end is in front of current start, start and end will be set to new end value.
     *
     * \param end new end cursor
     */
    void setEnd (const Cursor& end)
    {
      if (end < start())
        setRange (end, end);
      else
        setRange (start(), end);
    }

    /**
     * Expand this range if necessary to contain \p range.
     *
     * \param range range which this range should contain
     *
{'fraction_non_alphanumeric': 0.08969676378153402, 'fraction_numerical': 0.007814490783997282, 'mean_word_length': 2.3382478026651543, 'pattern_counts': {'":': 0, '<': 48, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5922774', 'n_tokens_mistral': 3447, 'n_tokens_neox': 3314, 'n_words': 1517}