Word counter now acts more like the word counter in MS Word - thx Barbara :)

This commit is contained in:
Nikolaj Olsson 2017-04-03 18:16:46 +02:00
parent f0c13c2236
commit 652844dc2b
3 changed files with 9 additions and 3 deletions

View File

@ -150,8 +150,7 @@ namespace Nikse.SubtitleEdit.Core
{
if (string.IsNullOrEmpty(Text))
return 0;
int wordCount = HtmlUtil.RemoveHtmlTags(Text, true).Split(new[] { ' ', ',', '.', '!', '?', ';', ':', '(', ')', '[', ']', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries).Length;
return (60.0 / Duration.TotalSeconds) * wordCount;
return (60.0 / Duration.TotalSeconds) * Text.CountWords();
}
}
}

View File

@ -90,6 +90,11 @@ namespace Nikse.SubtitleEdit.Core
return source.Replace("\r\r\n", "\n").Replace("\r\n", "\n").Replace('\r', '\n').Replace('\u2028', '\n').Split('\n');
}
public static int CountWords(this string source)
{
return HtmlUtil.RemoveHtmlTags(source, true).Split(new[] { ' ', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries).Length;
}
// http://www.codeproject.com/Articles/43726/Optimizing-string-operations-in-C
public static int FastIndexOf(this string source, string pattern)
{

View File

@ -179,7 +179,6 @@ https://github.com/SubtitleEdit/subtitleedit
foreach (string word in text.Split(ExpectedChars, StringSplitOptions.RemoveEmptyEntries))
{
var s = word.Trim();
_totalWords++;
if (s.Length > 1 && hashtable.ContainsKey(s))
{
hashtable[s]++;
@ -243,7 +242,10 @@ https://github.com/SubtitleEdit/subtitleedit
var hashtable = new Dictionary<string, int>();
foreach (Paragraph p in _subtitle.Paragraphs)
{
MostUsedWordsAdd(hashtable, p.Text);
_totalWords += p.Text.CountWords();
}
var sortedTable = new SortedDictionary<string, string>();
foreach (KeyValuePair<string, int> item in hashtable)