2013-04-24 12:58:19 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
2013-05-03 12:44:51 +00:00
|
|
|
|
namespace Mustache
|
2013-04-24 12:58:19 +00:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Provides utility methods that require regular expressions.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static class RegexHelper
|
|
|
|
|
{
|
2013-08-17 03:35:46 +00:00
|
|
|
|
internal const string Key = @"[_\w][_\w\d]*";
|
2013-04-24 12:58:19 +00:00
|
|
|
|
internal const string CompoundKey = Key + @"(\." + Key + ")*";
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Determines whether the given name is a legal identifier.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="name">The name to check.</param>
|
|
|
|
|
/// <returns>True if the name is a legal identifier; otherwise, false.</returns>
|
|
|
|
|
public static bool IsValidIdentifier(string name)
|
|
|
|
|
{
|
|
|
|
|
if (name == null)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
Regex regex = new Regex("^" + Key + "$");
|
|
|
|
|
return regex.IsMatch(name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|