Premiere commit - Omika
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Omika.HfSqlProbe;
|
||||
|
||||
internal static partial class SqlIdentifierValidator
|
||||
{
|
||||
/// <summary>Accepts only letters, digits, and underscores.</summary>
|
||||
[GeneratedRegex(@"\A[A-Za-z_][A-Za-z0-9_]*\z")]
|
||||
private static partial Regex IdentifierPattern();
|
||||
|
||||
public static bool IsValid(string name) => IdentifierPattern().IsMatch(name);
|
||||
|
||||
/// <summary>Validates and returns the identifier, or throws on invalid input.</summary>
|
||||
public static string Validate(string name)
|
||||
{
|
||||
if (!IsValid(name))
|
||||
throw new ArgumentException(
|
||||
$"Invalid SQL identifier: '{name}'. Only [A-Za-z0-9_] allowed.");
|
||||
return name;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user