예제 #1
0
        private static string GenerateAlias(string input, int desiredLength, bool mapToAnsi, bool skipInvalidCharacter, char invalidCharacterReplacement)
        {
            if (string.IsNullOrEmpty(input))
            {
                throw new ArgumentNullException("input");
            }
            if (AliasHelper.Analyze(invalidCharacterReplacement) != AliasHelper.CharacterCategory.RegularCharacter)
            {
                throw new ArgumentOutOfRangeException("invalidCharacterReplacement", invalidCharacterReplacement, new LocalizedString("DEV BUG: Parameter 'invalidCharacterReplacement' should be category of CharacterCategory.RegularCharacter."));
            }
            if (mapToAnsi)
            {
                input = UnicodeToAnsiConverter.Convert(input, skipInvalidCharacter, invalidCharacterReplacement);
            }
            StringBuilder stringBuilder = new StringBuilder(input.Length);

            AliasHelper.RecognisingState recognisingState = AliasHelper.RecognisingState.Start;
            int num  = 0;
            int num2 = 0;

            while (input.Length > num && desiredLength > num2)
            {
                char c = input[num];
                AliasHelper.CharacterCategory characterCategory = AliasHelper.Analyze(c);
                if (characterCategory != AliasHelper.CharacterCategory.WhiteSpaceSymbol)
                {
                    switch (recognisingState)
                    {
                    case AliasHelper.RecognisingState.Start:
                        switch (characterCategory)
                        {
                        case AliasHelper.CharacterCategory.RegularCharacter:
                            recognisingState = AliasHelper.RecognisingState.Terminal;
                            break;

                        case AliasHelper.CharacterCategory.InvalidCharacter:
                        case AliasHelper.CharacterCategory.DotSymbol:
                            if (skipInvalidCharacter)
                            {
                                goto IL_149;
                            }
                            c = invalidCharacterReplacement;
                            recognisingState = AliasHelper.RecognisingState.Terminal;
                            break;
                        }
                        break;

                    case AliasHelper.RecognisingState.Terminal:
                        switch (characterCategory)
                        {
                        case AliasHelper.CharacterCategory.InvalidCharacter:
                            if (skipInvalidCharacter)
                            {
                                goto IL_149;
                            }
                            c = invalidCharacterReplacement;
                            break;

                        case AliasHelper.CharacterCategory.DotSymbol:
                            if (input.Length - 1 == num || desiredLength - 1 == num2)
                            {
                                if (skipInvalidCharacter)
                                {
                                    goto IL_149;
                                }
                                c = invalidCharacterReplacement;
                            }
                            else
                            {
                                recognisingState = AliasHelper.RecognisingState.Middle;
                            }
                            break;
                        }
                        break;

                    case AliasHelper.RecognisingState.Middle:
                        switch (characterCategory)
                        {
                        case AliasHelper.CharacterCategory.RegularCharacter:
                            recognisingState = AliasHelper.RecognisingState.Terminal;
                            break;

                        case AliasHelper.CharacterCategory.InvalidCharacter:
                        case AliasHelper.CharacterCategory.DotSymbol:
                            if (skipInvalidCharacter && input.Length - 1 > num && desiredLength - 1 > num2)
                            {
                                goto IL_149;
                            }
                            c = invalidCharacterReplacement;
                            recognisingState = AliasHelper.RecognisingState.Terminal;
                            break;
                        }
                        break;
                    }
                    stringBuilder.Append(c);
                    num2++;
                }
IL_149:
                num++;
            }
            if (AliasHelper.RecognisingState.Terminal != recognisingState)
            {
                return(null);
            }
            return(stringBuilder.ToString());
        }
예제 #2
0
 public static string GenerateAlias(string input, bool skipInvalidCharacter)
 {
     return(AliasHelper.GenerateAlias(input, AliasHelper.MaximalAliasLength, true, skipInvalidCharacter, '?'));
 }
예제 #3
0
 public static string GenerateAlias(string input, char invalidCharacterReplacement)
 {
     return(AliasHelper.GenerateAlias(input, AliasHelper.MaximalAliasLength, true, false, invalidCharacterReplacement));
 }
예제 #4
0
 public static string GenerateAlias(string input)
 {
     return(AliasHelper.GenerateAlias(input, AliasHelper.MaximalAliasLength, true, false, '?'));
 }