Пример #1
0
        private InferResult InferMatch(int inputIndex, Token elementType, HashSet <char> invalidChars)
        {
            InferResult result           = new InferResult();
            char        currentInputChar = InputString[inputIndex];

            result.Ch = currentInputChar;

            switch (elementType)
            {
            case Token.Digit:
                TryFixupDigit(inputIndex, currentInputChar, elementType, result, invalidChars);
                break;

            case Token.Alpha:
                if (char.IsLetter(currentInputChar) == false && DetectAlphabetFixup(InputString, inputIndex) == FixupType.None)
                {
                    result.IsNoMatch = true;
                }
                else
                {
                    int newOffset = 1;
                    result.IsFixedUp = true;
                    char ch = AlphabetFixup(inputIndex, ref newOffset);
                    if (invalidChars.Contains(ch))
                    {
                        result.IsFixedUp = false;
                        result.IsNoMatch = true;
                        return(result);
                    }

                    result.Ch        = ch;
                    result.NewOffset = newOffset;
                }

                break;

            case Token.Both:
                AmbiguousResult ambiguousResult = CheckAmbiguous(ref inputIndex);
                result.Ch = ambiguousResult.Ch;
                if (ambiguousResult.IsAmbiguous)
                {
                    result.IsAmbiguous = true;
                }
                else
                {
                    TryFixupDigit(inputIndex, currentInputChar, elementType, result, invalidChars);
                }

                break;

            default:
                break;
            }

            return(result);
        }
Пример #2
0
        private AmbiguousResult CheckAmbiguous(ref int inputIndex)
        {
            AmbiguousResult match = new AmbiguousResult();
            char            input = InputString[inputIndex];

            match.Ch = input;

            switch (input)
            {
            case '8':
                match.IsAmbiguous = true;
                return(match);

            default:
                break;
            }

            return(match);
        }