[ENHANCE] Make Tag attributes highlight work correctly.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@272 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
donho 2008-07-03 10:48:00 +00:00
parent bd1e9eb82c
commit d28414d7c4

View File

@ -2604,33 +2604,90 @@ vector< pair<int, int> > Notepad_plus::getAttributesPos(int start, int end)
char *buf = new char[bufLen+1]; char *buf = new char[bufLen+1];
_pEditView->getText(buf, start, end); _pEditView->getText(buf, start, end);
int i = 0; enum {\
attr_invalid,\
attr_key,\
attr_pre_assign,\
attr_assign,\
attr_string,\
attr_value,\
attr_valid\
} state = attr_invalid;
int startPos = -1; int startPos = -1;
int oneMoreChar = 1;
int i = 0;
for (; i < bufLen ; i++) for (; i < bufLen ; i++)
{ {
if (buf[i] == ' ' || buf[i] == '\t') switch (buf[i])
{ {
if (startPos != -1) case ' ':
case '\t':
case '\n':
case '\r':
{ {
attributes.push_back(pair<int, int>(start+startPos, start+i)); if (state == attr_key)
startPos = -1; state = attr_pre_assign;
else if (state == attr_value)
{
state = attr_valid;
oneMoreChar = 0;
} }
} }
else break;
case '=':
{ {
if (startPos == -1) if (state == attr_key || state == attr_pre_assign)
state = attr_assign;
else if (state == attr_assign || state == attr_value)
state = attr_invalid;
}
break;
case '"':
{ {
if (state == attr_string)
{
state = attr_valid;
oneMoreChar = 1;
}
else if (state == attr_key || state == attr_pre_assign || state == attr_value)
state = attr_invalid;
else if (state == attr_assign)
state = attr_string;
}
break;
default:
{
if (state == attr_invalid)
{
state = attr_key;
startPos = i; startPos = i;
} }
else if (state == attr_pre_assign)
state = attr_invalid;
else if (state == attr_assign)
state = attr_value;
} }
} }
if (startPos != -1)
if (state == attr_valid)
{
attributes.push_back(pair<int, int>(start+startPos, start+i+oneMoreChar));
state = attr_invalid;
}
}
if (state == attr_value)
attributes.push_back(pair<int, int>(start+startPos, start+i-1)); attributes.push_back(pair<int, int>(start+startPos, start+i-1));
delete [] buf; delete [] buf;
return attributes; return attributes;
} }
void Notepad_plus::tagMatch() void Notepad_plus::tagMatch()
{ {
const NppGUI & nppGUI = (NppParameters::getInstance())->getNppGUI(); const NppGUI & nppGUI = (NppParameters::getInstance())->getNppGUI();