From 2c6f280c582c4799d2b203301609152ed0d6cc75 Mon Sep 17 00:00:00 2001 From: Edouard Dupin Date: Mon, 8 Aug 2011 10:24:24 +0200 Subject: [PATCH] new parsing mode of HL Done with success ==> can have some residual errors TODO : Recursive Hightlight --- Sources/Highlight/Highlight.cpp | 239 ++---- Sources/Highlight/Highlight.h | 12 +- Sources/Highlight/HighlightPattern.cpp | 43 +- Sources/Highlight/HighlightPattern.h | 3 +- Sources/tools/EdnBuf/EdnBuf_HighLight.cpp | 2 +- Sources/tools/NameSpaceEdn/RegExp.h | 8 +- test2.c | 978 +--------------------- 7 files changed, 90 insertions(+), 1195 deletions(-) diff --git a/Sources/Highlight/Highlight.cpp b/Sources/Highlight/Highlight.cpp index 90c4cd0..e062744 100644 --- a/Sources/Highlight/Highlight.cpp +++ b/Sources/Highlight/Highlight.cpp @@ -175,91 +175,67 @@ void Highlight::Display(void) } +// TODO : Celui qui appelle suprime des element pour rien ... Enfin c'est pas tr\Uffffffffgrave... Il suffirait juste de suprimer celuis d'avant si il n'est pas terminer... void Highlight::Parse(int32_t start, int32_t stop, std::vector &metaData, - int32_t &addingPos, - EdnVectorBuf &buffer, - int32_t elementID) + int32_t addingPos, + EdnVectorBuf &buffer) { 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; - } + //EDN_DEBUG("Parse element 0 => " << m_listHighlightPass1.size() << " ==> position search: (" << start << "," << stop << ")" ); 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()); + while (elementStartFind(elementStart, buffer.Size(), resultat, buffer); + if (HLP_FIND_ERROR != ret) { + //EDN_INFO("Find Pattern in the Buffer : (" << resultat.beginStart << "," << resultat.endStop << ")" ); + // Remove element in the current List where the current Element have a end inside the next... + int32_t kkk=addingPos; + while(kkk < (int32_t)metaData.size() ) { + if (metaData[kkk].beginStart <= resultat.endStop) { + // Remove element + metaData.erase(metaData.begin()+kkk, metaData.begin()+kkk+1); + // Increase the end of search + if (kkk < (int32_t)metaData.size()) { + // just befor the end of the next element + elementStop = metaData[kkk].beginStart-1; + } else { + // end of the buffer + elementStop = buffer.Size(); + } } else { - // Remove old element : - //EDN_DEBUG(" --> Remove : " << addingPos << "==>" << findNextElement+1 ); - metaData.erase(metaData.begin()+addingPos,metaData.begin()+findNextElement+1); - newEnd = metaData[addingPos].beginStart-1; + // Not find ==> exit the cycle : + break; } - // 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 { + // Add curent element in the list ... metaData.insert(metaData.begin() + addingPos, resultat); //EDN_DEBUG("INSERT at "<< addingPos << " S=" << resultat.beginStart << " E=" << resultat.endStop ); + // Update the current research starting element: (Set position at the end of the current element + elementStart = resultat.endStop-1; + // increment the position of insertion: + addingPos++; + // We find a pattern ==> Stop search for the current element + break; } - // parse the under element : - Parse(elementStart, resultat.beginStart-1, metaData, addingPos, buffer, elementID+1); - addingPos++; - elementStart = resultat.endStop; } + // Go to the next element (and search again ...). + elementStart++; } - // parse the under element : - Parse(elementStart, elementStop, metaData, addingPos, buffer, elementID+1); } + /** * @brief second pass of the hightlight * @@ -267,122 +243,33 @@ void Highlight::Parse(int32_t start, void Highlight::Parse2(int32_t start, int32_t stop, std::vector &metaData, - EdnVectorBuf &buffer, - int32_t elementID) + EdnVectorBuf &buffer) { - if (elementID >= (int32_t)m_listHighlightPass2.size() ){ - return; - } + int32_t elementID = 0; + //EDN_DEBUG("Parse element 0 => " << m_listHighlightPass2.size() << " ==> position search: (" << start << "," << stop << ")" ); 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); - } else { - ret = HLP_FIND_ERROR; - } - if (HLP_FIND_ERROR != ret) { - //EDN_INFO("Find Pattern in the Buffer : (" << resultat.beginStart << "," << resultat.endStop << ")" ); - // parse the under element : - Parse2(elementStart, resultat.beginStart, metaData, buffer, elementID+1); - // Add curent element in the list ... - metaData.push_back(resultat); - elementStart = resultat.endStop; + while (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 ... + metaData.push_back(resultat); + elementStart = resultat.endStop; + // Exit current cycle + break; + } } + // Go to the next element (and search again ...). + elementStart++; } - // parse the under element : - Parse2(elementStart, elementStop, metaData, buffer, elementID+1); } - -void Highlight::ParseOneElement(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/Highlight.h b/Sources/Highlight/Highlight.h index 50b8fd7..a638df8 100644 --- a/Sources/Highlight/Highlight.h +++ b/Sources/Highlight/Highlight.h @@ -57,9 +57,15 @@ class Highlight { bool HasExtention(Edn::String &ext); bool FileNameCompatible(Edn::File &fileName); void Display(void); - void Parse( int32_t start, int32_t stop, std::vector &metaData, int32_t &addingPos, EdnVectorBuf &buffer, int32_t elementID=0); - void Parse2(int32_t start, int32_t stop, std::vector &metaData, EdnVectorBuf &buffer, int32_t elementID=0); - + void Parse(int32_t start, + int32_t stop, + std::vector &metaData, + int32_t addingPos, + EdnVectorBuf &buffer); + void Parse2(int32_t start, + int32_t stop, + std::vector &metaData, + EdnVectorBuf &buffer); private: void ParseRules(TiXmlNode *child, std::vector &mListPatern, int32_t level); Edn::String m_styleName; //!< curent style name (like "c++" or "c" or "script Bash") diff --git a/Sources/Highlight/HighlightPattern.cpp b/Sources/Highlight/HighlightPattern.cpp index b7ab676..eca3262 100644 --- a/Sources/Highlight/HighlightPattern.cpp +++ b/Sources/Highlight/HighlightPattern.cpp @@ -190,46 +190,7 @@ void HighlightPattern::ParseRules(TiXmlNode *child, int32_t level) } } -resultFind_te HighlightPattern::Find(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->Process(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->Process(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; -} + /** * @brief Find Element only in the specify start characters and find the end with the range done * @@ -242,7 +203,7 @@ resultFind_te HighlightPattern::Find(int32_t start, int32_t stop, colorInformati * @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) +resultFind_te HighlightPattern::Find(int32_t start, int32_t stop, colorInformation_ts &resultat, EdnVectorBuf &buffer) { //EDN_DEBUG(" try to find the element"); resultat.beginStart = -1; diff --git a/Sources/Highlight/HighlightPattern.h b/Sources/Highlight/HighlightPattern.h index 232f1e3..6c59e09 100644 --- a/Sources/Highlight/HighlightPattern.h +++ b/Sources/Highlight/HighlightPattern.h @@ -65,8 +65,7 @@ class HighlightPattern { bool IsEnable(void); void Display(void); - 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); + resultFind_te Find(int32_t start, int32_t stop, colorInformation_ts &resultat, EdnVectorBuf &buffer); Colorize * GetColor(void) { return m_color; }; void ParseRules(TiXmlNode *child, int32_t level); diff --git a/Sources/tools/EdnBuf/EdnBuf_HighLight.cpp b/Sources/tools/EdnBuf/EdnBuf_HighLight.cpp index 4d689f7..ea1bc1f 100644 --- a/Sources/tools/EdnBuf/EdnBuf_HighLight.cpp +++ b/Sources/tools/EdnBuf/EdnBuf_HighLight.cpp @@ -228,7 +228,7 @@ void EdnBuf::GenerateHighLightAt(int32_t pos, int32_t endPos, int32_t addinPos) return; } //EDN_DEBUG("area : ("<Parse(pos, endPos, m_HLDataPass1, addinPos, m_data); + m_Highlight->ParseOneElement(pos, endPos, m_HLDataPass1, addinPos, m_data); } diff --git a/Sources/tools/NameSpaceEdn/RegExp.h b/Sources/tools/NameSpaceEdn/RegExp.h index 3a62477..7b9804c 100644 --- a/Sources/tools/NameSpaceEdn/RegExp.h +++ b/Sources/tools/NameSpaceEdn/RegExp.h @@ -1889,7 +1889,7 @@ template class EdnRegExp { || ( '_' == tmpVal ) ) { // go on the next char ... - continue; + return false; } } } @@ -1899,12 +1899,12 @@ template class EdnRegExp { { if (escapeChar == (char)SearchIn[startPos-1]) { //==> detected escape char ==> try find again ... - continue; + return false; } } // Check end : if (true == m_notEndWithChar) { - if (i+findLen < SearchIn.Size() ) { + if (startPos+findLen < SearchIn.Size() ) { char tmpVal = SearchIn[startPos+findLen]; if( ( 'a' <= tmpVal && 'z' >= tmpVal ) @@ -1915,7 +1915,7 @@ template class EdnRegExp { || ( '_' == tmpVal ) ) { // go on the next char ... - continue; + return false; } } } diff --git a/test2.c b/test2.c index 2b2ebc6..7993bf8 100644 --- a/test2.c +++ b/test2.c @@ -4,26 +4,18 @@ * @brief Editeur De N'ours : Buffer for internal Data (Sources) * @author Edouard DUPIN * @date 23/03/2011 - * @par Project + * @par Projectqsdfqsdfq * Edn * - * @par Copyright - * Copyright 2010 Edouard DUPIN, all right reserved - * - * This software is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY. - * - * Licence summary : - * You can modify and redistribute the sources code and binaries. - * You can send me the bug-fix - * You can not earn money with this Software (if the source extract from Edn - * represent less than 50% of original Sources) - * Term of the licence in in the file licence.txt. - * ******************************************************************************* */ + +/* +#if 0 +*/ -#include "tools_debug.h" + +//#include "tools_debug.h" #include "tools_globals.h" #include "EdnBuf.h" @@ -39,10 +31,10 @@ static int32_t textWidth(EdnVectorBin &text, int32_t tabDist); * @brief convertion table for non printable control caracters */ static const char *ControlCodeTable[32] = { - "NUL", "soh", "stx", "etx", "eot", "enq", "ack", "bel", "bs", "ht", "nl", "vt", "np", "cr", "so", "si", - "dle", "dc1", "dc2", "dc3", "dc4", "nak", "syn", "etb", "can", "em", "sub", "esc", "fs", "gs", "rs", "us"}; - + "NUL", "soh", "stx", "etx", "eot", "enq", "ack", "bel", "bs", "ht", "nl", "vt", "np", "cr", "so", "si", + "dle", "dc1", "dc2", "dc3", "dc4", "nak", "syn", "etb", "can", "em", "sub", "esc", "fs", "gs", "rs", "us"}; +#endif /** * @brief Constructor of the Edn buffer Text : @@ -86,953 +78,3 @@ EdnBuf::EdnBuf(void) m_nbLine = 1; m_HLDataSequence = 0; } - -/** - * @brief Destructor of the Edn buffer Text : - */ -EdnBuf::~EdnBuf(void) -{ - // TODO : Remove history and Future -} - -/** - * @brief Save in the current file open - * - * @param[in,out] myFile pointer on the file where data might be writed - * - * @return true if OK / false if an error occured - * - */ -bool EdnBuf::DumpIn(FILE *myFile) -{ - // write Data - return m_data.DumpIn(myFile); -} - - -/** - * @brief Load in the current file open - * - * @param[in,out] myFile pointer on the file where data might be read - * - * @return true if OK / false if an error occured - * - */ -bool EdnBuf::DumpFrom(FILE *myFile) -{ - if (true == m_data.DumpFrom(myFile) ) { - // set no selection - UpdateSelections(0, 0, m_data.Size() ); - // generate HighLight - CleanHighLight(); - GenerateHighLightAt(0, m_data.Size()); - CountNumberOfLines(); - return true; - } - return false; -} - - -void EdnBuf::GetAll(EdnVectorBin &text) -{ - // Clean output vector - text.Clear(); - // Set data on the vector - m_data.Get(0, m_data.Size(), text); -} - - -void EdnBuf::SetAll(EdnVectorBin &text) -{ - EdnVectorBin deletedText; - - // extract all data of the buffer : - GetAll(deletedText); - - // Remove all data in the buffer: - m_data.Clear(); - - // inset text data : - m_data.Insert(0, text); - - // Zero all of the existing selections - UpdateSelections(0, deletedText.Size(), 0); - - // Call the modification Event Manager - eventModification(0, m_data.Size(), deletedText); -} - -void EdnBuf::GetRange(int32_t start, int32_t end, EdnVectorBin &output) -{ - // Remove all data ... - output.Clear(); - // import data : - m_data.Get(start, end-start, output); - //EDN_DEBUG("request start=" << start << " end="<< end << " size="<< end-start << " result size=" << output.Size() ); -} - - -/** - * @brief Get an element at the selected position - * - * @param[in] pos Charecters Position, [0..n] - * - * @return The character at buffer position "pos" - * - */ -int8_t EdnBuf::operator[] (int32_t pos) -{ - int8_t res = m_data.Get(pos); - return res; -} - - -/** - * @brief Insert Data in the Buffer - * - * @param[in] pos Position in the Buffer - * @param[in] insertText Text to insert - * - * @return --- - * - */ -void EdnBuf::Insert(int32_t pos, EdnVectorBin &insertText) -{ - // if pos is not contiguous to existing text, make it - pos = edn_average(0, pos, m_data.Size() ); - // insert Data - insert(pos, insertText); - - // Call the redisplay ... - EdnVectorBin deletedText; - eventModification(pos, insertText.Size(), deletedText); -} - - -/** - * @brief Replace data in the buffer - * - * @param[in] start Position started in the buffer - * @param[in] end Position ended in the buffer - * @param[in] insertText Test to set in the range [start..end] - * - * @return --- - * - */ -void EdnBuf::Replace(int32_t start, int32_t end, EdnVectorBin &insertText) -{ - EdnVectorBin deletedText; - GetRange(start, end, deletedText); - m_data.Replace(start, end-start, insertText); - // update internal elements - eventModification(start, insertText.Size(), deletedText); -} - - -/** - * @brief Remove data between [start..end] - * - * @param[in] start Position started in the buffer - * @param[in] end Position ended in the buffer - * - * @return --- - * - */ -void EdnBuf::Remove(int32_t start, int32_t end) -{ - - EdnVectorBin deletedText; - // Make sure the arguments make sense - if (start > end) { - int32_t temp = start; - start = end; - end = temp; - } - start = edn_average(0 , start, m_data.Size()); - end = edn_average(0 , end, m_data.Size()); - - // Remove and redisplay - GetRange(start, end, deletedText); - m_data.Remove(start, end - start); - eventModification(start, 0, deletedText); -} - -/** - * @brief Get the current tabulation distance - * - * @param --- - * - * @return The current tabulation size - * - */ -int32_t EdnBuf::GetTabDistance(void) -{ - return m_tabDist; -} - - -/** - * @brief Set the current Tabulation size - * - * @param[in] tabDist The new tabulation size - * - * @return --- - * - */ -void EdnBuf::SetTabDistance(int32_t tabDist) -{ - // Change the tab setting - m_tabDist = tabDist; -} - - -/** - * @brief Get the data of a specific line - * - * @param[in] pos Position in a line that might be geted - * @param[out] text Data in the current line at pos - * - * @return --- - * - */ -void EdnBuf::GetLineText(int32_t pos, EdnVectorBin &text) -{ - GetRange( StartOfLine(pos), EndOfLine(pos), text); -} - - -/** - * @brief Find the position of the start of the current line - * - * @param[in] pos position inside the line whe we need to find the start - * - * @return position of the start of the line - * - */ -int32_t EdnBuf::StartOfLine(int32_t pos) -{ - int32_t startPos; - if (false == SearchBackward(pos, '\n', &startPos)) { - return 0; - } - return startPos + 1; -} - - -/** - * @brief Find the position of the end of the current line - * - * @param[in] pos position inside the line whe we need to find the end - * - * @return position of the end of the line - * - */ -int32_t EdnBuf::EndOfLine(int32_t pos) -{ - int32_t endPos; - if (false == SearchForward(pos, '\n', &endPos)) { - endPos = m_data.Size(); - } - return endPos; -} - - -/** - * @brief Transform the current caracter in the buffer in a common display char - * - * @param[in] c Char that might be converted - * @param[in] indent Curent indentation befor the curent char - * @param[out] outStr string of the displayed element - * - * @return --- - * - */ -int32_t EdnBuf::GetExpandedChar(int32_t pos, int32_t indent, char outUTF8[MAX_EXP_CHAR_LEN]) -{ - return ExpandCharacter( m_data.Get(pos), indent, outUTF8); -} - - -/** - * @brief generate the real display of character of the output (ex : \t ==> 4 spaces or less ...) - * - * @param[in] c Char that might be converted - * @param[in] indent Curent indentation befor the curent char - * @param[out] outStr string of the displayed element - * - * @return size of the display - * - */ -int32_t EdnBuf::ExpandCharacter(char c, int32_t indent, char outUTF8[MAX_EXP_CHAR_LEN]) -{ - int32_t i, nSpaces; - - /* Convert tabs to spaces */ - if (c == '\t') { - nSpaces = m_tabDist - (indent % m_tabDist); - for (i=0; i m_data.Size() ) { - return m_data.Size(); - } - EdnVectorBuf::Iterator myPosIt = m_data.Position(startPos); - int32_t lineCount = 0; - //EDN_INFO("startPos=" << startPos << " nLines=" << nLines); - while(myPosIt) - { - if ('\n' == *myPosIt) { - lineCount++; - if (lineCount == nLines) { - //EDN_INFO(" ==> (1) at position=" << myPosIt.Position()+1 ); - return myPosIt.Position()+1; - } - } - myPosIt++; - } - //EDN_INFO(" ==> (2) at position=" << myPosIt.Position() ); - return myPosIt.Position(); -} - - -/** - * @brief Find the first character of the line "nLines" backwards - * - * @param[in,out] startPos Start position to count (this caracter is not counted) - * @param[in,out] nLines number of line to count (if ==0 means find the beginning of the line) - * - * @return position of the starting the line - * - */ -int32_t EdnBuf::CountBackwardNLines(int32_t startPos, int32_t nLines) -{ - if (startPos <= 0) { - return 0; - } else if (startPos > m_data.Size() ) { - startPos = m_data.Size(); - } - //EDN_INFO("startPos=" << startPos << " nLines=" << nLines); - - EdnVectorBuf::Iterator myPosIt = m_data.Position(startPos-1); - int32_t lineCount = -1; - - while(myPosIt) { - if ('\n' == *myPosIt) { - lineCount++; - if (lineCount >= nLines) { - //EDN_INFO(" ==> (1) at position=" << myPosIt.Position()+1 ); - return myPosIt.Position()+1; - } - } - myPosIt--; - } - //EDN_INFO(" ==> (2) at position=0"); - return 0; -} - - -bool EdnBuf::charMatch(char first, char second, bool caseSensitive) -{ - if (false == caseSensitive) { - if ('A' <= first && 'Z' >= first) { - first = first - 'A' + 'a'; - } - if ('A' <= second && 'Z' >= second) { - second = second - 'A' + 'a'; - } - } - if(first == second) { - //EDN_DEBUG("charMatch(" << first << ", " << second << ", " << caseSensitive << ") ==> true"); - return true; - } else { - //EDN_DEBUG("charMatch(" << first << ", " << second << ", " << caseSensitive << ") ==> false"); - return false; - } -} -#dfgdfgdfg /*sdfsdf*/ -/** - * @brief Search forwards in buffer - * - * @param[in] startPos Position to start the search - * @param[in] searchVect String to search - * @param[out] foundPos Current position founded - * - * @return true ==> found data - * @return false ==> not found data - * - */ -bool EdnBuf::SearchForward(int32_t startPos, EdnVectorBin &searchVect, int32_t *foundPos, bool caseSensitive) -{ - int32_t position; - int32_t searchLen = searchVect.Size(); - int32_t dataLen = m_data.Size(); - char currentChar = '\0'; - //EDN_INFO(" startPos=" << startPos << " searchLen=" << searchLen); - for (position=startPos; position found data - * @return false ==> not found data - * - */ -bool EdnBuf::SearchBackward(int32_t startPos, EdnVectorBin &searchVect, int32_t *foundPos, bool caseSensitive) -{ - int32_t position; - int32_t searchLen = searchVect.Size(); - char currentChar = '\0'; - //EDN_INFO(" startPos=" << startPos << " searchLen=" << searchLen); - for (position=startPos; position>=searchLen-1; position--) { - currentChar = m_data[position]; - if (true == charMatch(currentChar, searchVect[searchLen-1], caseSensitive)) { - int32_t i; - bool found = true; - for (i=searchLen-1; i>=0; i--) { - currentChar = m_data[position - (searchLen-1) + i]; - if (false == charMatch(currentChar, searchVect[i], caseSensitive)) { - found = false; - break; - } - } - if (true == found) { - *foundPos = position - (searchLen-1); - return true; - } - } - } - *foundPos = m_data.Size(); - return false; -} - -static bool isChar(char value) -{ - if( ('a' <= value && 'z' >= value) - || ('A' <= value && 'Z' >= value) - || ('0' <= value && '9' >= value) - || '_' == value - || '~' == value) - { - //EDN_DEBUG(" is a char \"" << value << "\""); - return true; - } - //EDN_DEBUG(" is NOT a char \"" << value << "\""); - return false; -} - - -bool EdnBuf::SelectAround(int32_t startPos, int32_t &beginPos, int32_t &endPos) -{ - char currentChar = m_data[startPos]; - if( '\t' == currentChar - || ' ' == currentChar) - { - EDN_DEBUG("select spacer"); - // special case we are looking for separation - for (beginPos=startPos; beginPos>=0; beginPos--) { - currentChar = m_data[beginPos]; - if( '\t' != currentChar - && ' ' != currentChar) - { - beginPos++; - break; - } - } - // special case we are looking for separation - for (endPos=startPos; endPos=0; beginPos--) { - currentChar = m_data[beginPos]; - if( false == isChar(currentChar)) { - beginPos++; - break; - } - } - // Search forward - for (endPos=startPos; endPos=0; beginPos--) { - currentChar = m_data[beginPos]; - if(comparechar != currentChar) - { - beginPos++; - break; - } - } - // Search forward - for (endPos=startPos; endPos &insertText) -{ - // Insert data in buffer - m_data.Insert(pos, insertText); - // update the current selected area - UpdateSelections(pos, 0, insertText.Size() ); - // return the number of element inserted ... - return insertText.Size(); -} - - - - -/** - * @brief - * - * @param[in,out] --- - * - * @return --- - * - */ -// TODO : Reprog this ??? -static void addPadding(char *string, int32_t startIndent, int32_t toIndent, int32_t tabDist, int32_t useTabs, int32_t *charsAdded) -{ -/* - char *outPtr; - int32_t len, indent; - - indent = startIndent; - outPtr = string; - if (useTabs) { - while (indent < toIndent) { - len = CharWidth('\t', indent); - if( len > 1 - && indent + len <= toIndent) - { - *outPtr++ = '\t'; - indent += len; - } else { - *outPtr++ = ' '; - indent++; - } - } - } else { - while (indent < toIndent) { - *outPtr++ = ' '; - indent++; - } - } - *charsAdded = outPtr - string; -*/ -} - -/** - * @brief when modification appeare in the buffer we save it in the undo vector... - * - * @param[in] pos position of the add or remove - * @param[in] nInserted nb element inserted - * @param[in] deletedText Deleted elevent in a vector - * - * @return --- - * - */ -void EdnBuf::eventModification(int32_t pos, int32_t nInserted, EdnVectorBin &deletedText) -{ - if( 0 == deletedText.Size() - && 0 == nInserted) - { - // we do nothing ... - //EDN_INFO("EdnBuf::eventModification(pos="< not efficent methode ... - // ==> better methode : just update the number of line added and removed ... - //EDN_INFO(" add=" << CountLines(pos, pos+nInserted) << " lines | remove="<< CountLines(deletedText) << " lines"); - m_nbLine += CountLines(pos, pos+nInserted) - CountLines(deletedText); - // Update histories - if (false == m_isUndoProcessing) { - // normal or Redo processing - EdnBufHistory *exempleHistory = new EdnBufHistory(pos, nInserted, deletedText); - m_historyUndo.PushBack(exempleHistory); - if (false == m_isRedoProcessing) { - // remove all element in the redo system ... - int32_t i; - for (i=m_historyRedo.Size()-1; i>=0; i--) { - if (NULL != m_historyRedo[i]) { - delete(m_historyRedo[i]); - } - m_historyRedo.PopBack(); - } - } - } else { - // undo processing ==> add element in Redo vector ... - EdnBufHistory *exempleHistory = new EdnBufHistory(pos, nInserted, deletedText); - m_historyRedo.PushBack(exempleHistory); - } - // Regenerate the Highlight : - RegenerateHighLightAt(pos, deletedText.Size(), nInserted); - } -} - - - - - -/** - * @brief Search a character in the current buffer - * - * @param[in] startPos Position to start the search of the element - * @param[in] searchChar Character to search - * @param[out] foundPos Position where it was found - * - * @return true when find element - * - */ -bool EdnBuf::SearchForward(int32_t startPos, char searchChar, int32_t *foundPos) -{ - // Create iterator - EdnVectorBuf::Iterator myPosIt = m_data.Position(startPos); - // move in the string - while (myPosIt) { - if (*myPosIt == searchChar) { - *foundPos = myPosIt.Position(); - return true; - } - myPosIt++; - } - *foundPos = m_data.Size(); - return false; -} - - -/** - * @brief Search a character in the current buffer (backward - * - * @param[in] startPos Position to start the search of the element - * @param[in] searchChar Character to search - * @param[out] foundPos Position where it was found - * - * @return true when find element - * - */ -bool EdnBuf::SearchBackward(int32_t startPos, char searchChar, int32_t *foundPos) -{ - // Create iterator - EdnVectorBuf::Iterator myPosIt = m_data.Position(startPos-1); - // move in the string - while (myPosIt) { - if (*myPosIt == searchChar) { - *foundPos = myPosIt.Position(); - return true; - } - myPosIt--; - } - *foundPos = 0; - return false; -} - - -/** - * @brief Measure the width in the buffer input - * - * @param[in] text Buffer input - * @param[in] tabDist T bulation size - * - * @return maxWidth - * - */ -static int32_t textWidth(EdnVectorBin &text, int32_t tabDist) -{ -EDN_ERROR("REPROGRAM this fuction"); -/* - EdnVectorBin::Iterator myPosIt = text.Begin(); - int32_t width = 0, maxWidth = 0; - - while(myPosIt) { - if ('\n' == *myPosIt) { - if (width > maxWidth) { - maxWidth = width; - } - width = 0; - } else { - width += CharWidth(*myPosIt, width); - } - myPosIt++; - } - if (width > maxWidth) { - return width; - } - return maxWidth; -*/ -} - -