private void AddCurveBrackets() { int start = 0; for (int i = 0; i < lines.Length; i++) { Word[] words = Split.SeparateLine(Line.TrimmedLine(lines[i])); if (Word.IsBlock(words)) { if (IsSingleLineBlock(i)) { _AddCurveBrackets(ref i, ref start); } } else { Word first; try { first = Word.FirstNotEmptyWord(words); } catch (ArgumentOutOfRangeException) { continue; } if (first.Text == Data.ELSE.Text && Line.TrimmedLine(lines[i + 1]) != "{") { _AddCurveBrackets(ref i, ref start); } } } }
private void _AddCurveBrackets(ref int i, ref int start) { string offset = Line.GetOffset(lines[i]); string[] parts = new string[3]; parts[0] = lines[i]; parts[1] = offset + "{"; i++; start = i; parts[2] = offset + "\t" + Line.TrimmedLine(lines[i]); Split.Remove(ref lines, i); Split.InsertInsteadOf(i - 1, ref lines, parts); i++; int IF_Without_ELSE = 0; Word[] words = Split.SeparateLine(Line.TrimmedLine(lines[i])); while (Word.IsBlock(words)) { if (Word.FirstNotEmptyWord(words).Text == Data.IF.Text) { IF_Without_ELSE++; } if (IsSingleLineBlock(i)) { i++; } else { i = Brackets.GetCloseCurveBracketIndex(lines, i + 1); } words = Split.SeparateLine(Line.TrimmedLine(lines[i])); } bool wasSingleLine_ELSE = false; for (; IF_Without_ELSE > 0; IF_Without_ELSE--) { if (Line.TrimmedLine(lines[i + 1]) == Data.ELSE.Text) { if (IsSingleLineBlock(i)) { i++; wasSingleLine_ELSE = true; } else { i = Brackets.GetCloseCurveBracketIndex(lines, i + 1); wasSingleLine_ELSE = false; } } } if (wasSingleLine_ELSE) { i++; } parts[0] = lines[i]; parts[1] = offset + "}"; parts[2] = lines[i + 1]; Split.Remove(ref lines, i + 1); Split.InsertInsteadOf(i, ref lines, parts); i = start; }
private void CASE_ToSingleLine() { for (int i = 0; i < lines.Length; i++) { Word[] words = Split.SeparateLine(lines[i]); Word.TrimWords(ref words); if (words.Length == 0) { continue; } int nested_SWITCH = 0; bool wasNestedSwitch = false; if (Line.TrimmedLine(Word.FirstNotEmptyWord(words).Text) == Data.SWITCH.Text) { i++; int SWITCH_End = Brackets.GetCloseCurveBracketIndex(lines, i); for (int j = i + 1; j < SWITCH_End; j++) { words = Split.SeparateLine(lines[j]); string firstWord; try { firstWord = Line.TrimmedLine(Word.FirstNotEmptyWord(words).Text); } catch (Exception) { continue; } if (firstWord == Data.CASE.Text) { if (Word.IndexOfFirst(words, Data.CASE) == words.Length - 1) { CombineLines(ref j); break; } else { Split_CASE_Or_DEFAULT(words, j); } } else if (firstWord == Data.DEFAULT.Text) { if (Word.IndexOfFirst(words, Data.DEFAULT) == words.Length - 1) { CombineLines(ref j); break; } else { Split_CASE_Or_DEFAULT(words, j); } } else if (firstWord == Data.DEFAULT_WithColon.Text) { if (Word.IndexOfFirst(words, Data.DEFAULT_WithColon) == words.Length - 1) { CombineLines(ref j); break; } else { Split_CASE_Or_DEFAULT(words, j); } } else if ((firstWord == Data.SWITCH.Text || firstWord.Contains(Data.SWITCH_WithBracket.Text)) && !wasNestedSwitch) { nested_SWITCH = j; wasNestedSwitch = true; } } i = SWITCH_End; if (wasNestedSwitch) { i = nested_SWITCH; } } } }