private static IEnumerable <string> GetElements(string switchBody)
        {
            const string caseString    = "case";
            const string breakString   = "break";
            const string defaultString = "default";

            var innerStructures    = new InnerStructures.InnerStructures();
            int?caseStartIndex     = null;
            int?caseBodyStartIndex = null;

            for (var i = 0; i < switchBody.Length; i++)
            {
                innerStructures.Handle(switchBody[i]);
                if (innerStructures.IsInsideSomeStructure)
                {
                    continue;
                }
                if (caseString.IsSubstring(switchBody, i) || defaultString.IsSubstring(switchBody, i))
                {
                    caseStartIndex = i;
                }
                if (":".IsSubstring(switchBody, i) && caseStartIndex != null)
                {
                    yield return(switchBody.Substring(caseStartIndex.Value, i - caseStartIndex.Value + 1).Trim());

                    caseStartIndex     = null;
                    caseBodyStartIndex = i + 1;
                }
                if (breakString.IsSubstring(switchBody, i))
                {
                    yield return(switchBody.Substring(caseBodyStartIndex.Value, i - caseBodyStartIndex.Value).Trim());

                    yield return("break;");

                    caseBodyStartIndex = null;
                }
            }
            if (caseBodyStartIndex.HasValue)
            {
                yield return(switchBody.SafeSubstring(caseBodyStartIndex.Value, switchBody.Length).Trim());
            }
            if (caseStartIndex.HasValue)
            {
                yield return(switchBody.SafeSubstring(caseStartIndex.Value, switchBody.Length).Trim());
            }
        }
        public static string[] SplitByComma(this string code)
        {
            var result = new List<string>();

            var currentVariable = new StringBuilder();
            var innerStructures = new InnerStructures.InnerStructures();
            foreach (var @char in code)
            {
                innerStructures.Handle(@char);
                if (@char != ',' || innerStructures.IsInsideSomeStructure)
                    currentVariable.Append(@char);
                else
                {
                    result.Add(currentVariable.ToString());
                    currentVariable.Clear();
                }
            }
            result.Add(currentVariable.ToString());
            
            return result.Select(s => s.Trim()).ToArray();
        }
 private static IEnumerable<string> GetElements(string switchBody)
 {
     const string caseString = "case";
     const string breakString = "break";
     const string defaultString = "default";
     
     var innerStructures = new InnerStructures.InnerStructures();
     int? caseStartIndex = null;
     int? caseBodyStartIndex = null;
     for (var i = 0; i < switchBody.Length; i++)
     {
         innerStructures.Handle(switchBody[i]);
         if (innerStructures.IsInsideSomeStructure)
             continue;
         if (caseString.IsSubstring(switchBody, i) || defaultString.IsSubstring(switchBody, i))
         {
             caseStartIndex = i;
         }
         if (":".IsSubstring(switchBody, i) && caseStartIndex != null)
         {
             yield return switchBody.Substring(caseStartIndex.Value, i - caseStartIndex.Value + 1).Trim();
             caseStartIndex = null;
             caseBodyStartIndex = i + 1;
         }
         if (breakString.IsSubstring(switchBody, i))
         {
             yield return switchBody.Substring(caseBodyStartIndex.Value, i - caseBodyStartIndex.Value).Trim();
             yield return "break;";
             caseBodyStartIndex = null;
         }
     }
     if (caseBodyStartIndex.HasValue)
         yield return switchBody.SafeSubstring(caseBodyStartIndex.Value, switchBody.Length).Trim();
     if (caseStartIndex.HasValue)
         yield return switchBody.SafeSubstring(caseStartIndex.Value, switchBody.Length).Trim();
 }
        public static string[] SplitByComma(this string code)
        {
            var result = new List <string>();

            var currentVariable = new StringBuilder();
            var innerStructures = new InnerStructures.InnerStructures();

            foreach (var @char in code)
            {
                innerStructures.Handle(@char);
                if (@char != ',' || innerStructures.IsInsideSomeStructure)
                {
                    currentVariable.Append(@char);
                }
                else
                {
                    result.Add(currentVariable.ToString());
                    currentVariable.Clear();
                }
            }
            result.Add(currentVariable.ToString());

            return(result.Select(s => s.Trim()).ToArray());
        }