mirror of
https://github.com/lampame/lampac-ukraine.git
synced 2026-04-16 17:32:20 +00:00
fix: Correct bracket depth calculation by ignoring characters within string literals.
This commit is contained in:
parent
5ef4e2896c
commit
e0d9bfac92
@ -418,12 +418,51 @@ namespace Makhno
|
|||||||
return null;
|
return null;
|
||||||
|
|
||||||
int depth = 0;
|
int depth = 0;
|
||||||
|
bool inString = false;
|
||||||
|
bool escape = false;
|
||||||
|
char quoteChar = '\0';
|
||||||
|
|
||||||
for (int i = startIndex; i < text.Length; i++)
|
for (int i = startIndex; i < text.Length; i++)
|
||||||
{
|
{
|
||||||
char ch = text[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 == '[')
|
if (ch == '[')
|
||||||
|
{
|
||||||
depth++;
|
depth++;
|
||||||
else if (ch == ']')
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ch == ']')
|
||||||
{
|
{
|
||||||
depth--;
|
depth--;
|
||||||
if (depth == 0)
|
if (depth == 0)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user