public void Add(Token token) { if (null != token.Position) { this.errorPositions.ShiftLeft(true); } else { this.errorPositions.ShiftLeft(false); } history.Enqueue(token); if (history.Count > this.windowSize) { history.Dequeue(); } }
public MisspelledWord HandleChar(char chr, bool padding = false) { currentPos++; MisspelledWord misspelling = null; if (padding && word == String.Empty) { window.Add(new Token('.', true)); misspelling = window.GetMisspelledWord(); } else { switch (chr) { case '\r': case '\n': case '.': case '?': case '!': case ' ': Token token = null; if (String.Empty != word) { bool skipDetection = false; string[] wordContext = this.TrimSpecialChars(word); string pureWord = wordContext[1].ToLowerInvariant(); if (pureWord.Length == 1) { skipDetection = true; } if (containSpecial.Match(pureWord).Success || abbreviation.Match(wordContext[1]).Success || this.IsProbablyName(wordContext[1])) { skipDetection = true; } if (string.Empty == pureWord) { if (tokenWithAlphanum.Match(word).Success) { skipDetection = true; pureWord = word; } else { lastStart = currentPos; word = String.Empty; break; } } bool context = this.HasContextEnded(chr) ? true : false; if (!skipDetection && !this.dictionary.FindWord(pureWord)) { token = new Token(pureWord, context, wordContext, lastStart); } else { token = new Token(pureWord, context); } word = String.Empty; } if (null != token) { window.Add(token); lastToken = token; misspelling = window.GetMisspelledWord(); } lastStart = currentPos; break; default: word += chr; break; } } return misspelling; }