uniquifyId method

String uniquifyId(
  1. String id
)

Uniquifies an id generated from text.

Implementation

String uniquifyId(String id) {
  if (!uniqueIds.contains(id)) {
    uniqueIds.add(id);
    return id;
  }

  var suffix = 2;
  var suffixedId = '$id-$suffix';
  while (uniqueIds.contains(suffixedId)) {
    suffixedId = '$id-${suffix++}';
  }
  uniqueIds.add(suffixedId);
  return suffixedId;
}