private static int NumberOfMentionsInTweet(string account, string tweetText)
 {
     const string twitterAccountPattern = @"@[A-Za-z0-9_]{1,15}";
     var matches = new Regex(twitterAccountPattern).Matches(tweetText);
     return
         matches.Cast<object>().Count(match =>(account.IndexOf(match.ToString(), StringComparison.CurrentCultureIgnoreCase) < 0));
 }
Example #2
0
        public static void CommandHandler(object sender, ExecutedRoutedEventArgs ea)
        {
            ea.Handled = true;
            var mainWindow = (MainWindow)Application.Current.MainWindow;
            var tweet = ea.Parameter as Tweet ?? mainWindow.Timeline.GetSelectedTweet;
            if (tweet == null) return;
            if (tweet.IsDirectMessage)
            {
                mainWindow.Compose.ShowDirectMessage(tweet.ScreenName);
            }
            else
            {
                var matches = new Regex(@"(?<=^|(?<=[^a-zA-Z0-9-_\.]))@([A-Za-z]+[A-Za-z0-9_]+)")
                    .Matches(tweet.Text);

                var names = matches
                    .Cast<Match>()
                    .Where(m => m.Groups[1].Value != tweet.ScreenName)
                    .Where(m => m.Groups[1].Value != Settings.Default.ScreenName)
                    .Select(m => "@" + m.Groups[1].Value)
                    .Distinct();

                var replyTos = string.Join(" ", names);
                var message = string.Format("@{0} {1}{2}", tweet.ScreenName, replyTos, (replyTos.Length > 0) ? " " : "");
                mainWindow.Compose.Show(message, tweet.StatusId);
            }
        }
Example #3
0
        private IEnumerable<IProjectInfo> ResolveProjectFilesFrom(FileInfo file)
        {
            IEnumerable<IProjectInfo> projects;
            using (var reader = new StreamReader(file.OpenRead()))
            {
                var content = reader.ReadToEnd();
                var matches = new Regex("[.A-Za-z0-9\\\\]*.csproj").Matches(content);

                projects = matches.Cast<Match>()
                    .Where(match => File.Exists(string.Format("{0}\\{1}", file.DirectoryName, match.Value)))
                    .Select(match => ProjectInfoFrom(file, match));
            }
            return projects;
        }
Example #4
0
        internal static string ReplaceImg(string html)
        {
            var originalImages = new Regex(@"<img([^>]+)>").Matches(html);
            originalImages.Cast<Match>().Each(image =>
                {
                    var img = image.Value;
                    var src = AttributeParser(img, "src");
                    var alt = AttributeParser(img, "alt");
                    var title = AttributeParser(img, "title");

                    html = html.Replace(img, string.Format(@"![{0}]({1}{2})", alt, src, (title.Length > 0) ? string.Format(" \"{0}\"", title) : ""));
                });

            return html;
        }
Example #5
0
        public static string ReplaceAnchor(string html)
        {
            var originalAnchors = new Regex(@"<a[^>]+>[^<]+</a>").Matches(html);
            originalAnchors.Cast<Match>().Each(anchor =>
                {
                    var a = anchor.Value;
                    var linkText = GetLinkText(a);
                    var href = AttributeParser(a, "href");
                    var title = AttributeParser(a, "title");

                    html = html.Replace(a, string.Format(@"[{0}]({1}{2})", linkText, href, (title.Length > 0) ? string.Format(" \"{0}\"", title) : ""));
                });

            return html;
        }
Example #6
0
        internal static string ReplacePre(string html)
        {
            var preTags = new Regex(@"<pre\b[^>]*>([\s\S]*)<\/pre>").Matches(html);

            return preTags.Cast<Match>().Aggregate(html, ConvertPre);
        }
        internal static string SortChapterByName(MangaChapter arg)
        {
            var matches = new Regex(@"(([0-9])*[0-9])").Matches(arg.Name);
            if (matches.Count < 1) return "";

            return arg.Name.Substring(0, arg.Name.IndexOf(matches[0].Value)) + matches.Cast<Match>().Select(n => n.Value.PadLeft(3, '0')).Aggregate((m, n) => m + n);
        }
Example #8
0
 private static IList<string> GetUnsubstitutedSettings(string content)
 {
     var matches = new Regex(@"(?<!`)\${([^}]*)}").Matches(content);
     return (matches.Cast<object>().Select(match => match.ToString())).ToList();
 }
Example #9
0
        private IList<IProjectFile> ResolveProjectFilesFrom(string content)
        {
            var matches = new Regex("[.A-Za-z0-9\\\\]*.csproj").Matches(content);

            var projectFiles =  matches.Cast<Match>()
                    .Select(match => ProjectFile.Load(string.Format("{0}\\{1}", Path, match.Value)))
                    .Cast<IProjectFile>().ToList();

            if (projectFiles.IsEmpty()) throw new NoProjectsInSolutionComplaint(this);
            return projectFiles;
        }
Example #10
0
		public static string ReplaceCode(string html)
		{
			var singleLineCodeBlocks = new Regex(@"<code>([^\n]*?)</code>").Matches(html);
			singleLineCodeBlocks.Cast<Match>().ToList().ForEach(block =>
			{
				var code = block.Value;
				var content = GetCodeContent(code);
				html = html.Replace(code, string.Format("`{0}`", content));
			});

			var multiLineCodeBlocks = new Regex(@"<code>([^>]*?)</code>").Matches(html);
			multiLineCodeBlocks.Cast<Match>().ToList().ForEach(block =>
			{
				var code = block.Value;
				var content = GetCodeContent(code);
				content = IndentLines(content).TrimEnd() + Environment.NewLine + Environment.NewLine;
				html = html.Replace(code, string.Format("{0}    {1}", Environment.NewLine, TabsToSpaces(content)));
			});

			return html;
		}