| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using Quadarax.Foundation.QConsole.Configuration;
- namespace Quadarax.Foundation.QConsole.DevBench
- {
- class Program
- {
- static void Main(string[] args)
- {
- //var input = "-c:\"fofo aa\" -new:12 -b:True";
- //var result = Split(input, "\"", new[] {" ", "-"});
- //Console.ReadLine();
- var config = new StartupConfiguration("MyTestConsole", Version.Parse("1.0.0")).EnableDebugMode();
- config.CommandDefinitionAssebmly = Assembly.GetEntryAssembly();
- var console = new Engine(config, args);
- console.Start();
- Console.WriteLine("Press any key to exit (external wait)...");
- Console.ReadKey();
- }
- static string[] Split(string input, string valueBracket, string[] separators)
- {
- var result = new List<string>();
- var trimedInput = input.Trim();
- if (string.IsNullOrEmpty(trimedInput))
- return result.ToArray();
- var cValueBracked = valueBracket.ToCharArray().First();
- var cSeparators = separators.Select(x => x.ToCharArray().First());
- var nIndexStart = 0;
- var nIndexEnd = 0;
- var isInsideBracked = false;
- int offset = 0;
- for (offset = 0; offset < trimedInput.Length; offset++)
- {
- var current = trimedInput[offset];
- // current | isInside | Result
- // 1 1 0
- // 1 0 1
- // 0 1 1
- // 0 0 0
- isInsideBracked = current == cValueBracked ^ isInsideBracked;
- if (isInsideBracked)
- continue;
- if (cSeparators.Contains(current))
- {
- nIndexEnd = offset;
- result.Add(trimedInput.Substring(nIndexStart,nIndexEnd - nIndexStart));
- nIndexStart = nIndexEnd;
- isInsideBracked = false;
- }
- }
- if (offset>nIndexStart)
- result.Add(trimedInput.Substring(nIndexStart,offset - nIndexStart));
- return result.Where(x => !string.IsNullOrEmpty(x.Trim())).ToArray();
- }
- }
- }
|