public void SendKey(Char key)
        {
            key = Char.ToLower(key);
            if(_currentSearchScope != null) {
                _currentSearchScope = _currentSearchScope.Next(key) ;
                if(_currentSearchScope != null) {
                    _buffer.Append(key);
                } else {
                    _buffer.Clear();
                    if (_topLevelLetters.ContainsKey(key)) {
                        _currentSearchScope = _topLevelLetters[key];
                        if (_currentSearchScope != null) {
                            _buffer.Append(key);
                        }
                    }
                }
            } else {
                if (_topLevelLetters.ContainsKey(key)) {
                    _buffer.Append(key);
                    _currentSearchScope = _topLevelLetters[key];
                }
            }

            if(_currentSearchScope != null &&
               _currentSearchScope.IsWordEnd()) {
                _wordEntered.OnNext(_buffer.ToString());
                _buffer = new StringBuilder();
                _currentSearchScope = null;
            }
        }
Beispiel #2
0
 public LetterNode AddChild(Char letter)
 {
     if (_nextLetters.ContainsKey(letter)) {
         return _nextLetters[letter];
     } else {
         var n = new LetterNode(letter);
         _nextLetters.Add(letter, n);
         return n;
     }
 }
        public void AddWord(string word)
        {
            LetterNode start;
            var firstLetter = Char.ToLower(word[0]);
            if(_topLevelLetters.ContainsKey(firstLetter)) {
                start = _topLevelLetters[firstLetter];
            } else {
                start = new LetterNode(firstLetter);
                _topLevelLetters.Add(firstLetter, start);
            }

            foreach(var letter in word.Skip(1)) {
                var newNode = start.AddChild(Char.ToLower(letter));
                start = newNode;
            }
        }