Sunag.SEA3D.SEA3DAssimp.GetValidString C# (CSharp) Method

GetValidString() private method

private GetValidString ( IEnumerable objects, string name ) : string
objects IEnumerable
name string
return string
        private string GetValidString(IEnumerable<SEAObject> objects, string name)
        {
            if (name == null) name = "";

            foreach (SEAObject obj in objects)
            {
                if (obj.Name == name)
                {
                    Regex regex = new Regex("[0-9]+$");

                    int num = 0, numlen = 0;

                    if (regex.IsMatch(name))
                    {
                        Match match = regex.Match(name);

                        num = int.Parse(name.Substring(match.Index));
                        numlen = name.Length - match.Index;

                        name = name.Substring(0, match.Index);
                    }

                Rename:
                    while (true)
                    {
                        string numstr = (++num).ToString();

                        for (int i = 0; i < numlen; i++)
                        {
                            numstr = "0" + numstr;
                        }

                        string newname = name + numstr;

                        foreach (SEAObject obj2 in objects)
                        {
                            if (obj2.Name == newname)
                                goto Rename;
                        }

                        return newname;
                    }
                }
            }

            return name;
        }