namespace HSchool.Simulation;
///
/// The rules a school name has to pass. A name arrives from a browser, so it is trimmed and
/// stripped before anything stores it.
///
public static class SchoolNames
{
/// Trims, strips control characters and enforces the length limit.
public static bool TryNormalize(string? name, out string normalized)
{
normalized = string.Empty;
if (string.IsNullOrWhiteSpace(name))
{
return false;
}
var cleaned = new string(name.Where(character => !char.IsControl(character)).ToArray()).Trim();
if (cleaned.Length == 0 || cleaned.Length > School.MaxNameLength)
{
return false;
}
normalized = cleaned;
return true;
}
}