using System;
using System.Text.RegularExpressions;
namespace Mustache
{
///
/// Provides utility methods that require regular expressions.
///
internal static class RegexHelper
{
public const string Key = @"[_\w][_\w\d]*";
public const string String = @"'.*?'";
public const string Number = @"[-+]?\d*\.?\d+";
public const string CompoundKey = "@?" + Key + @"(?:\." + Key + ")*";
public const string Argument = @"(?:(?" + CompoundKey + @")|(?" + String + @")|(?" + Number + @"))";
///
/// Determines whether the given name is a legal identifier.
///
/// The name to check.
/// True if the name is a legal identifier; otherwise, false.
public static bool IsValidIdentifier(string name)
{
if (name == null)
{
return false;
}
Regex regex = new Regex("^" + Key + "$");
return regex.IsMatch(name);
}
public static bool IsString(string value)
{
if (value == null)
{
return false;
}
Regex regex = new Regex("^" + String + "$");
return regex.IsMatch(value);
}
public static bool IsNumber(string value)
{
if (value == null)
{
return false;
}
Regex regex = new Regex("^" + Number + "$");
return regex.IsMatch(value);
}
}
}