Factored out CharExtensions.ToDigit().