diff --git a/Sources/Highlight/Highlight.cpp b/Sources/Highlight/Highlight.cpp index ef52e7b..90c4cd0 100644 --- a/Sources/Highlight/Highlight.cpp +++ b/Sources/Highlight/Highlight.cpp @@ -175,7 +175,12 @@ void Highlight::Display(void) } -void Highlight::Parse(int32_t start, int32_t stop, std::vector &metaData, int32_t &addingPos, EdnVectorBuf &buffer, int32_t elementID) +void Highlight::Parse(int32_t start, + int32_t stop, + std::vector &metaData, + int32_t &addingPos, + EdnVectorBuf &buffer, + int32_t elementID) { if (0 > addingPos) { addingPos = 0; @@ -259,7 +264,11 @@ void Highlight::Parse(int32_t start, int32_t stop, std::vector &metaData, EdnVectorBuf &buffer, int32_t elementID) +void Highlight::Parse2(int32_t start, + int32_t stop, + std::vector &metaData, + EdnVectorBuf &buffer, + int32_t elementID) { if (elementID >= (int32_t)m_listHighlightPass2.size() ){ return; @@ -288,3 +297,92 @@ void Highlight::Parse2(int32_t start, int32_t stop, std::vector &metaData, + int32_t &addingPos, + EdnVectorBuf &buffer, + int32_t elementID) +{ + if (0 > addingPos) { + addingPos = 0; + } + /*int32_t emptyId = -1; + for (i=0; i< (int32_t)metaData.size(); i++) { + + }*/ + //EDN_DEBUG("Parse element " << elementID << " / " << m_listHighlightPass1.size() << " ==> position search: (" << start << "," << stop << ")" ); + if (elementID >= (int32_t)m_listHighlightPass1.size() ){ + //EDN_DEBUG("Return at " << elementID << " / " << m_listHighlightPass1.size() ); + return; + } + int32_t elementStart = start; + int32_t elementStop = stop; + resultFind_te ret = HLP_FIND_OK; + colorInformation_ts resultat; + while (HLP_FIND_ERROR != ret && elementStartFind(elementStart, elementStop, resultat, buffer); + if (HLP_FIND_ERROR != ret) { + //EDN_INFO("Find Pattern in the Buffer : (" << resultat.beginStart << "," << resultat.endStop << ")" ); + // Add curent element in the list ... + if (HLP_FIND_OK_NO_END == ret) { + // find if we have a next element with th save Pointer and not higher the this one + int32_t findNextElement = -1; + int32_t i; + int32_t curentLevel = ((HighlightPattern*)resultat.patern)->GetLevel(); + for (i=addingPos; i< (int32_t)metaData.size(); i++) { + if (curentLevel > ((HighlightPattern*)metaData[i].patern)->GetLevel() ) { + //EDN_DEBUG(" -> Find upper element at "<< i ); + break; + } else if (curentLevel < ((HighlightPattern*)metaData[i].patern)->GetLevel() ) { + findNextElement = i; + //EDN_DEBUG(" -> Find under element at "<< i ); + } + if (metaData[i].patern == resultat.patern) + { + findNextElement = i; + //EDN_DEBUG(" -> Find a same element at "<< i ); + break; + } + } + + if (-1 != findNextElement) { + // if not find a end, we need to search the end of this one and parse all data inside... + int32_t newEnd = buffer.Size(); + if (findNextElement >= (int32_t)metaData.size()-1) { + // Remove old element : + //EDN_DEBUG(" --> Remove : " << addingPos << "==>" << (int32_t)metaData.size() << " (end)" ); + metaData.erase(metaData.begin()+addingPos,metaData.end()); + } else { + // Remove old element : + //EDN_DEBUG(" --> Remove : " << addingPos << "==>" << findNextElement+1 ); + metaData.erase(metaData.begin()+addingPos,metaData.begin()+findNextElement+1); + newEnd = metaData[addingPos].beginStart-1; + } + // Regenerate a local parsing : in a higher range of text + Parse(elementStart, edn_max(newEnd, stop), metaData, addingPos, buffer, elementID); + // Break the curent process, beacause we reparse the data in all range... + return; + } else { + //EDN_DEBUG(" --> No element removed " ); + metaData.insert(metaData.begin() + addingPos, resultat); + //EDN_DEBUG("INSERT at "<< addingPos << " S=" << resultat.beginStart << " E=" << resultat.endStop ); + } + } else { + metaData.insert(metaData.begin() + addingPos, resultat); + //EDN_DEBUG("INSERT at "<< addingPos << " S=" << resultat.beginStart << " E=" << resultat.endStop ); + } + // parse the under element : + Parse(elementStart, resultat.beginStart-1, metaData, addingPos, buffer, elementID+1); + addingPos++; + elementStart = resultat.endStop; + } + } + // parse the under element : + Parse(elementStart, elementStop, metaData, addingPos, buffer, elementID+1); +} \ No newline at end of file diff --git a/Sources/Highlight/HighlightPattern.cpp b/Sources/Highlight/HighlightPattern.cpp index 0bfe163..b7ab676 100644 --- a/Sources/Highlight/HighlightPattern.cpp +++ b/Sources/Highlight/HighlightPattern.cpp @@ -230,3 +230,55 @@ resultFind_te HighlightPattern::Find(int32_t start, int32_t stop, colorInformati } return HLP_FIND_ERROR; } +/** + * @brief Find Element only in the specify start characters and find the end with the range done + * + * @param[in] start First character to search data (if recognise it start here) + * @param[in] stop End of the possibility whe search can continue + * @param[out] resultat Position where find data + * @param[in] buffer : Where to search data + * + * @return HLP_FIND_OK We find a compleate pattern + * @return HLP_FIND_OK_NO_END Xe find a partial pattern (missing end) + * @return HLP_FIND_ERROR Not find the pattern + */ +resultFind_te HighlightPattern::FindOneElement(int32_t start, int32_t stop, colorInformation_ts &resultat, EdnVectorBuf &buffer) +{ + //EDN_DEBUG(" try to find the element"); + resultat.beginStart = -1; + resultat.beginStop = -1; + resultat.endStart = -1; + resultat.endStop = -1; + resultat.notEnded = false; + resultat.patern = this; + + // when we have only one element : + if (false == m_haveStopPatern) { + if (true == m_regExpStart->ProcessOneElement(buffer, start, stop)) { + resultat.beginStart = m_regExpStart->Start(); + resultat.beginStop = m_regExpStart->Stop(); + resultat.endStart = m_regExpStart->Start(); + resultat.endStop = m_regExpStart->Stop(); + return HLP_FIND_OK; + } + //EDN_DEBUG("NOT find hightlightpatern ..."); + } else { + // try while we find the first element + if (true == m_regExpStart->ProcessOneElement(buffer, start, stop, m_escapeChar)) { + resultat.beginStart = m_regExpStart->Start(); + resultat.beginStop = m_regExpStart->Stop(); + if (true == m_regExpStop->Process(buffer, resultat.beginStop, stop, m_escapeChar)) { + resultat.endStart = m_regExpStop->Start(); + resultat.endStop = m_regExpStop->Stop(); + return HLP_FIND_OK; + } else { + resultat.endStart = stop+1; + resultat.endStop = stop+1; + resultat.notEnded = true; + return HLP_FIND_OK_NO_END; + } + } + //EDN_DEBUG("NOT find start hightlightpatern ..."); + } + return HLP_FIND_ERROR; +} diff --git a/Sources/Highlight/HighlightPattern.h b/Sources/Highlight/HighlightPattern.h index 670466a..232f1e3 100644 --- a/Sources/Highlight/HighlightPattern.h +++ b/Sources/Highlight/HighlightPattern.h @@ -65,7 +65,8 @@ class HighlightPattern { bool IsEnable(void); void Display(void); - resultFind_te Find(int32_t start, int32_t stop, colorInformation_ts &resultat, EdnVectorBuf &buffer); + resultFind_te Find( int32_t start, int32_t stop, colorInformation_ts &resultat, EdnVectorBuf &buffer); + resultFind_te FindOneElement(int32_t start, int32_t stop, colorInformation_ts &resultat, EdnVectorBuf &buffer); Colorize * GetColor(void) { return m_color; }; void ParseRules(TiXmlNode *child, int32_t level); @@ -79,8 +80,8 @@ class HighlightPattern { bool m_haveStopPatern; //!< Stop patern presence bool m_multiline; //!< The patern is multiline char m_escapeChar; //!< Escape char to prevent exeit of patern .... - Edn::VectorType m_subPatern; //!< Under patern of this one -// Edn::VectorType m_subColor; //!< Under Color in the start RegExp ... + Edn::VectorType m_subPatern; //!< Under patern of this one +// Edn::VectorType m_subColor; //!< Under Color in the start RegExp ... }; #endif diff --git a/Sources/tools/NameSpaceEdn/RegExp.h b/Sources/tools/NameSpaceEdn/RegExp.h index 8a20801..3a62477 100644 --- a/Sources/tools/NameSpaceEdn/RegExp.h +++ b/Sources/tools/NameSpaceEdn/RegExp.h @@ -1801,13 +1801,13 @@ template class EdnRegExp { if (true == m_notBeginWithChar) { if (i>0) { char tmpVal = SearchIn[i-1]; - if( ( 'a' <= tmpVal - && 'z' >= tmpVal ) - || ( 'A' <= tmpVal - && 'Z' >= tmpVal ) - || ( '0' <= tmpVal - && '9' >= tmpVal ) - || ( '_' == tmpVal ) ) + if( ( 'a' <= tmpVal + && 'z' >= tmpVal ) + || ( 'A' <= tmpVal + && 'Z' >= tmpVal ) + || ( '0' <= tmpVal + && '9' >= tmpVal ) + || ( '_' == tmpVal ) ) { // go on the next char ... continue; @@ -1827,13 +1827,13 @@ template class EdnRegExp { if (true == m_notEndWithChar) { if (i+findLen < SearchIn.Size() ) { char tmpVal = SearchIn[i+findLen]; - if( ( 'a' <= tmpVal - && 'z' >= tmpVal ) - || ( 'A' <= tmpVal - && 'Z' >= tmpVal ) - || ( '0' <= tmpVal - && '9' >= tmpVal ) - || ( '_' == tmpVal ) ) + if( ( 'a' <= tmpVal + && 'z' >= tmpVal ) + || ( 'A' <= tmpVal + && 'Z' >= tmpVal ) + || ( '0' <= tmpVal + && '9' >= tmpVal ) + || ( '_' == tmpVal ) ) { // go on the next char ... continue; @@ -1860,6 +1860,72 @@ template class EdnRegExp { return false; }; + bool ProcessOneElement( CLASS_TYPE &SearchIn, + int32_t startPos, + int32_t endPos, + char escapeChar=0) + { + if (false == m_isOk) { + return false; + } + int32_t buflen = SearchIn.Size(); + if (endPos > buflen) { + endPos = buflen; + } + if (startPos > endPos) { + return false; + } + int32_t findLen=0; + int32_t maxlen = endPos-startPos; + if (true == m_notBeginWithChar) { + if (startPos>0) { + char tmpVal = SearchIn[startPos-1]; + if( ( 'a' <= tmpVal + && 'z' >= tmpVal ) + || ( 'A' <= tmpVal + && 'Z' >= tmpVal ) + || ( '0' <= tmpVal + && '9' >= tmpVal ) + || ( '_' == tmpVal ) ) + { + // go on the next char ... + continue; + } + } + } + if (true == m_exprRootNode.Parse(SearchIn, startPos, maxlen, findLen)) { + if( 0!=escapeChar + && startPos>0) + { + if (escapeChar == (char)SearchIn[startPos-1]) { + //==> detected escape char ==> try find again ... + continue; + } + } + // Check end : + if (true == m_notEndWithChar) { + if (i+findLen < SearchIn.Size() ) { + char tmpVal = SearchIn[startPos+findLen]; + if( ( 'a' <= tmpVal + && 'z' >= tmpVal ) + || ( 'A' <= tmpVal + && 'Z' >= tmpVal ) + || ( '0' <= tmpVal + && '9' >= tmpVal ) + || ( '_' == tmpVal ) ) + { + // go on the next char ... + continue; + } + } + } + m_areaFind.start = startPos; + m_areaFind.stop = startPos + findLen; + return true; + } + return false; + }; + /** * @brief