22using System . Collections ;
33using System . Collections . Generic ;
44using System . Collections . ObjectModel ;
5+ using System . ComponentModel ;
56using System . Linq ;
67using System . Net . Sockets ;
78
@@ -11,44 +12,44 @@ namespace J4JSoftware.CommandLine
1112 // option key) used in the framework and ensures they are all used uniquely.
1213 public class MasterTextCollection
1314 {
14- public static MasterTextCollection GetWindowsDefault ( StringComparison ? comparison = null )
15+ public static MasterTextCollection GetDefault ( CommandLineStyle cmdLineStyle , StringComparison ? comparison = null )
1516 {
16- var retVal = new MasterTextCollection ( ) ;
17+ var retVal = new MasterTextCollection ( comparison ?? StringComparison . OrdinalIgnoreCase ) ;
1718
18- retVal . AddRange ( TextUsageType . Prefix , "/" , "-" , "--" ) ;
19- retVal . Add ( TextUsageType . Quote , "\" " ) ;
20- retVal . Add ( TextUsageType . ValueEncloser , "=" ) ;
19+ switch ( cmdLineStyle )
20+ {
21+ case CommandLineStyle . Linux :
22+ retVal . AddRange ( TextUsageType . Prefix , "-" , "--" ) ;
23+ retVal . AddRange ( TextUsageType . Quote , "\" " , "'" ) ;
24+ retVal . Add ( TextUsageType . ValueEncloser , "=" ) ;
2125
22- retVal . Initialize ( comparison . HasValue ? comparison . Value : StringComparison . OrdinalIgnoreCase ) ;
26+ break ;
2327
24- return retVal ;
25- }
28+ case CommandLineStyle . Universal :
29+ retVal . AddRange ( TextUsageType . Prefix , "-" , "--" , "/" ) ;
30+ retVal . AddRange ( TextUsageType . Quote , "\" " , "'" ) ;
31+ retVal . Add ( TextUsageType . ValueEncloser , "=" ) ;
2632
27- public static MasterTextCollection GetLinuxDefault ( StringComparison ? comparison = null )
28- {
29- var retVal = new MasterTextCollection ( ) ;
30-
31- retVal . AddRange ( TextUsageType . Prefix , "-" , "--" ) ;
32- retVal . AddRange ( TextUsageType . Quote , "\" " , "'" ) ;
33- retVal . Add ( TextUsageType . ValueEncloser , "=" ) ;
33+ break ;
34+
35+ case CommandLineStyle . Windows :
36+ retVal . AddRange ( TextUsageType . Prefix , "/" , "-" , "--" ) ;
37+ retVal . Add ( TextUsageType . Quote , "\" " ) ;
38+ retVal . Add ( TextUsageType . ValueEncloser , "=" ) ;
3439
35- retVal . Initialize ( comparison . HasValue ? comparison . Value : StringComparison . Ordinal ) ;
40+ break ;
41+ }
3642
3743 return retVal ;
3844 }
39-
45+
4046 private readonly List < TextUsage > _items = new List < TextUsage > ( ) ;
4147
42- public bool IsValid => TextComparer != null && TextComparison != null ;
43-
44- public StringComparison ? TextComparison { get ; private set ; }
45- public IEqualityComparer < string > ? TextComparer { get ; private set ; }
46-
47- public void Initialize ( StringComparison textComp )
48+ public MasterTextCollection ( StringComparison comparison )
4849 {
49- TextComparison = textComp ;
50+ TextComparison = comparison ;
5051
51- TextComparer = textComp switch
52+ TextComparer = comparison switch
5253 {
5354 StringComparison . CurrentCultureIgnoreCase => StringComparer . CurrentCultureIgnoreCase ,
5455 StringComparison . CurrentCulture => StringComparer . CurrentCulture ,
@@ -60,13 +61,16 @@ public void Initialize( StringComparison textComp )
6061 } ;
6162 }
6263
64+ public StringComparison TextComparison { get ; }
65+ public IEqualityComparer < string > TextComparer { get ; }
66+
6367 // indicates whether the supplied text exists in the collection
6468 public bool Contains ( string text )
65- => IsValid && _items . Any ( x => string . Equals ( x . Text , text , TextComparison ! . Value ) ) ;
69+ => _items . Any ( x => string . Equals ( x . Text , text , TextComparison ) ) ;
6670
6771 // indicates whether the supplied text exists in the collection for the specified usage
6872 public bool Contains ( string text , TextUsageType usage ) =>
69- IsValid && _items . Any ( x => x . Usage == usage && string . Equals ( x . Text , text , TextComparison ! . Value ) ) ;
73+ _items . Any ( x => x . Usage == usage && string . Equals ( x . Text , text , TextComparison ) ) ;
7074
7175 // adds an item to the collection
7276 public bool Add ( TextUsageType usage , string item )
0 commit comments