Skip to content

Commit

Permalink
Update RefactorWindow.axaml.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
FixeQyt authored Aug 1, 2024
1 parent b159154 commit f178f76
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions SkEditor/Views/RefactorWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,36 @@ private static async Task RemoveComments()

private static string RemoveMultiLineComments(string text)
{
var CommentChar = "###";
var commentChar = "###";
int startIndex = 0;

while ((startIndex = text.IndexOf(CommentChar, startIndex)) != -1)
while ((startIndex = text.IndexOf(commentChar, startIndex)) != -1)
{
int endIndex = text.IndexOf(CommentChar, startIndex + CommentChar.Length);
int endIndex = text.IndexOf(commentChar, startIndex + commentChar.Length);
if (endIndex == -1) break;
endIndex += CommentChar.Length;
if (IsInsideQuotes(text, startIndex))
{
startIndex = endIndex + commentChar.Length;
continue;
}

endIndex += commentChar.Length;
text = text.Remove(startIndex, endIndex - startIndex);
}

return text;
}

private static bool IsInsideQuotes(string text, int index)
{
int quoteCount = 0;
for (int i = 0; i < index; i++)
{
if (text[i] == '"') quoteCount++;
}
return (quoteCount % 2 != 0);
}

private static string RemoveSingleLineComments(string text)
{
var lines = text.Split('\n');
Expand Down

0 comments on commit f178f76

Please sign in to comment.