4
4
using System . Linq ;
5
5
using System . Text . RegularExpressions ;
6
6
using EncodingNormalior . Annotations ;
7
- using EncodingNormalior . Resource ;
8
7
9
8
namespace EncodingNormalior . Model
10
9
{
@@ -56,13 +55,13 @@ static InspectFileWhiteListSetting()
56
55
57
56
public InspectFileWhiteListSetting ( [ NotNull ] List < string > whiteList )
58
57
{
59
- foreach ( var temp in whiteList . Where ( temp=> ! string . IsNullOrEmpty ( temp ) ) )
58
+ foreach ( var temp in whiteList . Where ( temp => ! string . IsNullOrEmpty ( temp ) ) )
60
59
{
61
60
Parse ( temp ) ;
62
61
}
63
62
}
64
63
65
- private static Regex _folderRegex = new Regex ( "\\ w+[\\ \\ |/]" ) ;
64
+ private static readonly Regex FolderRegex = new Regex ( "\\ w+[\\ \\ |/]" ) ;
66
65
67
66
public static List < string > DefaultWhiteList { set ; get ; }
68
67
@@ -81,9 +80,9 @@ public static InspectFileWhiteListSetting ReadWhiteListSetting(string file)
81
80
{
82
81
throw new ArgumentException ( "文件不存在" + file ) ;
83
82
}
83
+
84
84
var whiteList = new List < string > ( ) ;
85
- using ( StreamReader stream = new StreamReader (
86
- new FileStream ( file , FileMode . Open ) ) )
85
+ using ( StreamReader stream = new StreamReader ( new FileStream ( file , FileMode . Open ) ) )
87
86
{
88
87
whiteList . AddRange ( stream . ReadToEnd ( ) . Split ( '\n ' ) . Select ( temp => temp . Replace ( "\r " , "" ) . Trim ( ) ) ) ;
89
88
}
@@ -97,15 +96,14 @@ private static IEnumerable<string> ReadWhiteList(string file)
97
96
string [ ] whiteList ;
98
97
if ( File . Exists ( file ) )
99
98
{
100
- using ( StreamReader stream = new StreamReader (
101
- new FileStream ( file , FileMode . Open ) ) )
99
+ using ( StreamReader stream = new StreamReader ( new FileStream ( file , FileMode . Open ) ) )
102
100
{
103
101
whiteList = stream . ReadToEnd ( ) . Split ( '\n ' ) ;
104
102
}
105
103
}
106
104
else
107
105
{
108
- whiteList = TextFileSuffix . WhiteList . Split ( '\n ' ) ;
106
+ whiteList = EncodingNormaliorContext . WhiteList . Split ( '\n ' ) ;
109
107
}
110
108
111
109
var fileSuffix = whiteList . Select ( temp => temp . Replace ( "\r " , "" ) . Trim ( ) ) ;
@@ -119,10 +117,10 @@ public void Add(string whiteList)
119
117
120
118
public void Remove ( string whiteList )
121
119
{
122
- var folderWhiteList = ( ( List < string > ) FolderWhiteList ) ;
120
+ var folderWhiteList = ( ( List < string > ) FolderWhiteList ) ;
123
121
124
122
Remove ( whiteList , folderWhiteList ) ;
125
- folderWhiteList = ( List < string > ) FileWhiteList ;
123
+ folderWhiteList = ( List < string > ) FileWhiteList ;
126
124
Remove ( whiteList , folderWhiteList ) ;
127
125
}
128
126
@@ -147,20 +145,19 @@ public void Add(List<string> whiteList)
147
145
148
146
private void Parse ( string whiteList )
149
147
{
150
- _folderRegex = new Regex ( "\\ w+[\\ \\ |/]$" ) ;
151
-
152
- if ( _folderRegex . IsMatch ( whiteList ) )
148
+ if ( FolderRegex . IsMatch ( whiteList ) )
153
149
{
154
- ( ( List < string > ) FolderWhiteList ) . Add ( whiteList . Substring ( 0 , whiteList . Length - 1 ) ) ;
150
+ ( ( List < string > ) FolderWhiteList ) . Add ( whiteList . Substring ( 0 , whiteList . Length - 1 ) ) ;
155
151
}
156
152
else
157
153
{
158
154
if ( whiteList . Contains ( "\\ " ) || whiteList . Contains ( "/" ) )
159
155
{
160
156
throw new ArgumentException ( "不支持指定文件夹中的文件\r \n " + whiteList + " 错误" ) ;
161
157
}
162
- ( ( List < string > ) FileWhiteList ) . Add ( whiteList ) ;
163
- ( ( List < Regex > ) FileRegexWhiteList ) . Add ( new Regex ( GetWildcardRegexString ( whiteList ) ,
158
+
159
+ ( ( List < string > ) FileWhiteList ) . Add ( whiteList ) ;
160
+ ( ( List < Regex > ) FileRegexWhiteList ) . Add ( new Regex ( GetWildcardRegexString ( whiteList ) ,
164
161
RegexOptions . IgnoreCase ) ) ;
165
162
}
166
163
}
@@ -182,6 +179,7 @@ public bool ConformWhiteList(string whiteList)
182
179
{
183
180
return false ;
184
181
}
182
+
185
183
return true ;
186
184
}
187
185
0 commit comments