in client/Apache.ShenYu.Client/Registers/ShenyuConsulRegister.cs [119:150]
private string NormalizeForDns(string s)
{
if (string.ReferenceEquals(s, null) || !char.IsLetter(s[0]) || !char.IsLetterOrDigit(s[s.Length - 1]))
{
throw new System.ArgumentException("Consul service ids must not be empty, must start "
+ "with a letter, end with a letter or digit, "
+ "and have as interior characters only letters, "
+ "digits, and hyphen: " + s);
}
StringBuilder normalized = new StringBuilder();
char? prev = null;
foreach (char curr in s.ToCharArray())
{
char? toAppend = null;
if (char.IsLetterOrDigit(curr))
{
toAppend = curr;
}
else if (prev == null || !(prev == SEPARATOR))
{
toAppend = SEPARATOR;
}
if (toAppend != null)
{
normalized.Append(toAppend);
prev = toAppend;
}
}
return normalized.ToString();
}