/* * Box Social™ * http://boxsocial.net/ * Copyright © 2007, David Lachlan Smith * * $Id:$ * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Globalization; using System.Text; using System.Text.RegularExpressions; using BoxSocial.IO; namespace BoxSocial.Internals { public static class Navigation { public static void GenerateSlug(string title, ref string slug) { if (string.IsNullOrEmpty(slug)) { slug = title; } NormaliseSlug(ref slug); } public static void NormaliseSlug(ref string slug) { // normalise slug if it has been fiddeled with slug = slug.ToLower().Normalize(NormalizationForm.FormD); string normalisedSlug = string.Empty; for (int i = 0; i < slug.Length; i++) { if (CharUnicodeInfo.GetUnicodeCategory(slug[i]) != UnicodeCategory.NonSpacingMark) { normalisedSlug += slug[i]; } } slug = Regex.Replace(normalisedSlug, @"([\W]+)", "-"); } } }