Program.cs 2.5 KB

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