/// <summary>
 /// Determines whether the given word can be added to the user ignore word list.
 /// </summary>
 /// <param name="word">The word to check for.</param>
 /// <returns> <c>true</c> if the given word can be added to the user ignore word list; otherwise, <c>false</c>.</returns>
 public bool CanAddToUserIgnoreList(string word)
 {
     return(!IgnoreList.Exists(f =>
                               string.Compare(f, word, StringComparison.Ordinal) == 0));
 }
        /// <summary>
        /// Fetches the miss-spelled words and their locations of the given text using compiled regular expression to match the words.
        /// </summary>
        public List <SpellingError> SpellCheckFast(string text)
        {
            var result = new List <SpellingError>();

            var words = WordBoundaryRegex.Matches(text);


            // initialize a list of failed words to speed up the spell checking..
            List <string> failedWords = new List <string>();

            // initialize a list of passed words to speed up the spell checking..
            List <string> wordOkList = new List <string>();


            for (int i = 0; i < words.Count; i++)
            {
                if (wordOkList.Contains(words[i].Value))
                {
                    // already passed the check..
                    continue;
                }

                // check if the word is already in the list of failed words..
                bool inFailedWordList = failedWords.Contains(words[i].Value);

                if (inFailedWordList)
                {
                    // ..add the location to the result..
                    result.Add(new SpellingError
                    {
                        StartLocation = words[i].Index, EndLocation = words[i].Length + words[i].Index,
                        Word          = words[i].Value,
                    });
                    continue;
                }

                // check the ignore list..
                if (IgnoreList.Exists(f =>
                                      string.Equals(f, words[i].Value, StringComparison.InvariantCultureIgnoreCase)))
                {
                    // flag the word as ok to prevent re-checking the validity..
                    wordOkList.Add(words[i].Value);

                    // the word is valid via user dictionary or user ignore list..
                    continue;
                }

                // validate the possible user dictionary..
                bool userDictionaryOk = UserDictionary?.Check(words[i].Value) ?? false;

                if (userDictionaryOk)
                {
                    // flag the word as ok to prevent re-checking the validity..
                    wordOkList.Add(words[i].Value);

                    // the word is valid via user dictionary or user ignore list..
                    continue;
                }

                // validate the word with the loaded dictionary..
                if (!DictionaryCheck(words[i].Value))
                {
                    // flag the word as invalid to prevent re-checking the validity..
                    failedWords.Add(words[i].Value);

                    // ..add the location to the result..
                    result.Add(new SpellingError
                    {
                        StartLocation = words[i].Index, EndLocation = words[i].Length + words[i].Index,
                        Word          = words[i].Value,
                    });
                }
                else
                {
                    // flag the word as ok to prevent re-checking the validity..
                    wordOkList.Add(words[i].Value);
                }
            }

            return(result);
        }
示例#3
0
            public userConextMenu(ChatMessage parent) : base()
            {
                this.Items.Add(new MenuItem()
                {
                    Header = "Open profile"
                });

                if (!FriendList.Exists(parent.Nickname))
                {
                    this.Items.Add(new MenuItem()
                    {
                        Header = "Add to friend list"
                    });
                    ((MenuItem)Items[1]).Click += (o, e) =>
                    {
                        App.FriendList.Add(parent.Nickname);

                        //osu_chat.MainWindow.friends.Add(await osu_chat.MainWindow.GetChatUser(parent.Nickname));
                    };
                }
                else
                {
                    this.Items.Add(new MenuItem()
                    {
                        Header = "Remove from friend list"
                    });
                    ((MenuItem)Items[1]).Click += (o, e) =>
                    {
                        App.FriendList.Remove(parent.Nickname);

                        //osu_chat.MainWindow.friends.Remove(osu_chat.MainWindow.friends.Where(u => u.Nickname == parent.Nickname).First());
                    };
                }

                if (!IgnoreList.Exists(parent.Nickname))
                {
                    this.Items.Add(new MenuItem()
                    {
                        Header = "Add to ignore list"
                    });
                    ((MenuItem)Items[2]).Click += (o, e) =>
                    {
                        IgnoreList.Add(parent.Nickname);

                        //osu_chat.MainWindow.ignoredUser.Add(await osu_chat.MainWindow.GetChatUser(parent.Nickname));
                    };
                }
                else
                {
                    this.Items.Add(new MenuItem()
                    {
                        Header = "Remove from ignore list"
                    });
                    ((MenuItem)Items[2]).Click += (o, e) =>
                    {
                        IgnoreList.Remove(parent.Nickname);
                    };
                }


                ((MenuItem)Items[0]).Click += async(o, e) =>
                {
                    // zameniti na user id
                    Process.Start(string.Format("http://osu.ppy.sh/u/{0}", (await Osu.Api.GetUserAsync(ApiKey, parent.Nickname)).UserId));
                };
            }