1 // /home/jeremie/TaoParser/NGenerator/CommandLine.cs
2 // Writtent by jeremie at 21:43 03/06/2007
4 // This file is licensed under the LGPL licence as described in the COPYING file
7 using System
.Collections
.Generic
;
11 public class CommandLine
14 IDictionary
<string, string> options
;
15 //protected Option[] options;
17 char argSeparator
= ':';
21 public CommandLine(string[] argLine
)
24 throw new ArgumentNullException("argLine");
26 args
= new string[argLine
.Length
];
27 argLine
.CopyTo(args
, 0);
30 public CommandLine(string[] argLine
, char argument
, char separator
) :
33 argSeparator
= separator
;
37 /*public Option[] Options {
46 public string[] Names
{
50 string[] namesTemp
= new string[names
.Length
];
51 Array
.Copy(names
, namesTemp
, names
.Length
);
56 public bool IsDefined(string option
)
60 return options
.ContainsKey(option
);
63 public string this[string key
] {
66 options
.TryGetValue(key
, out output
);
71 protected void ParseOptions()
76 options
= new Dictionary
<string, string>();
80 foreach (string s
in args
) {
83 int indexOfSeparator
= s
.IndexOf(argSeparator
);
85 // Determine the option name be it with a value or a switch
86 string optionName
= (indexOfSeparator
!= -1) ?
87 s
.Substring(1, (indexOfSeparator
- 1)) : s
.Substring(1);
89 // Retrieve the associated parameter value if any
90 string optionValue
= (indexOfSeparator
!= -1) ?
91 s
.Substring(indexOfSeparator
+ 1) : null;
93 options
.Add(optionName
, optionValue
);
100 nameIndex
= index
+ 1;
103 protected void ParseNames()
105 ICollection
<string> temp
= new List
<string>();
108 for (int i
= nameIndex
; i
< args
.Length
; i
++)
111 foreach (string s
in args
)
115 if (temp
.Count
!= 0) {
116 names
= new string[temp
.Count
];
117 temp
.CopyTo(names
, 0);