git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@279 f5eea248-9336-0410-98b8-ebc06183d4e3

This commit is contained in:
donho 2008-07-08 17:49:30 +00:00
parent 1338ac4fe5
commit 722416bcc4
2 changed files with 79 additions and 40 deletions

View File

@ -2365,6 +2365,7 @@ BOOL Notepad_plus::notify(SCNotification *notification)
} }
return FALSE; return FALSE;
} }
void Notepad_plus::findMatchingBracePos(int & braceAtCaret, int & braceOpposite) void Notepad_plus::findMatchingBracePos(int & braceAtCaret, int & braceOpposite)
{ {
int caretPos = int(_pEditView->execute(SCI_GETCURRENTPOS)); int caretPos = int(_pEditView->execute(SCI_GETCURRENTPOS));
@ -2482,8 +2483,14 @@ TagCateg Notepad_plus::getTagCategory(XmlMatchedTagsPos & tagsPos, int curPos)
return outOfTag; return outOfTag;
} }
bool Notepad_plus::getMatchedTagPos(int searchStart, int searchEnd, const char *tag2find, const char *oppositeTag2find, XmlMatchedTagsPos & tagsPos) bool Notepad_plus::getMatchedTagPos(int searchStart, int searchEnd, const char *tag2find, const char *oppositeTag2find, vector<int> oppositeTagFound, XmlMatchedTagsPos & tagsPos)
{ {
/*
char func[256];
sprintf(func, "getMatchedTagPos(%d, %d)", searchStart, searchEnd);
writeLog("c:\\npplog", func);
*/
const bool search2Left = false; const bool search2Left = false;
const bool search2Right = true; const bool search2Right = true;
@ -2494,36 +2501,82 @@ bool Notepad_plus::getMatchedTagPos(int searchStart, int searchEnd, const char *
if (ltPosOnR == -1) if (ltPosOnR == -1)
return false; return false;
if ((direction == search2Left) && (getTagCategory(tagsPos, ltPosOnR+2) != tagOpen))
return false;
pair<int, int> oppositeTagPos; pair<int, int> oppositeTagPos;
int s = foundPos.first; int s = foundPos.first;
int e = tagsPos.tagOpenEnd; int e = tagsPos.tagOpenEnd;
if (direction == search2Left) if (direction == search2Left)
{ {
s = foundPos.second;
e = tagsPos.tagCloseStart;
} }
int openLtPosOnR = getFirstTokenPosFrom(s, e, oppositeTag2find, oppositeTagPos); int ltTag = getFirstTokenPosFrom(s, e, oppositeTag2find, oppositeTagPos);
if (openLtPosOnR == -1) if (ltTag == -1)
{ {
tagsPos.tagCloseStart = foundPos.first;
tagsPos.tagCloseEnd = foundPos.second;
if (direction == search2Left) if (direction == search2Left)
{ {
tagsPos.tagOpenStart = foundPos.first;
tagsPos.tagOpenEnd = foundPos.second;
//tagsPos.tagNameEnd = ltTag + 1 + (endPos - startPos);
}
else
{
tagsPos.tagCloseStart = foundPos.first;
tagsPos.tagCloseEnd = foundPos.second;
} }
return true; return true;
} }
else if (isInList(ltTag, oppositeTagFound))
{
while (true)
{
ltTag = getFirstTokenPosFrom(ltTag, e, oppositeTag2find, oppositeTagPos);
if (ltTag == -1)
{
if (direction == search2Left)
{
tagsPos.tagOpenStart = foundPos.first;
tagsPos.tagOpenEnd = foundPos.second;
}
else
{
tagsPos.tagCloseStart = foundPos.first;
tagsPos.tagCloseEnd = foundPos.second;
}
return true;
}
else if (!isInList(ltTag, oppositeTagFound))
{
oppositeTagFound.push_back(ltTag);
break;
}
// else do nothing
}
}
else
{
oppositeTagFound.push_back(ltTag);
}
int start = foundPos.second; int start, end;
int end = searchEnd;
if (direction == search2Left) if (direction == search2Left)
{ {
start = foundPos.first;
end = searchEnd;
} }
return getMatchedTagPos(start, end, tag2find, oppositeTag2find, tagsPos); else
{
start = foundPos.second;
end = searchEnd;
}
return getMatchedTagPos(start, end, tag2find, oppositeTag2find, oppositeTagFound, tagsPos);
} }
@ -2563,7 +2616,8 @@ bool Notepad_plus::getXmlMatchedTagsPos(XmlMatchedTagsPos & tagsPos)
delete [] tagName; delete [] tagName;
return getMatchedTagPos(tagsPos.tagOpenEnd, docLen, closeTag.c_str(), openTag.c_str(), tagsPos); vector<int> passedTagList;
return getMatchedTagPos(tagsPos.tagOpenEnd, docLen, closeTag.c_str(), openTag.c_str(), passedTagList, tagsPos);
} }
case tagClose : // if tagClose search left case tagClose : // if tagClose search left
@ -2578,7 +2632,6 @@ bool Notepad_plus::getXmlMatchedTagsPos(XmlMatchedTagsPos & tagsPos)
string openTag = "<"; string openTag = "<";
openTag += tagName; openTag += tagName;
//openTag += "[ >]";
string closeTag = "</"; string closeTag = "</";
closeTag += tagName; closeTag += tagName;
@ -2586,32 +2639,12 @@ bool Notepad_plus::getXmlMatchedTagsPos(XmlMatchedTagsPos & tagsPos)
delete [] tagName; delete [] tagName;
int startOpen = tagsPos.tagCloseStart; vector<int> passedTagList;
bool isFirstTime = true; bool isFound = getMatchedTagPos(tagsPos.tagCloseStart, 0, openTag.c_str(), closeTag.c_str(), passedTagList, tagsPos);
int posBeginSearch; if (isFound)
tagsPos.tagNameEnd = tagsPos.tagOpenStart + 1 + (endPos - startPos);
pair<int, int> foundPos; return isFound;
while (true)
{
int ltPosOnL = getFirstTokenPosFrom(startOpen, 0, openTag.c_str(), foundPos);
if (ltPosOnL == -1)
return false;
if (getTagCategory(tagsPos, ltPosOnL+2) != tagOpen)
return false;
pair<int, int> tmpPos;
int closeLtPosOnL = getFirstTokenPosFrom(isFirstTime?foundPos.second:posBeginSearch, tagsPos.tagCloseStart, closeTag.c_str(), tmpPos);
isFirstTime = false;
if (closeLtPosOnL == -1)
{
tagsPos.tagNameEnd = ltPosOnL + 1 + (endPos - startPos);
return true;
}
startOpen = foundPos.first;
posBeginSearch = tmpPos.second;
}
return false;
} }
case inSingleTag : // if in single tag case inSingleTag : // if in single tag

View File

@ -677,9 +677,15 @@ private:
int getFirstTokenPosFrom(int targetStart, int targetEnd, const char *token, pair<int, int> & foundPos); int getFirstTokenPosFrom(int targetStart, int targetEnd, const char *token, pair<int, int> & foundPos);
TagCateg getTagCategory(XmlMatchedTagsPos & tagsPos, int curPos); TagCateg getTagCategory(XmlMatchedTagsPos & tagsPos, int curPos);
bool getMatchedTagPos(int searchStart, int searchEnd, const char *tag2find, const char *oppositeTag2find, XmlMatchedTagsPos & tagsPos); bool getMatchedTagPos(int searchStart, int searchEnd, const char *tag2find, const char *oppositeTag2find, vector<int> oppositeTagFound, XmlMatchedTagsPos & tagsPos);
bool getXmlMatchedTagsPos(XmlMatchedTagsPos & tagsPos); bool getXmlMatchedTagsPos(XmlMatchedTagsPos & tagsPos);
vector< pair<int, int> > getAttributesPos(int start, int end); vector< pair<int, int> > getAttributesPos(int start, int end);
bool isInList(int element, vector<int> elementList) {
for (size_t i = 0 ; i < elementList.size() ; i++)
if (element == elementList[i])
return true;
return false;
};
void tagMatch(); void tagMatch();
void activateNextDoc(bool direction); void activateNextDoc(bool direction);