CK.Keyboard.KeyboardContext.EnsureUnique C# (CSharp) Method

EnsureUnique() static private method

Computes a unique name (suffixed with '(n)' where n is a number) given a function that check existence of proposed names. It relies on R.KeyboardAutoNumPattern and R.KeyboardAutoNumRegex resources to offer culture dependant naming.
static private EnsureUnique ( string newName, string currentName, Predicate exists ) : string
newName string Proposed name.
currentName string Current name (null if none).
exists Predicate Function that check the existence.
return string
        internal static string EnsureUnique( string newName, string currentName, Predicate<string> exists )
        {
            string nCleaned = Regex.Replace( newName, R.KeyboardAutoNumRegex, String.Empty );
            string n = nCleaned;
            if ( n != currentName )
            {
                int autoNum = 1;
                while ( n != currentName && exists( n ) )
                {
                    n = String.Format( R.KeyboardAutoNumPattern, nCleaned, autoNum++ );
                }
            }
            return n;
        }