summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.UITest.TestCloud/Mono.Options/ArgumentSource.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.UITest.TestCloud/Mono.Options/ArgumentSource.cs')
-rw-r--r--Xamarin.Forms.UITest.TestCloud/Mono.Options/ArgumentSource.cs78
1 files changed, 78 insertions, 0 deletions
diff --git a/Xamarin.Forms.UITest.TestCloud/Mono.Options/ArgumentSource.cs b/Xamarin.Forms.UITest.TestCloud/Mono.Options/ArgumentSource.cs
new file mode 100644
index 00000000..da24d02b
--- /dev/null
+++ b/Xamarin.Forms.UITest.TestCloud/Mono.Options/ArgumentSource.cs
@@ -0,0 +1,78 @@
+using System.Collections.Generic;
+using System.IO;
+using System.Text;
+
+namespace Mono.Options
+{
+ public abstract class ArgumentSource
+ {
+ public abstract string Description { get; }
+
+ public abstract string[] GetNames();
+ public abstract bool GetArguments(string value, out IEnumerable<string> replacement);
+
+ public static IEnumerable<string> GetArgumentsFromFile(string file)
+ {
+ return GetArguments(File.OpenText(file), true);
+ }
+
+ public static IEnumerable<string> GetArguments(TextReader reader)
+ {
+ return GetArguments(reader, false);
+ }
+
+ // Cribbed from mcs/driver.cs:LoadArgs(string)
+ static IEnumerable<string> GetArguments(TextReader reader, bool close)
+ {
+ try
+ {
+ StringBuilder arg = new StringBuilder();
+
+ string line;
+ while ((line = reader.ReadLine()) != null)
+ {
+ int t = line.Length;
+
+ for (int i = 0; i < t; i++)
+ {
+ char c = line[i];
+
+ if (c == '"' || c == '\'')
+ {
+ char end = c;
+
+ for (i++; i < t; i++)
+ {
+ c = line[i];
+
+ if (c == end)
+ break;
+ arg.Append(c);
+ }
+ }
+ else if (c == ' ')
+ {
+ if (arg.Length > 0)
+ {
+ yield return arg.ToString();
+ arg.Length = 0;
+ }
+ }
+ else
+ arg.Append(c);
+ }
+ if (arg.Length > 0)
+ {
+ yield return arg.ToString();
+ arg.Length = 0;
+ }
+ }
+ }
+ finally
+ {
+ if (close)
+ reader.Close();
+ }
+ }
+ }
+} \ No newline at end of file