Program.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. using Quadarax.Foundation.QConsole.Configuration;
  6. using Quadarax.Foundation.QConsole.Context;
  7. namespace Quadarax.Foundation.QConsole.DevBench
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. //var input = "-c:\"fofo aa\" -new:12 -b:True";
  14. //var result = Split(input, "\"", new[] {" ", "-"});
  15. //Console.ReadLine();
  16. var config = new StartupConfiguration("MyTestConsole", Version.Parse("1.0.0"));
  17. config.AllowInteractive = false;
  18. config.WaitOnKeyInNonInteractiveMode = true;
  19. config.CommandDefinitionAssebmly = new Assembly[]{Assembly.GetEntryAssembly()};
  20. config.DisableDefaultCommands();
  21. config.ShowStatusOnEveryCommand = false;
  22. var console = new Engine(config, new DefualtEngineContext(), args);
  23. console.Start();
  24. Console.WriteLine("Press any key to exit (external wait)...");
  25. Console.ReadKey();
  26. }
  27. static string[] Split(string input, string valueBracket, string[] separators)
  28. {
  29. var result = new List<string>();
  30. var trimedInput = input.Trim();
  31. if (string.IsNullOrEmpty(trimedInput))
  32. return result.ToArray();
  33. var cValueBracked = valueBracket.ToCharArray().First();
  34. var cSeparators = separators.Select(x => x.ToCharArray().First());
  35. var nIndexStart = 0;
  36. var nIndexEnd = 0;
  37. var isInsideBracked = false;
  38. int offset = 0;
  39. for (offset = 0; offset < trimedInput.Length; offset++)
  40. {
  41. var current = trimedInput[offset];
  42. // current | isInside | Result
  43. // 1 1 0
  44. // 1 0 1
  45. // 0 1 1
  46. // 0 0 0
  47. isInsideBracked = current == cValueBracked ^ isInsideBracked;
  48. if (isInsideBracked)
  49. continue;
  50. if (cSeparators.Contains(current))
  51. {
  52. nIndexEnd = offset;
  53. result.Add(trimedInput.Substring(nIndexStart,nIndexEnd - nIndexStart));
  54. nIndexStart = nIndexEnd;
  55. isInsideBracked = false;
  56. }
  57. }
  58. if (offset>nIndexStart)
  59. result.Add(trimedInput.Substring(nIndexStart,offset - nIndexStart));
  60. return result.Where(x => !string.IsNullOrEmpty(x.Trim())).ToArray();
  61. }
  62. }
  63. }