public bool IsValidCaptcha(string text) { if (text == null || CurrentText == null) { return(false); } return(text.ToLower().Equals(CurrentText.ToLower())); }
private void textBox1_TextChanged(object sender, TextChangedEventArgs e) { if (ReplacingNow) { return; } if (!WordStart) { foreach (TextChange change in e.Changes) { if (change.AddedLength > 0) { switch (textBoxContent.Text.Substring(change.Offset, 1)) { case " ": case ",": case ".": case ":": case ";": case "(": case ")": case "!": case "?": case "\"": WordStart = true; UsernameStarted = false; HashtagStarted = false; break; default: WordStart = false; break; } if (WordStart) { break; } } } } if (UsernameStarted || HashtagStarted) { foreach (TextChange change in e.Changes) { if (change.AddedLength > 0) { switch (textBoxContent.Text.Substring(change.Offset, 1)) { case " ": case ",": case ".": case ":": case ";": case "(": case ")": case "!": case "?": case "\"": WordStart = true; UsernameStarted = false; HashtagStarted = false; break; default: WordStart = false; break; } if (WordStart) { break; } } } } if (WordStart && (!UsernameStarted && !HashtagStarted)) { foreach (TextChange change in e.Changes) { if (change.AddedLength > 0) { if (textBoxContent.Text.Substring(change.Offset, 1) == " ") { WordStart = true; continue; } else { WordStart = false; } if (textBoxContent.Text.Substring(change.Offset, 1) == "@") { UsernameStarted = true; StartPosition = change.Offset; CurrentText = ""; } else if (textBoxContent.Text.Substring(change.Offset, 1) == "#") { HashtagStarted = true; StartPosition = change.Offset; CurrentText = ""; } } } } if (UsernameStarted) { foreach (TextChange change in e.Changes) { if (change.AddedLength > 0) { CurrentText += textBoxContent.Text.Substring(change.Offset, change.AddedLength); } else if (change.RemovedLength > 0) { if (change.RemovedLength >= CurrentText.Length) { UsernameStarted = false; CurrentText = ""; MatchingTexts.Clear(); popupMatchingUsernames.IsOpen = false; return; } else if (change.RemovedLength == CurrentText.Length) { WordStart = true; CurrentText = ""; popupMatchingUsernames.IsOpen = false; MatchingTexts.Clear(); } else { CurrentText = CurrentText.Substring(0, CurrentText.Length - change.RemovedLength); } } } if (Usernames.Where(name => name.ToLower().StartsWith(CurrentText.ToLower())).Count() > 0) { MatchingTexts.Clear(); foreach (string username in Usernames.Where(name => name.ToLower().StartsWith(CurrentText.ToLower()))) { MatchingTexts.Add(username); if (MatchingTexts.Count >= Properties.Settings.Default.MaxNumberOfEntriesInAutocomplete) { break; } } popupMatchingUsernames.PlacementRectangle = textBoxContent.GetRectFromCharacterIndex(textBoxContent.CaretIndex, true); popupMatchingUsernames.IsOpen = true; } else { MatchingTexts.Clear(); popupMatchingUsernames.IsOpen = false; } } else if (HashtagStarted) { foreach (TextChange change in e.Changes) { if (change.AddedLength > 0) { CurrentText += textBoxContent.Text.Substring(change.Offset, change.AddedLength); } else if (change.RemovedLength > 0) { if (change.RemovedLength >= CurrentText.Length) { HashtagStarted = false; CurrentText = ""; MatchingTexts.Clear(); popupMatchingUsernames.IsOpen = false; return; } else if (change.RemovedLength == CurrentText.Length) { WordStart = true; CurrentText = ""; popupMatchingUsernames.IsOpen = false; MatchingTexts.Clear(); } else { CurrentText = CurrentText.Substring(0, CurrentText.Length - change.RemovedLength); } } } if (Hashtags.Where(tag => tag.ToLower().StartsWith(CurrentText.ToLower())).Count() > 0) { MatchingTexts.Clear(); foreach (string hashtag in Hashtags.Where(tag => tag.ToLower().StartsWith(CurrentText.ToLower()))) { MatchingTexts.Add(hashtag); if (MatchingTexts.Count >= Properties.Settings.Default.MaxNumberOfEntriesInAutocomplete) { break; } } popupMatchingUsernames.PlacementRectangle = textBoxContent.GetRectFromCharacterIndex(textBoxContent.CaretIndex, true); popupMatchingUsernames.IsOpen = true; } else { MatchingTexts.Clear(); popupMatchingUsernames.IsOpen = false; } } }
private void textBox1_TextChanged(object sender, TextChangedEventArgs e) { if (ReplacingNow) { return; } if (!WordStart) { foreach (TextChange change in e.Changes) { if (change.AddedLength > 0) { switch (textBoxContent.Text.Substring(change.Offset, 1)) { case " ": case ",": case ".": case ":": case ";": case "(": case ")": case "!": case "?": case "\"": WordStart = true; UsernameStarted = false; HashtagStarted = false; break; default: WordStart = false; break; } if (WordStart) { break; } } } } if (UsernameStarted || HashtagStarted) { foreach (TextChange change in e.Changes) { if (change.AddedLength > 0) { switch (textBoxContent.Text.Substring(change.Offset, 1)) { case " ": case ",": case ".": case ":": case ";": case "(": case ")": case "!": case "?": case "\"": WordStart = true; UsernameStarted = false; HashtagStarted = false; break; default: WordStart = false; break; } if (WordStart) { break; } } } } if (WordStart && (!UsernameStarted && !HashtagStarted)) { foreach (TextChange change in e.Changes) { if (change.AddedLength > 0) { if (textBoxContent.Text.Substring(change.Offset, 1) == " ") { WordStart = true; continue; } else { WordStart = false; } if (textBoxContent.Text.Substring(change.Offset, 1) == "@") { UsernameStarted = true; StartPosition = change.Offset; CurrentText = ""; } else if (textBoxContent.Text.Substring(change.Offset, 1) == "#") { HashtagStarted = true; StartPosition = change.Offset; CurrentText = ""; } } } } if (UsernameStarted) { foreach (TextChange change in e.Changes) { if (change.AddedLength > 0) { CurrentText += textBoxContent.Text.Substring(change.Offset, change.AddedLength); } else if (change.RemovedLength > 0) { if (change.RemovedLength >= CurrentText.Length) { UsernameStarted = false; CurrentText = ""; MatchingTexts.Clear(); popupMatchingUsernames.IsOpen = false; return; } else if (change.RemovedLength == CurrentText.Length) { WordStart = true; CurrentText = ""; popupMatchingUsernames.IsOpen = false; MatchingTexts.Clear(); } else { CurrentText = CurrentText.Substring(0, CurrentText.Length - change.RemovedLength); } } } if (AppController.Current.AllKnownUsernames.Where(name => name.ToLower().StartsWith(CurrentText.ToLower())).Count() > 0) { MatchingTexts.Clear(); foreach (string username in AppController.Current.AllKnownUsernames.Where(name => name.ToLower().StartsWith(CurrentText.ToLower()))) { MatchingTexts.Add(username); if (MatchingTexts.Count >= 10) { break; } } popupMatchingUsernames.PlacementRectangle = textBoxContent.GetRectFromCharacterIndex(textBoxContent.CaretIndex, true); popupMatchingUsernames.IsOpen = true; } else { MatchingTexts.Clear(); popupMatchingUsernames.IsOpen = false; } } else if (HashtagStarted) { foreach (TextChange change in e.Changes) { if (change.AddedLength > 0) { CurrentText += textBoxContent.Text.Substring(change.Offset, change.AddedLength); } else if (change.RemovedLength > 0) { if (change.RemovedLength >= CurrentText.Length) { HashtagStarted = false; CurrentText = ""; MatchingTexts.Clear(); popupMatchingUsernames.IsOpen = false; return; } else if (change.RemovedLength == CurrentText.Length) { WordStart = true; CurrentText = ""; popupMatchingUsernames.IsOpen = false; MatchingTexts.Clear(); } else { CurrentText = CurrentText.Substring(0, CurrentText.Length - change.RemovedLength); } } } if (AppController.Current.AllKnownHashtags.Where(tag => tag.ToLower().StartsWith(CurrentText.ToLower())).Count() > 0) { MatchingTexts.Clear(); foreach (string hashtag in AppController.Current.AllKnownHashtags.Where(tag => tag.ToLower().StartsWith(CurrentText.ToLower()))) { MatchingTexts.Add(hashtag); if (MatchingTexts.Count >= 10) { break; } } popupMatchingUsernames.PlacementRectangle = textBoxContent.GetRectFromCharacterIndex(textBoxContent.CaretIndex, true); popupMatchingUsernames.IsOpen = true; } else { MatchingTexts.Clear(); popupMatchingUsernames.IsOpen = false; } } #region links as markups string pattern = @"\[(?<markupText>[^\]]+)\]\((?<markupLink>[^)]+)\)"; NumberOfChars = textBoxContent.Text.Length; MarkdownLinksInText.Clear(); foreach (Match match in Regex.Matches(textBoxContent.Text, pattern, RegexOptions.IgnoreCase)) { if (!MarkdownLinksInText.ContainsKey(match.Groups["markupLink"].Value)) { MarkdownLinksInText.Add(match.Groups["markupLink"].Value, match.Groups["markupText"].Value); } NumberOfChars -= 4 + match.Groups["markupLink"].Value.Length; } #endregion }