(function() {
  var MULTI_LINE_REGEX_REGEX, Point;

  Point = require('./point');

  MULTI_LINE_REGEX_REGEX = /\\s|\\r|\\n|\r|\n|^\[\^|[^\\]\[\^/;

  module.exports = {
    spliceArray: function(array, start, removedCount, insertedItems) {
      var i, insertedCount, j, k, l, len, lengthDelta, newLength, oldLength, ref, ref1, ref2, ref3, value;
      if (insertedItems == null) {
        insertedItems = [];
      }
      oldLength = array.length;
      insertedCount = insertedItems.length;
      removedCount = Math.min(removedCount, oldLength - start);
      lengthDelta = insertedCount - removedCount;
      newLength = oldLength + lengthDelta;
      if (lengthDelta > 0) {
        array.length = newLength;
        for (i = j = ref = newLength - 1, ref1 = start + insertedCount; j >= ref1; i = j += -1) {
          array[i] = array[i - lengthDelta];
        }
      } else {
        for (i = k = ref2 = start + insertedCount, ref3 = newLength; k < ref3; i = k += 1) {
          array[i] = array[i - lengthDelta];
        }
        array.length = newLength;
      }
      for (i = l = 0, len = insertedItems.length; l < len; i = l += 1) {
        value = insertedItems[i];
        array[start + i] = insertedItems[i];
      }
    },
    newlineRegex: /\r\n|\n|\r/g,
    normalizePatchChanges: function(changes) {
      return changes.map(function(change) {
        return {
          start: Point.fromObject(change.newStart),
          oldExtent: Point.fromObject(change.oldExtent),
          newExtent: Point.fromObject(change.newExtent),
          newText: change.newText
        };
      });
    },
    regexIsSingleLine: function(regex) {
      return !MULTI_LINE_REGEX_REGEX.test(regex.source);
    }
  };

}).call(this);
