size_t FunctionZoneParser::getBodyClosePos(size_t begin, const TCHAR *bodyOpenSymbol, const TCHAR *bodyCloseSymbol, const std::vector< std::pair<int, int> > & commentZones, ScintillaEditView **ppEditView) { size_t cntOpen = 1; int docLen = (*ppEditView)->getCurrentDocLen(); if (begin >= (size_t)docLen) return docLen; generic_string exprToSearch = TEXT("("); exprToSearch += bodyOpenSymbol; exprToSearch += TEXT("|"); exprToSearch += bodyCloseSymbol; exprToSearch += TEXT(")"); int flags = SCFIND_REGEXP | SCFIND_POSIX | SCFIND_REGEXP_DOTMATCHESNL; (*ppEditView)->execute(SCI_SETSEARCHFLAGS, flags); int targetStart = (*ppEditView)->searchInTarget(exprToSearch.c_str(), exprToSearch.length(), begin, docLen); int targetEnd = 0; do { if (targetStart != -1 && targetStart != -2) // found open or close symbol { targetEnd = int((*ppEditView)->execute(SCI_GETTARGETEND)); // Treat it only if it's NOT in the comment zone if (!isInZones(targetStart, commentZones)) { // Now we determinate the symbol (open or close) int tmpStart = (*ppEditView)->searchInTarget(bodyOpenSymbol, lstrlen(bodyOpenSymbol), targetStart, targetEnd); if (tmpStart != -1 && tmpStart != -2) // open symbol found { ++cntOpen; } else // if it's not open symbol, then it must be the close one { --cntOpen; } } } else // nothing found { cntOpen = 0; // get me out of here targetEnd = begin; } targetStart = (*ppEditView)->searchInTarget(exprToSearch.c_str(), exprToSearch.length(), targetEnd, docLen); } while (cntOpen); return targetEnd; }
void FunctionZoneParser::classParse(vector<foundInfo> & foundInfos, vector< pair<int, int> > &scannedZones, const std::vector< std::pair<int, int> > & commentZones, size_t begin, size_t end, ScintillaEditView **ppEditView, generic_string classStructName) { if (begin >= end) return; int flags = SCFIND_REGEXP | SCFIND_POSIX | SCFIND_REGEXP_DOTMATCHESNL; (*ppEditView)->execute(SCI_SETSEARCHFLAGS, flags); int targetStart = (*ppEditView)->searchInTarget(_rangeExpr.c_str(), _rangeExpr.length(), begin, end); int targetEnd = 0; while (targetStart != -1 && targetStart != -2) { targetEnd = int((*ppEditView)->execute(SCI_GETTARGETEND)); // Get class name int foundPos = 0; generic_string classStructName = parseSubLevel(targetStart, targetEnd, _classNameExprArray, foundPos, ppEditView); if (_openSymbole != TEXT("") && _closeSymbole != TEXT("")) { targetEnd = getBodyClosePos(targetEnd, _openSymbole.c_str(), _closeSymbole.c_str(), ppEditView); } if (targetEnd > int(end)) //we found a result but outside our range, therefore do not process it { break; } scannedZones.push_back(pair<int, int>(targetStart, targetEnd)); int foundTextLen = targetEnd - targetStart; if (targetStart + foundTextLen == int(end)) break; // Begin to search all method inside //vector< generic_string > emptyArray; if (!isInZones(targetStart, commentZones)) { funcParse(foundInfos, targetStart, targetEnd, ppEditView, classStructName); } begin = targetStart + (targetEnd - targetStart); targetStart = (*ppEditView)->searchInTarget(_rangeExpr.c_str(), _rangeExpr.length(), begin, end); } }
void FunctionParser::funcParse(std::vector<foundInfo> & foundInfos, size_t begin, size_t end, ScintillaEditView **ppEditView, generic_string classStructName, const std::vector< std::pair<int, int> > * commentZones) { if (begin >= end) return; if (_functionExpr.length() == 0) return; int flags = SCFIND_REGEXP | SCFIND_POSIX | SCFIND_REGEXP_DOTMATCHESNL; (*ppEditView)->execute(SCI_SETSEARCHFLAGS, flags); int targetStart = (*ppEditView)->searchInTarget(_functionExpr.c_str(), _functionExpr.length(), begin, end); int targetEnd = 0; //foundInfos.clear(); while (targetStart != -1 && targetStart != -2) { targetStart = int((*ppEditView)->execute(SCI_GETTARGETSTART)); targetEnd = int((*ppEditView)->execute(SCI_GETTARGETEND)); if (targetEnd > int(end)) //we found a result but outside our range, therefore do not process it { break; } int foundTextLen = targetEnd - targetStart; if (targetStart + foundTextLen == int(end)) break; foundInfo fi; // dataToSearch & data2ToSearch are optional if (!_functionNameExprArray.size() && !_classNameExprArray.size()) { TCHAR foundData[1024]; (*ppEditView)->getGenericText(foundData, 1024, targetStart, targetEnd); fi._data = foundData; // whole found data fi._pos = targetStart; } else { int foundPos; if (_functionNameExprArray.size()) { fi._data = parseSubLevel(targetStart, targetEnd, _functionNameExprArray, foundPos, ppEditView); fi._pos = foundPos; } if (classStructName != TEXT("")) { fi._data2 = classStructName; fi._pos2 = -1; // change -1 valeur for validated data2 } else if (_classNameExprArray.size()) { fi._data2 = parseSubLevel(targetStart, targetEnd, _classNameExprArray, foundPos, ppEditView); fi._pos2 = foundPos; } } if (fi._pos != -1 || fi._pos2 != -1) // at least one should be found { if (commentZones != NULL) { if (!isInZones(fi._pos, *commentZones) && !isInZones(fi._pos2, *commentZones)) foundInfos.push_back(fi); } else { foundInfos.push_back(fi); } } begin = targetStart + foundTextLen; targetStart = (*ppEditView)->searchInTarget(_functionExpr.c_str(), _functionExpr.length(), begin, end); } }