more reliable & maintainable extension methods

This commit is contained in:
Licshee
2016-02-06 12:56:25 +08:00
parent 687f397ae3
commit 4a45d60c40
3 changed files with 6 additions and 4 deletions
+1 -1
View File
@@ -21,7 +21,7 @@ namespace Shadowsocks.Controller
string line;
while ((line = sr.ReadLine()) != null)
{
if (line == "" || line[0] == '#')
if (line.BeginWith('#'))
continue;
var pos = line.IndexOf('=');
@@ -30,6 +30,7 @@ namespace Shadowsocks.Controller
}
}
private static readonly IEnumerable<char> IgnoredLineBegins = new[] { '!', '[' };
private void http_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
try
@@ -44,7 +45,7 @@ namespace Shadowsocks.Controller
string rule;
while ((rule = sr.ReadLine()) != null)
{
if (rule == "" || rule[0] == '!' || rule[0] == '[')
if (rule.BeginWithAny(IgnoredLineBegins))
continue;
lines.Add(rule);
}
@@ -102,7 +103,7 @@ namespace Shadowsocks.Controller
string line;
while ((line = sr.ReadLine()) != null)
{
if (line == "" || line[0] == '!' || line[0] == '[')
if (line.BeginWithAny(IgnoredLineBegins))
continue;
valid_lines.Add(line);
}
@@ -442,6 +442,7 @@ namespace Shadowsocks.Controller
UpdatePACFromGFWListError(this, e);
}
private static readonly IEnumerable<char> IgnoredLineBegins = new[] { '!', '[' };
private void pacServer_UserRuleFileChanged(object sender, EventArgs e)
{
// TODO: this is a dirty hack. (from code GListUpdater.http_DownloadStringCompleted())
@@ -459,7 +460,7 @@ namespace Shadowsocks.Controller
string rule;
while ((rule = sr.ReadLine()) != null)
{
if (rule == "" || rule[0] == '!' || rule[0] == '[')
if (rule.BeginWithAny(IgnoredLineBegins))
continue;
lines.Add(rule);
}