replaceFunctionCall static method

String replaceFunctionCall(
  1. String source,
  2. String functionName,
  3. String replacement
)

Replace all calls to functionName in source with replacement.

source内のfunctionNameの呼び出しをすべてreplacementに置き換えます。

Implementation

static String replaceFunctionCall(
  String source,
  String functionName,
  String replacement,
) {
  var updated = source;
  var searchStart = 0;
  var replaced = false;
  while (true) {
    final range = _findFunctionCall(updated, functionName, searchStart);
    if (range == null) {
      break;
    }
    final next = replaced ? "" : replacement;
    updated = updated.replaceRange(range.start, range.end, next);
    searchStart = range.start + next.length;
    replaced = true;
  }
  return updated;
}