From 722416bcc44da58f2da699f766595e80a9fab2c1 Mon Sep 17 00:00:00 2001 From: donho Date: Tue, 8 Jul 2008 17:49:30 +0000 Subject: [PATCH] git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@279 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/src/Notepad_plus.cpp | 111 ++++++++++++++++++++----------- PowerEditor/src/Notepad_plus.h | 8 ++- 2 files changed, 79 insertions(+), 40 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 63357e258..a3f9af695 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -2365,6 +2365,7 @@ BOOL Notepad_plus::notify(SCNotification *notification) } return FALSE; } + void Notepad_plus::findMatchingBracePos(int & braceAtCaret, int & braceOpposite) { int caretPos = int(_pEditView->execute(SCI_GETCURRENTPOS)); @@ -2482,8 +2483,14 @@ TagCateg Notepad_plus::getTagCategory(XmlMatchedTagsPos & tagsPos, int curPos) 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 oppositeTagFound, XmlMatchedTagsPos & tagsPos) { +/* + char func[256]; + + sprintf(func, "getMatchedTagPos(%d, %d)", searchStart, searchEnd); + writeLog("c:\\npplog", func); +*/ const bool search2Left = false; const bool search2Right = true; @@ -2494,36 +2501,82 @@ bool Notepad_plus::getMatchedTagPos(int searchStart, int searchEnd, const char * if (ltPosOnR == -1) return false; + if ((direction == search2Left) && (getTagCategory(tagsPos, ltPosOnR+2) != tagOpen)) + return false; + pair oppositeTagPos; int s = foundPos.first; int e = tagsPos.tagOpenEnd; 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) { - + 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; } + 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 end = searchEnd; - + int start, end; if (direction == search2Left) { - + start = foundPos.first; + end = searchEnd; + } + else + { + start = foundPos.second; + end = searchEnd; } - return getMatchedTagPos(start, end, tag2find, oppositeTag2find, tagsPos); + + return getMatchedTagPos(start, end, tag2find, oppositeTag2find, oppositeTagFound, tagsPos); } @@ -2563,7 +2616,8 @@ bool Notepad_plus::getXmlMatchedTagsPos(XmlMatchedTagsPos & tagsPos) delete [] tagName; - return getMatchedTagPos(tagsPos.tagOpenEnd, docLen, closeTag.c_str(), openTag.c_str(), tagsPos); + vector passedTagList; + return getMatchedTagPos(tagsPos.tagOpenEnd, docLen, closeTag.c_str(), openTag.c_str(), passedTagList, tagsPos); } case tagClose : // if tagClose search left @@ -2578,7 +2632,6 @@ bool Notepad_plus::getXmlMatchedTagsPos(XmlMatchedTagsPos & tagsPos) string openTag = "<"; openTag += tagName; - //openTag += "[ >]"; string closeTag = " foundPos; - while (true) - { - int ltPosOnL = getFirstTokenPosFrom(startOpen, 0, openTag.c_str(), foundPos); - if (ltPosOnL == -1) - return false; - - if (getTagCategory(tagsPos, ltPosOnL+2) != tagOpen) - return false; + vector passedTagList; + bool isFound = getMatchedTagPos(tagsPos.tagCloseStart, 0, openTag.c_str(), closeTag.c_str(), passedTagList, tagsPos); + if (isFound) + tagsPos.tagNameEnd = tagsPos.tagOpenStart + 1 + (endPos - startPos); - pair 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; + return isFound; } case inSingleTag : // if in single tag diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index bd75b5aa8..651f3820f 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -677,9 +677,15 @@ private: int getFirstTokenPosFrom(int targetStart, int targetEnd, const char *token, pair & foundPos); 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 oppositeTagFound, XmlMatchedTagsPos & tagsPos); bool getXmlMatchedTagsPos(XmlMatchedTagsPos & tagsPos); vector< pair > getAttributesPos(int start, int end); + bool isInList(int element, vector elementList) { + for (size_t i = 0 ; i < elementList.size() ; i++) + if (element == elementList[i]) + return true; + return false; + }; void tagMatch(); void activateNextDoc(bool direction);