Program.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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.WaitOnKeyInNonInteractiveMode = true;
  18. config.CommandDefinitionAssebmly = new Assembly[]{Assembly.GetEntryAssembly()};
  19. config.DisableDefaultCommands();
  20. var console = new Engine(config, args);
  21. console.Start();
  22. Console.WriteLine("Press any key to exit (external wait)...");
  23. Console.ReadKey();
  24. }
  25. static string[] Split(string input, string valueBracket, string[] separators)
  26. {
  27. var result = new List<string>();
  28. var trimedInput = input.Trim();
  29. if (string.IsNullOrEmpty(trimedInput))
  30. return result.ToArray();
  31. var cValueBracked = valueBracket.ToCharArray().First();
  32. var cSeparators = separators.Select(x => x.ToCharArray().First());
  33. var nIndexStart = 0;
  34. var nIndexEnd = 0;
  35. var isInsideBracked = false;
  36. int offset = 0;
  37. for (offset = 0; offset < trimedInput.Length; offset++)
  38. {
  39. var current = trimedInput[offset];
  40. // current | isInside | Result
  41. // 1 1 0
  42. // 1 0 1
  43. // 0 1 1
  44. // 0 0 0
  45. isInsideBracked = current == cValueBracked ^ isInsideBracked;
  46. if (isInsideBracked)
  47. continue;
  48. if (cSeparators.Contains(current))
  49. {
  50. nIndexEnd = offset;
  51. result.Add(trimedInput.Substring(nIndexStart,nIndexEnd - nIndexStart));
  52. nIndexStart = nIndexEnd;
  53. isInsideBracked = false;
  54. }
  55. }
  56. if (offset>nIndexStart)
  57. result.Add(trimedInput.Substring(nIndexStart,offset - nIndexStart));
  58. return result.Where(x => !string.IsNullOrEmpty(x.Trim())).ToArray();
  59. }
  60. }
  61. }