Files
Umbraco-CMS/umbraco/cms/helpers/Casing.cs
hartvig a2e01c1ac2 WORK IN PROGRESS, GET THE STABLE SOURCE FROM THE DOWNLOADS TAB
Adds support for new 4.1 content schema

[TFS Changeset #63631]
2010-01-28 22:59:50 +00:00

40 lines
1.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace umbraco.cms.helpers
{
public class Casing
{
private const string ValidCharacters = "_-abcdefghijklmnopqrstuvwxyz";
/// <summary>
/// A helper method to ensure that an Alias string doesn't contains any illegal characters
/// which is defined in a private constant 'ValidCharacters' in this class.
/// Conventions over configuration, baby. You can't touch this - MC Hammer!
/// </summary>
/// <param name="alias">The alias.</param>
/// <returns>An alias guaranteed not to contain illegal characters</returns>
public static string SafeAlias(string alias)
{
StringBuilder safeString = new StringBuilder();
int aliasLength = alias.Length;
for (int i = 0; i < aliasLength;i++ )
{
string currentChar = alias.Substring(i, 1);
if (ValidCharacters.Contains(currentChar.ToLower()))
{
// check for camel (if next character is a space, we'll upper case the current one
if (i < aliasLength-1 && alias.Substring(i + 1, 1) == " ")
currentChar = currentChar.ToUpper();
safeString.Append(currentChar);
}
}
return safeString.ToString();
}
}
}