normalizePrefix function

String normalizePrefix(
  1. String value
)

Normalizes one path segment into '' or /segment form.

Empty input, '/', and '//' all collapse to '' so that joining is associative and a controller mounted at the root does not gain a trailing slash.

Implementation

String normalizePrefix(String value) {
  var normalized = value.trim();
  if (normalized.isEmpty) return '';
  if (!normalized.startsWith('/')) normalized = '/$normalized';
  while (normalized.length > 1 && normalized.endsWith('/')) {
    normalized = normalized.substring(0, normalized.length - 1);
  }
  normalized = normalized.replaceAll(RegExp('/+'), '/');
  return normalized == '/' ? '' : normalized;
}