process replacements in the string of code to actually update the markup

@param {string} code         the code to process replacements in
@param {Function} onComplete   what to do when we are done processing
@returns void
178809
function _processReplacements(code, onComplete) {

        /**
         * processes a single replacement
         *
         * @param {string} code
         * @param {Array} positions
         * @param {number} i
         * @param {Function} onComplete
         * @returns void
         */
        function _processReplacement(code, positions, i, onComplete) {
            if (i < positions.length) {
                ++replacement_counter;
                var pos = positions[i],
                    replacement = replacements[CURRENT_LEVEL][pos];
                code = _replaceAtPosition(pos, replacement['replace'], replacement['with'], code);

                // process next function
                var next = function() {
                    _processReplacement(code, positions, ++i, onComplete);
                };

                // use a timeout every 250 to not freeze up the UI
                return replacement_counter % 250 > 0 ? next() : setTimeout(next, 0);
            }

            onComplete(code);
        }

        var string_positions = keys(replacements[CURRENT_LEVEL]);
        _processReplacement(code, string_positions, 0, onComplete);
    }
336185
def set_code(self, code):
        

        for i, (_, style_code) in enumerate(self.styles):
            if code == style_code:
                self.SetSelection(i)
359486
def replace(code, pattern, goal):
    """"""
    finder = similarfinder.RawSimilarFinder(code)
    matches = list(finder.get_matches(pattern))
    ast = patchedast.get_patched_ast(code)
    lines = codeanalyze.SourceLinesAdapter(code)
    template = similarfinder.CodeTemplate(goal)
    computer = _ChangeComputer(code, ast, lines, template, matches)
    result = computer.get_changed()
    if result is None:
        return code
    return result
661082
function parse(code) {
  code = code + '\n';
  var lines = code.split(/\r\n|\r|\n/);

  var header;
  var sections = [];

  var comments = [];
  var inComment = false, section;
  lines.forEach(function(line) {
    // comment block
    if (/^\/\*/.test(line)) {
      inComment = true;
    }
    if (/\*\/$/.test(line)) {
      inComment = false;
      line = line.replace(/\*\/$/, '');
      comments.push(cleanLine(line));
      return;
    }

    if (/^\/\//.test(line)) {
      comments.push(cleanLine(line));
      return;
    }

    if (inComment) {
      comments.push(cleanLine(line));
      return;
    }

    // it is not comment now
    if (comments.length) {
      section = parseSection(comments);
      if (section) {
        sections.push(section);
      } else if (!header && !sections.length) {
        header = comments.join('\n');
      }
      // reset storage
      comments = [];
    }
  });
  return {header: header, sections: sections};
}
454350
protected void replaceText(CharSequence text) {
        switch (mAutoCompleteMode){
            case AUTOCOMPLETE_MODE_SINGLE:
                ((InternalAutoCompleteTextView)mInputView).superReplaceText(text);
                break;
            case AUTOCOMPLETE_MODE_MULTI:
                ((InternalMultiAutoCompleteTextView)mInputView).superReplaceText(text);
                break;
        }
    }
1354270
function _highlightCodeBlock(code_blocks, i, onComplete) {
        if (i < code_blocks.length) {
            var block = code_blocks[i],
                language = _getLanguageForBlock(block);

            if (!_hasClass(block, 'rainbow') && language) {
                language = language.toLowerCase();

                _addClass(block, 'rainbow');

                return _highlightBlockForLanguage(block.innerHTML, language, function(code) {
                    block.innerHTML = code;

                    // reset the replacement arrays
                    replacements = {};
                    replacement_positions = {};

                    // if you have a listener attached tell it that this block is now highlighted
                    if (onHighlight) {
                        onHighlight(block, language);
                    }

                    // process the next block
                    setTimeout(function() {
                        _highlightCodeBlock(code_blocks, ++i, onComplete);
                    }, 0);
                });
            }
            return _highlightCodeBlock(code_blocks, ++i, onComplete);
        }

        if (onComplete) {
            onComplete();
        }
    }
533614
function (type, code) {
      $sgCodeTitles.removeClass('sg-code-title-active');

      switch (type) {
        case 'e':
          $sgCodeTitleHtml.addClass('sg-code-title-active');

          break;

        case 'm':
          $sgCodeTitleMustache.addClass('sg-code-title-active');

          break;
      }

      $sgCodeFill.removeClass().addClass('language-markup');
      $sgCodeFill.html(code);
      window.Prism.highlightElement($sgCodeFill[0]);

      if (codeViewer.copyOnInit) {
        codeViewer.selectCode();
        codeViewer.copyOnInit = false;
      }
    }
814246
function fixChromeAutocomplete() {
      const global = formlyConfig.extras.removeChromeAutoComplete === true
      const offInstance = scope.options && scope.options.removeChromeAutoComplete === false
      const onInstance = scope.options && scope.options.removeChromeAutoComplete === true
      if ((global && !offInstance) || onInstance) {
        const input = document.createElement('input')
        input.setAttribute('autocomplete', 'address-level4')
        input.setAttribute('hidden', 'true')
        el[0].appendChild(input)
      }

    }
276630
function applyToShareJS(cm, change) {

      // CodeMirror changes give a text replacement.

      var startPos = 0;  // Get character position from # of chars in each line.
      var i = 0;         // i goes through all lines.

      while (i < change.from.line) {
        startPos += cm.lineInfo(i).text.length + 1;   // Add 1 for '\n'
        i++;
      }

      startPos += change.from.ch;

      // sharejs json path to the location of the change
      var textPath = ['text', startPos];

      // array of operations that will be submitted
      var ops = [];

      // object to keep track of lines that were deleted
      var deletedLines = {};

      // get an updated document
      var doc = ctx.get();

      if (change.to.line == change.from.line && change.to.ch == change.from.ch) {
        // nothing was removed.
      } else {

        // change in lines (deleted lines)
        if(change.to.line !== change.from.line){
          for (i = change.to.line; i > change.from.line; i--) {

            if(doc.lines[i] !== undefined){
              ops.push({p:['lines', i], ld: doc.lines[i]});
              deletedLines[i] = true;
            }
          }
        }

        // change in text (deletion)
        ops.push({p:textPath, sd: change.removed.join('\n')});
      }

      if (change.text) {

        // change in text (insertion)
        ops.push({p:textPath, si: change.text.join('\n')});

        // new lines and pasting
        if ((change.from.line === change.to.line && change.text.length > 1) || change.origin === 'paste') {

          // figure out if there should also be an included line insertion
          // // if the change was just to add a new line character, do a replace
          // // on that line and then do an insert for the next
          if (change.text.join('\n') === '\n') {
            ops.push({p:['lines', change.from.line+1], li: {
              client: timestamps.client,
              timestamp: new Date ()
            }});
          } else {
            /*
             *  For the following values of change.origin, we know what we want to happen.
             *  - null - this is a programmatic insertion
             *  - paste, redo, undo - cm detected the indicated behavior
             *
             *  For others, they'll have to fall through and be handled accordingly.
             *  Not having this conditional here leads to things breaking...
             */
            if (change.origin && change.origin !== 'paste' && change.origin !== 'redo' && change.origin !== 'undo') {
              console.warn('not sure what to do in this case', change);
            } else {

              if (newTimestamp !== doc.lines[change.from.line].timestamp ||
                  timestamps.client !== doc.lines[change.from.line].client) {

                // replace (delete and insert) the line with updated values
                ops.push({p:['lines', change.from.line], ld: doc.lines[change.from.line], li: {
                  client: timestamps.client,
                  timestamp: new Date ()
                }});
              }

              for (i = 1; i < change.text.length; i++) {
                ops.push({p:['lines', change.from.line+1], li: {
                  client: timestamps.client,
                  timestamp: new Date ()
                }});
              }
            }
          }
        } else {
          // change in lines (replace + insertion)
          for (var changeTextIndex = 0; changeTextIndex < change.text.length; changeTextIndex++) {
            var lineChange = change.text[changeTextIndex];
            var lineIndex = change.from.line + changeTextIndex;

            if (doc.lines[lineIndex]) {

              // if this line was just deleted, we don't want to submit any
              // updates for it ... we have already updated the text appropriately,
              // updating this now will update the wrong line.

              var newTimestamp = new Date ();

              // the line metadata has changed (new author or new date)
              if (newTimestamp !== doc.lines[lineIndex].timestamp ||
                  timestamps.client !== doc.lines[lineIndex].client) {

                // replace (delete and insert) the line with updated values

                ops.push({p:['lines', lineIndex], ld: doc.lines[lineIndex], li: {
                  client: timestamps.client,
                  timestamp: newTimestamp
                }});
              }
            } else {
              // the line doesn't currently exist, so insert a new line
              ops.push({p:['lines', lineIndex], li: {
                client: timestamps.client,
                timestamp: new Date ()
              }});
            }
          }
        }
      }

      // submit the complete list of changes
      ctx.submitOp(ops);

      // call the function again on the next change, if there is one
      if (change.next) {
        applyToShareJS(cm, change.next);
      }
    }
673302
function providePlugins(code) {
  var chunks = [];
  if (typeof code === 'string') {
    code = code.split('\n');
  }
  chunks.push("function (" + Object.keys(plugins).join(', ') + ") {");
  chunks.push("  return " + code[0]);

  code.forEach(function (line, index) {
    if (index === 0) return; // omit the first line
    chunks.push("  " + line);
  });
  chunks.push("}");
  return chunks;
}
1038745
function(code)
        {
            if (code === null)
                code = '';

            this.code = code;

            var div = this.create('div');

            // create main HTML
            div.innerHTML = this.getHtml(code);

            // set up click handlers
            if (this.getParam('toolbar'))
                attachEvent(findElement(div, '.toolbar'), 'click', sh.toolbar.handler);

            if (this.getParam('quick-code'))
                attachEvent(findElement(div, '.code'), 'dblclick', quickCodeHandler);

            return div;
        }
1356227
function _initComplete(err, result) {
          if( !isResolved ) {
            isResolved = true;
            if( err ) { def.reject(err); }
            else { def.resolve(result); }
          }
        }
1073587
function onComplete(options, callback) {
        return function (req) {
            var resp;
            if (ctype = req.getResponseHeader('Content-Type')) {
                ctype = ctype.split(';')[0];
            }
            if (ctype === 'application/json' || ctype === 'text/json') {
                try {
                    resp = $.parseJSON(req.responseText)
                }
                catch (e) {
                    return callback(e, null, req);
                }
            }
            else {
                var ct = req.getResponseHeader("content-type") || "";
                var xml = ct.indexOf("xml") >= 0;
                resp = xml ? req.responseXML : req.responseText;
            }
            if (req.status == 200 || req.status == 201 || req.status == 202) {
                callback(null, resp, req);
            }
            else if (resp && (resp.error || resp.reason)) {
                var err = new Error(resp.reason || resp.error);
                err.error = resp.error;
                err.reason = resp.reason;
                err.code = resp.code;
                err.status = req.status;
                callback(err, null, req);
            }
            else {
                // TODO: map status code to meaningful error message
                var msg = req.statusText;
                if (!msg || msg === 'error') {
                    msg = 'Returned status code: ' + req.status;
                }
                var err2 = new Error(msg);
                err2.status = req.status;
                callback(err2, null, req);
            }
        };
    }
210946
public static String applyCodeReplacements(Iterable<CodeReplacement> replacements, String code) {
    List<CodeReplacement> sortedReplacements = ORDER_CODE_REPLACEMENTS.sortedCopy(replacements);
    validateNoOverlaps(sortedReplacements);

    StringBuilder sb = new StringBuilder();
    int lastIndex = 0;
    for (CodeReplacement replacement : sortedReplacements) {
      sb.append(code, lastIndex, replacement.getStartPosition());
      sb.append(replacement.getNewContent());
      lastIndex = replacement.getEndPosition();
    }
    if (lastIndex <= code.length()) {
      sb.append(code, lastIndex, code.length());
    }
    return sb.toString();
  }
855664
function highlight (code, lang) {
  if (!lang) {
    return code
  }

  var isDiff = DIFF_REGEXP.test(lang)

  // Remove the diff suffix. E.g. "javascript.diff".
  lang = lang.replace(DIFF_REGEXP, '')

  // Ignore unknown languages.
  if (!isDiff && !supported(lang)) {
    return code
  }

  return isDiff ? diff(code, lang) : hljs.highlight(lang, code).value
}
866174
function (code, location) {

			if (arguments.length === 1) {
				location = code;
				code = 302;
			}

			render(code, EMPTY_STRING, location);
		}
941098
function onComplete (err) {
    if (err) {
      console.log('interpolation encountered an error: ', err)
      return callback(err)
    }
    // set is complete and create a queue drain function
    // however, a feed may not have any interpolated times, so
    // `isComplete` is set in case nothing is pushed to the queue
    isComplete = true
    updateQueue.drain = () => {
      console.log('interpolation completed successfully')
      callback(err)
    }
  }