<commit_before>// This file is part of the Kate project within KDE.
// (C) 2009 <NAME> <dhaumann kde org>
// License: LGPL v2 or v3

/**
 * Prototype Range.
 */
function Range()
{
  if (arguments.length == 0) {
    return new Range(0, 0, 0, 0);
  } else if (arguments.length == 1 && typeof arguments[0] == "object") {
    // assume: range = new Range(otherRange);
    return arguments[0].clone();
  } else if (arguments.length == 2 && typeof arguments[0] == "object"
                                   && typeof arguments[1] == "object") {
    // assume: range = new Range(startCursor, endCursor);
    this.start = arguments[0].clone();
    this.end = arguments[1].clone();
  } else if (arguments.length == 4 && typeof arguments[0] == "number"
                                   && typeof arguments[1] == "number"
                                   && typeof arguments[2] == "number"
                                   && typeof arguments[3] == "number") {
    this.start = new Cursor(arguments[0], arguments[1]);
    this.end = new Cursor(arguments[2], arguments[3]);
  } else {
    throw "Wrong usage of Range constructor";
  }

  this.clone = function() {
    return new Range(this.start, this.end);
  };

  this.isValid = function() {
    return this.start.isValid() && this.end.isValid();
  };

  this.invalid = function() {
    return new Range(-1, -1, -1, -1);
  };

  this.contains = function(cursorOrRange) {
    if (cursorOrRange.start && cursorOrRange.end) {
      // assume a range
      return (cursorOrRange.start.compareTo(this.start) >= 0 &&
              cursorOrRange.end.compareTo(this.end) <= 0);
    } else {
      // assume a cursor
      return (cursorOrRange.compareTo(this.start) >= 0 &&
              cursorOrRange.compareTo(this.end) < 0);
    }
  };

  this.containsColumn = function(column) {
    return (column >= this.start.column) && (column < this.end.column);
  };

  this.containsLine = function(line) {
    return (line > this.start.line || (line == this.start.line && this.start.column == 0)) && line < this.end.line;
  };

  this.overlaps = function(range) {
    if (range.start.compareTo(this.start) <= 0) {
      return range.end.compareTo(this.start) > 0;
    } else if (range.end.compareTo(this.end) >= 0) {
      return range.start.compareTo(this.end) < 0;
    } else {
      return this.contains(range);
    }
  };

  this.overlapsLine = function(line) {
    return (line >= this.start.line && line <= this.end.line);
  }

  this.overlapsColumn = function(column) {
    return column >= this.start.column && column <= this.end.column;
  }

  this.equals = function(other) {
    return (this.start.equals(other.start) && this.end.equals(other.end));
  };

  this.toString = function() {
    return "Range(" + this.start + ", " + this.end + ")";
  };
}
<commit_msg>new js api: bool Range.onSingleLine()<commit_after>// This file is part of the Kate project within KDE.
// (C) 2009 <NAME> <dhaumann kde org>
// License: LGPL v2 or v3

/**
 * Prototype Range.
 */
function Range()
{
  if (arguments.length == 0) {
    return new Range(0, 0, 0, 0);
  } else if (arguments.length == 1 && typeof arguments[0] == "object") {
    // assume: range = new Range(otherRange);
    return arguments[0].clone();
  } else if (arguments.length == 2 && typeof arguments[0] == "object"
                                   && typeof arguments[1] == "object") {
    // assume: range = new Range(startCursor, endCursor);
    this.start = arguments[0].clone();
    this.end = arguments[1].clone();
  } else if (arguments.length == 4 && typeof arguments[0] == "number"
                                   && typeof arguments[1] == "number"
                                   && typeof arguments[2] == "number"
                                   && typeof arguments[3] == "number") {
    this.start = new Cursor(arguments[0], arguments[1]);
    this.end = new Cursor(arguments[2], arguments[3]);
  } else {
    throw "Wrong usage of Range constructor";
  }

  this.clone = function() {
    return new Range(this.start, this.end);
  };

  this.isValid = function() {
    return this.start.isValid() && this.end.isValid();
  };

  this.invalid = function() {
    return new Range(-1, -1, -1, -1);
  };

  this.contains = function(cursorOrRange) {
    if (cursorOrRange.start && cursorOrRange.end) {
      // assume a range
      return (cursorOrRange.start.compareTo(this.start) >= 0 &&
              cursorOrRange.end.compareTo(this.end) <= 0);
    } else {
      // assume a cursor
      return (cursorOrRange.compareTo(this.start) >= 0 &&
              cursorOrRange.compareTo(this.end) < 0);
    }
  };

  this.containsColumn = function(column) {
    return (column >= this.start.column) && (column < this.end.column);
  };

  this.containsLine = function(line) {
    return (line > this.start.line || (line == this.start.line && this.start.column == 0)) && line < this.end.line;
  };

  this.overlaps = function(range) {
    if (range.start.compareTo(this.start) <= 0) {
      return range.end.compareTo(this.start) > 0;
    } else if (range.end.compareTo(this.end) >= 0) {
      return range.start.compareTo(this.end) < 0;
    } else {
      return this.contains(range);
    }
  };

  this.overlapsLine = function(line) {
    return (line >= this.start.line && line <= this.end.line);
  }

  this.overlapsColumn = function(column) {
    return column >= this.start.column && column <= this.end.column;
  }

  this.onSingleLine = function() {
    return (this.start.line == this.start.line);
  }

  this.equals = function(other) {
    return (this.start.equals(other.start) && this.end.equals(other.end));
  };

  this.toString = function() {
    return "Range(" + this.start + ", " + this.end + ")";
  };
}

{'fraction_non_alphanumeric': 0.16640474943251266, 'fraction_numerical': 0.0143181421337524, 'mean_word_length': 2.4863055386488133, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6512208', 'n_tokens_mistral': 1870, 'n_tokens_neox': 1798, 'n_words': 409}