Transform two Deletions --------
326086
function transformDeleteDelete (a, b, first) {
  // reduce to a normalized case
  if (a.pos > b.pos) {
    return transformDeleteDelete(b, a, !first)
  }
  if (a.pos === b.pos && a.str.length > b.str.length) {
    return transformDeleteDelete(b, a, !first)
  }
  // take out overlapping parts
  if (b.pos < a.pos + a.str.length) {
    var s = b.pos - a.pos
    var s1 = a.str.length - s
    var s2 = s + b.str.length
    a.str = a.str.slice(0, s) + a.str.slice(s2)
    b.str = b.str.slice(s1)
    b.pos -= s
  } else {
    b.pos -= a.str.length
  }
}
831247
def _transform_incoming(self, son, collection, skip=0):
        """"""
        skip = 0 if skip < 0 else skip
        if isinstance(son, dict):
            for (key, value) in son.items():
                if key.startswith('$'):
                    if isinstance(value, dict):
                        skip = 2
                    else:
                        pass  # allow mongo to complain
                if self.replace in key:
                    k = key if skip else self.transform_key(key)
                    son[k] = self._transform_incoming(
                        son.pop(key), collection, skip=skip - 1)
                elif isinstance(value, dict):  # recurse into sub-docs
                    son[key] = self._transform_incoming(value, collection,
                                                        skip=skip - 1)
                elif isinstance(value, list):
                    son[key] = [
                        self._transform_incoming(k, collection, skip=skip - 1)
                        for k in value
                    ]
            return son
        elif isinstance(son, list):
            return [self._transform_incoming(item, collection, skip=skip - 1)
                    for item in son]
        else:
            return son
156722
def concatenate_matches(a, b, text, name):
    """"""
    match = Match(a.start, b.end, text[a.start:b.end], name)
    for k, v in a.matches.items():
        match.matches[k] = v
    for k, v in b.matches.items():
        match.matches[k] = v
    if a.name is not None:
        aa = copy(a)
        del aa[MATCHES]
        match.matches[a.name] = aa
    if b.name is not None:
        bb = copy(b)
        del bb[MATCHES]
        match.matches[b.name] = bb
    return match
1322281
def combine_elem(ind1, ind2):
    """"""
    def inner(seq):
        shift = 2**16
        if seq[ind1] < 0:
            seq[ind1] += shift
        if seq[ind2] < 0:
            seq[ind2] += shift
        return (seq[ind1] << 16) | seq[ind2]
    return inner
1104942
function replaceComplete(text, re, fnc) {
    var doNext = true,
      reg = new RegExp(re); // safe (not literal)
    function fncWrap() {
      doNext = true;
      return fnc.apply(null, arguments);
    }
    // This is faster than using RegExp#exec() and RegExp#lastIndex,
    // because replace() isn't called more than twice in almost all cases.
    while (doNext) {
      doNext = false;
      text = text.replace(reg, fncWrap);
    }
    return text;
  }
785
function replaceInFile (filename, regex, replacement) {
    let contents = fs.readFileSync (filename, 'utf8')
    const parts = contents.split (regex)
    const newContents = parts[0] + replacement + parts[1]
    fs.truncateSync (filename)
    fs.writeFileSync (filename, newContents)
}
1010957
function appendTransform(defaults, transform) {
    defaults = angular.isArray(defaults) ? defaults : [defaults];
    return (transform) ? defaults.concat(transform) : defaults;
  }
746507
function replace(targetStr, searchStr, replaceStr, nPrev, nNext) {
  let result = targetStr;
  for (let i = 0; i < result.length; ++i) {
    if (result.substr(i, searchStr.length) === searchStr &&
      checkSubStr(result, i - nPrev.length, nPrev) === false &&
      checkSubStr(result, i + searchStr.length, nNext) === false) {
      result = result.slice(0, i) + replaceStr + result.slice(i + searchStr.length);
    }
  }
  return result;
}
13370
function mergeTitle( elem ) {
		merge( elem, function( old ) {
			var text = elem.children[ 0 ];

			utils.replaceElement( old.children[ 0 ], text );
			old.children[ 0 ] = text;
		} );
	}
1318135
function replaceWithMultiple(nodes) {
  this.resync();

  nodes = this._verifyNodeList(nodes);
  t.inheritLeadingComments(nodes[0], this.node);
  t.inheritTrailingComments(nodes[nodes.length - 1], this.node);
  this.node = this.container[this.key] = null;
  this.insertAfter(nodes);
  if (!this.node) this.dangerouslyRemove();
}
308407
def MultiMarkForDeletion(self, urns):
    """"""
    all_children_urns = self.RecursiveMultiListChildren(urns)

    urns.extend(collection.Flatten(itervalues(all_children_urns)))
    self._urns_for_deletion.update(urns)

    for obj in self.MultiOpen(urns):
      obj.OnDelete(deletion_pool=self)
951868
function(str1, str2, splitter){
    splitter = typeof splitter === 'string' ? splitter : '';

    var seq1 = str1.split(splitter),
        seq2 = str2.split(splitter),
        script = compare(seq1, seq2);

    script.forEach(function(change){
        if(change[2]){
            change[2] = change[2].join(splitter);
        }
    });

    return {
        splitter: splitter,
        diff: script
    };
}
16997
def _split_after_delimiter(self, item, indent_amt):
        """"""
        self._delete_whitespace()

        if self.fits_on_current_line(item.size):
            return

        last_space = None
        for item in reversed(self._lines):
            if (
                last_space and
                (not isinstance(item, Atom) or not item.is_colon)
            ):
                break
            else:
                last_space = None
            if isinstance(item, self._Space):
                last_space = item
            if isinstance(item, (self._LineBreak, self._Indent)):
                return

        if not last_space:
            return

        self.add_line_break_at(self._lines.index(last_space), indent_amt)
1175550
function transform(str, from, to) {
  let out = '';
  const escaped = '\\' + to;

  for (let i = 0; i < str.length; i++) {
    if (str[i] === to) {
      out += escaped;
    } else if (str[i] === from) {
      out += to;
    } else if (str[i] === '\\' && i + 1 < str.length && str[i + 1] === from) {
      out += from;
      i++;
    } else {
      out += str[i];
    }
  }
  return out;
}
181309
function replaceAt(items, item, index) {
  var copy = items.slice();
  copy.splice(index, 1, item);
  return copy;
}
1081927
def replace(self, child, replacement):
        """"""
        for i in range(len(self.chunks)):
            if self.chunks[i] == child:
                self.chunks[i] = replacement
614205
def transform_file(ELEMS, ofname, EPO, TREE, opt):
    "'"

    BED4_FRM = "%s\t%d\t%d\t%s\n"
    log.info("%s (%d) elements ..." % (opt.screen and "screening" or "transforming", ELEMS.shape[0]))
    with open(ofname, 'w') as out_fd:
        if opt.screen:
            for elem in ELEMS.flat:
                matching_blocks = [attrgetter("value")(_) for _ in TREE.find(elem['chrom'], elem['start'], elem['end'])]
                assert set( matching_blocks ) <= set( EPO.keys() )
                if matching_blocks:
                    out_fd.write(BED4_FRM % elem)
        else:
            for chrom in set( ELEMS['chrom'] ):
                transform_by_chrom(EPO,
                        ELEMS[ELEMS['chrom'] == chrom],
                        TREE, chrom, opt, out_fd)
    log.info("DONE!")