private string Slugify(FillSlugContext slugContext) { _slugEventHandler.FillingSlugFromTitle(slugContext); if (!slugContext.Adjusted) { string stFormKD = slugContext.Title.ToLower().Normalize(NormalizationForm.FormKD); var sb = new StringBuilder(); foreach (char t in stFormKD) { // Allowed symbols if (t == '-' || t == '_' || t == '~') { sb.Append(t); continue; } UnicodeCategory uc = CharUnicodeInfo.GetUnicodeCategory(t); switch (uc) { case UnicodeCategory.LowercaseLetter: case UnicodeCategory.OtherLetter: case UnicodeCategory.DecimalDigitNumber: // Keep letters and digits sb.Append(t); break; case UnicodeCategory.NonSpacingMark: // Remove diacritics break; default: // Replace all other chars with dash sb.Append('-'); break; } } slugContext.Slug = sb.ToString().Normalize(NormalizationForm.FormC); // Simplifies dash groups for (int i = 0; i < slugContext.Slug.Length - 1; i++) { if (slugContext.Slug[i] == '-') { int j = 0; while (i + j + 1 < slugContext.Slug.Length && slugContext.Slug[i + j + 1] == '-') { j++; } if (j > 0) { slugContext.Slug = slugContext.Slug.Remove(i + 1, j); } } } if (slugContext.Slug.Length > 1000) { slugContext.Slug = slugContext.Slug.Substring(0, 1000); } slugContext.Slug = slugContext.Slug.Trim('-', '_', '.'); } _slugEventHandler.FilledSlugFromTitle(slugContext); return slugContext.Slug; }
private string Slugify(FillSlugContext slugContext) { _slugEventHandler.FillingSlugFromTitle(slugContext); if (!slugContext.Adjusted) { var disallowed = new Regex(@"[/:?#\[\]@!$&'()*+,;=\s\""\<\>\\\|]+"); slugContext.Slug = disallowed.Replace(slugContext.Title, "-").Trim('-','.'); if (slugContext.Slug.Length > 1000) slugContext.Slug = slugContext.Slug.Substring(0, 1000).Trim('-', '.'); slugContext.Slug = StringExtensions.RemoveDiacritics(slugContext.Slug.ToLower()); } _slugEventHandler.FilledSlugFromTitle(slugContext); return slugContext.Slug; }
private string Slugify(FillSlugContext slugContext) { _slugEventHandler.FillingSlugFromTitle(slugContext); if (!slugContext.Adjusted) { var disallowed = new Regex(@"[/:?#\[\]@!$&'()*+,;=\s\""\<\>\\]+"); slugContext.Slug = disallowed.Replace(slugContext.Title, "-").Trim('-', '.'); if (slugContext.Slug.Length > 1000) { slugContext.Slug = slugContext.Slug.Substring(0, 1000).Trim('-', '.'); } slugContext.Slug = StringExtensions.RemoveDiacritics(slugContext.Slug.ToLower()); } _slugEventHandler.FilledSlugFromTitle(slugContext); return(slugContext.Slug); }
public void FillingSlugFromTitle(FillSlugContext aContext) { if (aContext == null || string.IsNullOrWhiteSpace(aContext.Title)) { return; } // Lower input slug. string lSlug = aContext.Title.ToLower(RussianCulture); // Replace URL-disallowed characters with dashes. lSlug = DisallowedLettersRegex.Replace(lSlug, "-").Trim('-'); // Replace all cyrillic characters with english transleteration counterparts. lSlug = ReplaceCyrillicCharacters(lSlug); // Trim slug if it has more than 1000 characters. if (lSlug.Length > 1000) { lSlug = lSlug.Substring(0, 1000); } // Remove all leading and trailing dots from slug. lSlug = lSlug.Trim('.').ToLower(); // Processing is done. Don't process further. aContext.Slug = lSlug; aContext.Adjusted = true; }
public void FilledSlugFromTitle(FillSlugContext aContext) { }
private string Slugify(FillSlugContext slugContext) { _slugEventHandler.FillingSlugFromTitle(slugContext); if (!slugContext.Adjusted) { string stFormKD = slugContext.Title.ToLower().Normalize(NormalizationForm.FormKD); var sb = new StringBuilder(); foreach (char t in stFormKD) { // Allowed symbols if (t == '-' || t == '_' || t == '~') { sb.Append(t); continue; } UnicodeCategory uc = CharUnicodeInfo.GetUnicodeCategory(t); switch (uc) { case UnicodeCategory.LowercaseLetter: case UnicodeCategory.OtherLetter: case UnicodeCategory.DecimalDigitNumber: // Keep letters and digits sb.Append(t); break; case UnicodeCategory.NonSpacingMark: // Remove diacritics break; default: // Replace all other chars with dash sb.Append('-'); break; } } slugContext.Slug = sb.ToString().Normalize(NormalizationForm.FormC); // Simplifies dash groups for (int i = 0; i < slugContext.Slug.Length - 1; i++) { if (slugContext.Slug[i] == '-') { int j = 0; while (i + j + 1 < slugContext.Slug.Length && slugContext.Slug[i + j + 1] == '-') { j++; } if (j > 0) { slugContext.Slug = slugContext.Slug.Remove(i + 1, j); } } } if (slugContext.Slug.Length > 1000) { slugContext.Slug = slugContext.Slug.Substring(0, 1000); } slugContext.Slug = slugContext.Slug.Trim('-', '_', '.'); } _slugEventHandler.FilledSlugFromTitle(slugContext); return(slugContext.Slug); }
public void FillingSlugFromTitle(FillSlugContext context) { var localizationAspect = context.Content.As<ILocalizableAspect>(); if (localizationAspect == null) return; context.Title = _transliterationService.Convert(context.Title, localizationAspect.Culture); }