+10
-5
lines changedFilter options
+10
-5
lines changed Original file line number Diff line number Diff line change
@@ -9,6 +9,14 @@ internal static class WordCounter
9
9
{
10
10
private static readonly string[] ExcludeNodeXPaths = ["//title"];
11
11
12
+
#if NET8_0_OR_GREATER
13
+
private static readonly System.Buffers.SearchValues<char> SpecialChars = System.Buffers.SearchValues.Create(".?!;:,()[]");
14
+
#else
15
+
private static readonly string SpecialChars = ".?!;:,()[]";
16
+
#endif
17
+
18
+
private static readonly char[] DelimiterChars = [' ', '\t', '\n'];
19
+
12
20
public static long CountWord(string html)
13
21
{
14
22
ArgumentNullException.ThrowIfNull(html);
@@ -50,10 +58,7 @@ private static int CountWordInText(string text)
50
58
return 0;
51
59
}
52
60
53
-
string specialChars = ".?!;:,()[]";
54
-
char[] delimiterChars = [' ', '\t', '\n'];
55
-
56
-
string[] wordList = text.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);
57
-
return wordList.Count(s => !s.Trim().All(specialChars.Contains));
61
+
string[] wordList = text.Split(DelimiterChars, StringSplitOptions.RemoveEmptyEntries);
62
+
return wordList.Count(static s => !s.Trim().All(static c => SpecialChars.Contains(c)));
58
63
}
59
64
}
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4