static string[] VersionToArray(string version)
{
if (string.IsNullOrEmpty(version))
{
return Array.Empty<string>();
}
var sb = new StringBuilder(version.Length);
char last = '\0';
for (int i = 0; i < version.Length; i++)
{
var ch = version[i];
if (ch == '-' || ch == '+' || ch == '_' || ch == '.')
{
if (last != '.')
{
sb.Append(last = '.');
}
}
else if (i > 0 && (char.IsDigit(ch) ^ char.IsDigit(version[i - 1])))
{
if (last != '.')
{
sb.Append('.');
}
sb.Append(last = ch);
}
else if (char.IsLetterOrDigit(ch))
{
sb.Append(last = ch);
}
else
{
if (last != '.')
{
sb.Append(last = '.');
}
}
}
if (last == '.')
{
sb.Length--;
}
return sb.ToString().Split('.');
}