@@ -12,64 +12,65 @@ namespace FastFind
1212 using System ;
1313 using System . Collections . Generic ;
1414 using System . Diagnostics ;
15+ using System . Globalization ;
1516 using System . IO ;
1617 using System . Text ;
1718 using System . Text . RegularExpressions ;
1819
1920 /// <summary>
2021 /// Implements the command line parsing for the Fast Find program.
2122 /// </summary>
22- internal class FastFindArgumentParser : ArgParser
23+ internal sealed class FastFindArgumentParser : ArgParser
2324 {
2425 /// <summary>
2526 /// The path flag.
2627 /// </summary>
27- private const string PathFlag = "path" ;
28+ private const String PathFlag = "path" ;
2829
2930 /// <summary>
3031 /// The path flag short.
3132 /// </summary>
32- private const string PathFlagShort = "p" ;
33+ private const String PathFlagShort = "p" ;
3334
3435 /// <summary>
3536 /// The use regular expressions flag.
3637 /// </summary>
37- private const string RegExFlag = "regex" ;
38+ private const String RegExFlag = "regex" ;
3839
3940 /// <summary>
4041 /// The short use regular expressions flag.
4142 /// </summary>
42- private const string RegExFlagShort = "re" ;
43+ private const String RegExFlagShort = "re" ;
4344
4445 /// <summary>
4546 /// The only files flag.
4647 /// </summary>
47- private const string IncludeDirectoryName = "includedir" ;
48+ private const String IncludeDirectoryName = "includedir" ;
4849
4950 /// <summary>
5051 /// The short only files flag short.
5152 /// </summary>
52- private const string IncludeDirectoryNameShort = "i" ;
53+ private const String IncludeDirectoryNameShort = "i" ;
5354
5455 /// <summary>
5556 /// The no statistics flag.
5657 /// </summary>
57- private const string NoStats = "nostats" ;
58+ private const String NoStats = "nostats" ;
5859
5960 /// <summary>
6061 /// The short no stats flag.
6162 /// </summary>
62- private const string NoStatsShort = "ns" ;
63+ private const String NoStatsShort = "ns" ;
6364
6465 /// <summary>
6566 /// The help flag.
6667 /// </summary>
67- private const string HelpFlag = "help" ;
68+ private const String HelpFlag = "help" ;
6869
6970 /// <summary>
7071 /// The short help flag.
7172 /// </summary>
72- private const string HelpFlagShort = "?" ;
73+ private const String HelpFlagShort = "?" ;
7374
7475 /// <summary>
7576 /// The raw patterns as they come in from the command line.
@@ -131,7 +132,7 @@ public FastFindArgumentParser()
131132 /// <param name="errorInfo">
132133 /// The string with the invalid command line option.
133134 /// </param>
134- public override void OnUsage ( string errorInfo )
135+ public override void OnUsage ( String errorInfo )
135136 {
136137 ProcessModule exe = Process . GetCurrentProcess ( ) . Modules [ 0 ] ;
137138 Console . WriteLine ( Constants . UsageString , exe . FileVersionInfo . FileVersion ) ;
@@ -159,32 +160,15 @@ public override void OnUsage(string errorInfo)
159160 /// <returns>
160161 /// One of the <see cref="ArgParser.SwitchStatus"/> values.
161162 /// </returns>
162- protected override SwitchStatus OnSwitch ( string switchSymbol , string switchValue )
163+ protected override SwitchStatus OnSwitch ( String switchSymbol , String switchValue )
163164 {
164165 SwitchStatus ss = SwitchStatus . NoError ;
165166
166167 switch ( switchSymbol )
167168 {
168169 case PathFlag :
169170 case PathFlagShort :
170- if ( false == String . IsNullOrEmpty ( this . Path ) )
171- {
172- this . errorMessage = Constants . PathMultipleSwitches ;
173- ss = SwitchStatus . Error ;
174- }
175- else
176- {
177- if ( Directory . Exists ( switchValue ) )
178- {
179- this . Path = switchValue ;
180- }
181- else
182- {
183- this . errorMessage = Constants . PathNotExist ;
184- ss = SwitchStatus . Error ;
185- }
186- }
187-
171+ ss = TestPath ( switchValue ) ;
188172 break ;
189173
190174 case RegExFlag :
@@ -225,7 +209,7 @@ protected override SwitchStatus OnSwitch(string switchSymbol, string switchValue
225209 /// <returns>
226210 /// One of the <see cref="ArgParser.SwitchStatus"/> values.
227211 /// </returns>
228- protected override SwitchStatus OnNonSwitch ( string value )
212+ protected override SwitchStatus OnNonSwitch ( String value )
229213 {
230214 // Just add this to the list of patterns to search for.
231215 this . rawPatterns . Add ( value ) ;
@@ -257,7 +241,7 @@ protected override SwitchStatus OnDoneParse()
257241 else
258242 {
259243 // Convert all the raw patterns into regular expressions.
260- for ( int i = 0 ; i < this . rawPatterns . Count ; i ++ )
244+ for ( Int32 i = 0 ; i < this . rawPatterns . Count ; i ++ )
261245 {
262246 String thePattern = this . rawPatterns [ i ] ;
263247 if ( false == this . useRegEx )
@@ -278,7 +262,10 @@ protected override SwitchStatus OnDoneParse()
278262 // when the user specified the -regex switch and they
279263 // used a DOS wildcard pattern like *..
280264 StringBuilder sb = new StringBuilder ( ) ;
281- sb . AppendFormat ( Constants . InvalidRegExFmt , thePattern , e . Message ) ;
265+ sb . AppendFormat ( CultureInfo . CurrentCulture ,
266+ Constants . InvalidRegExFmt ,
267+ thePattern ,
268+ e . Message ) ;
282269 this . errorMessage = sb . ToString ( ) ;
283270 ss = SwitchStatus . Error ;
284271 break ;
@@ -288,5 +275,39 @@ protected override SwitchStatus OnDoneParse()
288275
289276 return ss ;
290277 }
278+
279+ /// <summary>
280+ /// Isolates the checking for the path parameter.
281+ /// </summary>
282+ /// <param name="pathToTest">
283+ /// The path value to test.
284+ /// </param>
285+ /// <returns>
286+ /// A valid <see cref="SwitchStatus"/> value.
287+ /// </returns>
288+ private SwitchStatus TestPath ( String pathToTest )
289+ {
290+ SwitchStatus ss = SwitchStatus . Error ;
291+ if ( false == String . IsNullOrEmpty ( this . Path ) )
292+ {
293+ this . errorMessage = Constants . PathMultipleSwitches ;
294+ ss = SwitchStatus . Error ;
295+ }
296+ else
297+ {
298+ if ( Directory . Exists ( pathToTest ) )
299+ {
300+ this . Path = pathToTest ;
301+ }
302+ else
303+ {
304+ this . errorMessage = Constants . PathNotExist ;
305+ ss = SwitchStatus . Error ;
306+ }
307+ }
308+
309+ return ss ;
310+ }
311+
291312 }
292313}
0 commit comments