using System.Text; namespace SlpModularCms.Modules.Offerings.Services; /// /// Turns a title into a URL/display-safe slug (lowercase, hyphen-separated, no diacritics). /// Pure string transform — uniqueness is handled by the caller. /// public static class Slugifier { public static string Slugify(string value) { var normalized = value.Normalize(NormalizationForm.FormD); var builder = new StringBuilder(normalized.Length); var lastWasHyphen = false; foreach (var c in normalized) { var category = System.Globalization.CharUnicodeInfo.GetUnicodeCategory(c); if (category == System.Globalization.UnicodeCategory.NonSpacingMark) continue; if (char.IsLetterOrDigit(c)) { builder.Append(char.ToLowerInvariant(c)); lastWasHyphen = false; } else if (!lastWasHyphen && builder.Length > 0) { builder.Append('-'); lastWasHyphen = true; } } if (lastWasHyphen) builder.Length--; return builder.Length > 0 ? builder.ToString() : "pakket"; } }