コード例 #1
0
ファイル: SRTCount.cs プロジェクト: harrywong/SubtitleCount
        public CountResult Count(string content)
        {
            int words = 0, lines = 0;
            var lineWords = new List<int>();

            var linesMatch = Regex.Matches(content, LinePattern, RegexOptions.Multiline);

            bool textLine = false;
            foreach (Match match in linesMatch)
            {
                if (match.Value.Contains("-->"))
                {
                    textLine = true;
                    continue;
                }
                if (textLine)
                {
                    string text = match.Value.Trim().Replace(" ", "").Replace(" ", "");
                    int line = text.Length;
                    words += line;
                    lines++;
                    lineWords.Add(line);
                    textLine = false;
                }
            }

            var result = new CountResult(words, lines);
            result.LineWords = lineWords;

            return result;
        }
コード例 #2
0
ファイル: ASSCount.cs プロジェクト: harrywong/SubtitleCount
        public CountResult Count(string content)
        {
            int words = 0, lines = 0;
            var lineWords = new List<int>();
            var regexResult = Regex.Matches(content, TextPattern, RegexOptions.Multiline);

            lines = regexResult.Count;
            foreach (Match match in regexResult)
            {
                if (match.Groups["text"].Success)
                {
                    string text = match.Groups["text"].Value.Trim().Replace(" ", "").Replace(" ", "");
                    var tagRegexResult = Regex.Matches(text, TagPattern);
                    int line = text.Length - tagRegexResult.Cast<Match>().Sum(c => c.Value.Length);
                    words += line;
                    lineWords.Add(line);
                }
            }

            var result = new CountResult(words, lines) { LineWords = lineWords };
            return result;
        }