computeInsertedText static method

String computeInsertedText(
  1. String oldText,
  2. String newText
)

Implementation

static String computeInsertedText(String oldText, String newText) {
  int commonPrefix = 0;
  while (commonPrefix < oldText.length &&
      commonPrefix < newText.length &&
      oldText[commonPrefix] == newText[commonPrefix]) {
    commonPrefix++;
  }

  int commonSuffix = 0;
  while (commonSuffix < oldText.length - commonPrefix &&
      commonSuffix < newText.length - commonPrefix &&
      oldText[oldText.length - 1 - commonSuffix] ==
          newText[newText.length - 1 - commonSuffix]) {
    commonSuffix++;
  }

  return newText.substring(
    commonPrefix,
    newText.length - commonSuffix,
  );
}