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); }
private void TryFixupDigit(int inputIndex, char currentInputChar, Token elementType, InferResult result, HashSet <char> invalidChars) { int newOffset = 1; result.IsFixedUp = DetectDigitFixup(InputString, inputIndex); if (char.IsDigit(currentInputChar) == false && !result.IsFixedUp) { if (elementType == Token.Digit) { result.IsNoMatch = true; } } else if (result.IsFixedUp) { char ch = DigitFixup(inputIndex, ref newOffset); if (invalidChars.Contains(ch)) { result.IsNoMatch = true; } else { result.Ch = ch; result.NewOffset = newOffset; } } }