fix: Correct bracket depth calculation by ignoring characters within string literals.

This commit is contained in:
baliasnyifeliks 2026-02-03 20:11:25 +02:00
parent 5ef4e2896c
commit e0d9bfac92

View File

@ -418,12 +418,51 @@ namespace Makhno
return null;
int depth = 0;
bool inString = false;
bool escape = false;
char quoteChar = '\0';
for (int i = startIndex; i < text.Length; i++)
{
char ch = text[i];
if (inString)
{
if (escape)
{
escape = false;
continue;
}
if (ch == '\\')
{
escape = true;
continue;
}
if (ch == quoteChar)
{
inString = false;
quoteChar = '\0';
}
continue;
}
if (ch == '"' || ch == '\'')
{
inString = true;
quoteChar = ch;
continue;
}
if (ch == '[')
{
depth++;
else if (ch == ']')
continue;
}
if (ch == ']')
{
depth--;
if (depth == 0)