[netcore] Remove local copy of static alc resolve methods
[mono-project.git] / docs / HtmlAgilityPack / HtmlCmdLine.cs
blob1421765252f8cdca451dbd9e24f5b96754cab2aa
1 // HtmlAgilityPack V1.0 - Simon Mourier <simon underscore mourier at hotmail dot com>
2 using System;
4 namespace HtmlAgilityPack
6 internal class HtmlCmdLine
8 #region Static Members
10 internal static bool Help;
12 #endregion
14 #region Constructors
16 static HtmlCmdLine()
18 Help = false;
19 ParseArgs();
22 #endregion
24 #region Internal Methods
26 internal static string GetOption(string name, string def)
28 string p = def;
29 string[] args = Environment.GetCommandLineArgs();
30 for (int i = 1; i < args.Length; i++)
32 GetStringArg(args[i], name, ref p);
34 return p;
37 internal static string GetOption(int index, string def)
39 string p = def;
40 string[] args = Environment.GetCommandLineArgs();
41 int j = 0;
42 for (int i = 1; i < args.Length; i++)
44 if (GetStringArg(args[i], ref p))
46 if (index == j)
47 return p;
48 else
49 p = def;
50 j++;
53 return p;
56 internal static bool GetOption(string name, bool def)
58 bool p = def;
59 string[] args = Environment.GetCommandLineArgs();
60 for (int i = 1; i < args.Length; i++)
62 GetBoolArg(args[i], name, ref p);
64 return p;
67 internal static int GetOption(string name, int def)
69 int p = def;
70 string[] args = Environment.GetCommandLineArgs();
71 for (int i = 1; i < args.Length; i++)
73 GetIntArg(args[i], name, ref p);
75 return p;
78 #endregion
80 #region Private Methods
82 private static void GetBoolArg(string Arg, string Name, ref bool ArgValue)
84 if (Arg.Length < (Name.Length + 1)) // -name is 1 more than name
85 return;
86 if (('/' != Arg[0]) && ('-' != Arg[0])) // not a param
87 return;
88 if (Arg.Substring(1, Name.Length).ToLower() == Name.ToLower())
89 ArgValue = true;
92 private static void GetIntArg(string Arg, string Name, ref int ArgValue)
94 if (Arg.Length < (Name.Length + 3)) // -name:12 is 3 more than name
95 return;
96 if (('/' != Arg[0]) && ('-' != Arg[0])) // not a param
97 return;
98 if (Arg.Substring(1, Name.Length).ToLower() == Name.ToLower())
102 ArgValue = Convert.ToInt32(Arg.Substring(Name.Length + 2, Arg.Length - Name.Length - 2));
104 catch
110 private static bool GetStringArg(string Arg, ref string ArgValue)
112 if (('/' == Arg[0]) || ('-' == Arg[0]))
113 return false;
114 ArgValue = Arg;
115 return true;
118 private static void GetStringArg(string Arg, string Name, ref string ArgValue)
120 if (Arg.Length < (Name.Length + 3)) // -name:x is 3 more than name
121 return;
122 if (('/' != Arg[0]) && ('-' != Arg[0])) // not a param
123 return;
124 if (Arg.Substring(1, Name.Length).ToLower() == Name.ToLower())
125 ArgValue = Arg.Substring(Name.Length + 2, Arg.Length - Name.Length - 2);
128 private static void ParseArgs()
130 string[] args = Environment.GetCommandLineArgs();
131 for (int i = 1; i < args.Length; i++)
133 // help
134 GetBoolArg(args[i], "?", ref Help);
135 GetBoolArg(args[i], "h", ref Help);
136 GetBoolArg(args[i], "help", ref Help);
140 #endregion