new parsing mode of HL Done with success ==> can have some residual errors
TODO : Recursive Hightlight
This commit is contained in:
parent
722dafaaef
commit
2c6f280c58
@ -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<colorInformation_ts> &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 && elementStart<elementStop) {
|
||||
ret = m_listHighlightPass1[elementID]->Find(elementStart, elementStop, resultat, buffer);
|
||||
while (elementStart<elementStop) {
|
||||
//EDN_DEBUG("Parse element in the buffer id=" << elementStart);
|
||||
//try to fond the HL in ALL of we have
|
||||
int32_t jjj;
|
||||
for (jjj=0; jjj<m_listHighlightPass1.size(); jjj++){
|
||||
resultFind_te ret = HLP_FIND_OK;
|
||||
//EDN_DEBUG("Parse HL id=" << jjj << " position search: (" << start << "," << buffer.Size() << ")" );
|
||||
// Stop the search to the end (to get the end of the pattern)
|
||||
ret = m_listHighlightPass1[jjj]->Find(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 {
|
||||
// Not find ==> exit the cycle :
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 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);
|
||||
// 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++;
|
||||
elementStart = resultat.endStop;
|
||||
// We find a pattern ==> Stop search for the current element
|
||||
break;
|
||||
}
|
||||
}
|
||||
// parse the under element :
|
||||
Parse(elementStart, elementStop, metaData, addingPos, buffer, elementID+1);
|
||||
// Go to the next element (and search again ...).
|
||||
elementStart++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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<colorInformation_ts> &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 && elementStart<elementStop) {
|
||||
if (m_listHighlightPass2[elementID]!=NULL) {
|
||||
ret = m_listHighlightPass2[elementID]->Find(elementStart, elementStop, resultat, buffer);
|
||||
} else {
|
||||
ret = HLP_FIND_ERROR;
|
||||
}
|
||||
while (elementStart<elementStop) {
|
||||
//EDN_DEBUG("Parse element in the buffer id=" << elementStart);
|
||||
//try to fond the HL in ALL of we have
|
||||
int32_t jjj;
|
||||
for (jjj=0; jjj<m_listHighlightPass2.size(); jjj++){
|
||||
resultFind_te ret = HLP_FIND_OK;
|
||||
//EDN_DEBUG("Parse HL id=" << jjj << " position search: (" << start << "," << buffer.Size() << ")" );
|
||||
// Stop the search to the end (to get the end of the pattern)
|
||||
ret = m_listHighlightPass2[jjj]->Find(elementStart, elementStop, resultat, buffer);
|
||||
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;
|
||||
}
|
||||
}
|
||||
// parse the under element :
|
||||
Parse2(elementStart, elementStop, metaData, buffer, elementID+1);
|
||||
}
|
||||
|
||||
|
||||
void Highlight::ParseOneElement(int32_t start,
|
||||
int32_t stop,
|
||||
std::vector<colorInformation_ts> &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 && elementStart<elementStop) {
|
||||
/*
|
||||
Algo : faire un boucle incrémentant le start, et ne pas mettre de contrainet pour le stop
|
||||
par contre quand on a un stop on doit faire un controle sur la présence d'element avant le end qu'il vas faloir detruire...
|
||||
*/
|
||||
}
|
||||
ret = m_listHighlightPass1[elementID]->Find(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 );
|
||||
// Exit current cycle
|
||||
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;
|
||||
// Go to the next element (and search again ...).
|
||||
elementStart++;
|
||||
}
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
@ -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<colorInformation_ts> &metaData, int32_t &addingPos, EdnVectorBuf &buffer, int32_t elementID=0);
|
||||
void Parse2(int32_t start, int32_t stop, std::vector<colorInformation_ts> &metaData, EdnVectorBuf &buffer, int32_t elementID=0);
|
||||
|
||||
void Parse(int32_t start,
|
||||
int32_t stop,
|
||||
std::vector<colorInformation_ts> &metaData,
|
||||
int32_t addingPos,
|
||||
EdnVectorBuf &buffer);
|
||||
void Parse2(int32_t start,
|
||||
int32_t stop,
|
||||
std::vector<colorInformation_ts> &metaData,
|
||||
EdnVectorBuf &buffer);
|
||||
private:
|
||||
void ParseRules(TiXmlNode *child, std::vector<HighlightPattern*> &mListPatern, int32_t level);
|
||||
Edn::String m_styleName; //!< curent style name (like "c++" or "c" or "script Bash")
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
||||
|
@ -228,7 +228,7 @@ void EdnBuf::GenerateHighLightAt(int32_t pos, int32_t endPos, int32_t addinPos)
|
||||
return;
|
||||
}
|
||||
//EDN_DEBUG("area : ("<<pos<<","<<endPos<<") insert at : " << addinPos);
|
||||
m_Highlight->Parse(pos, endPos, m_HLDataPass1, addinPos, m_data);
|
||||
m_Highlight->ParseOneElement(pos, endPos, m_HLDataPass1, addinPos, m_data);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1889,7 +1889,7 @@ template<class CLASS_TYPE> class EdnRegExp {
|
||||
|| ( '_' == tmpVal ) )
|
||||
{
|
||||
// go on the next char ...
|
||||
continue;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1899,12 +1899,12 @@ template<class CLASS_TYPE> 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 CLASS_TYPE> class EdnRegExp {
|
||||
|| ( '_' == tmpVal ) )
|
||||
{
|
||||
// go on the next char ...
|
||||
continue;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
974
test2.c
974
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.
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#include "tools_debug.h"
|
||||
/*
|
||||
#if 0
|
||||
*/
|
||||
|
||||
|
||||
//#include "tools_debug.h"
|
||||
#include "tools_globals.h"
|
||||
#include "EdnBuf.h"
|
||||
|
||||
@ -42,7 +34,7 @@ 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"};
|
||||
|
||||
|
||||
#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<int8_t> &text)
|
||||
{
|
||||
// Clean output vector
|
||||
text.Clear();
|
||||
// Set data on the vector
|
||||
m_data.Get(0, m_data.Size(), text);
|
||||
}
|
||||
|
||||
|
||||
void EdnBuf::SetAll(EdnVectorBin<int8_t> &text)
|
||||
{
|
||||
EdnVectorBin<int8_t> 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<int8_t> &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<int8_t> &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<int8_t> 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<int8_t> &insertText)
|
||||
{
|
||||
EdnVectorBin<int8_t> 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<int8_t> 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<int8_t> &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<nSpaces; i++) {
|
||||
outUTF8[i] = ' ';
|
||||
}
|
||||
outUTF8[i] = '\0';
|
||||
return nSpaces;
|
||||
}
|
||||
|
||||
// Convert ASCII control codes to readable character sequences
|
||||
if (c == '\0') {
|
||||
outUTF8[0] = '<';
|
||||
outUTF8[1] = 'n';
|
||||
outUTF8[2] = 'u';
|
||||
outUTF8[3] = 'l';
|
||||
outUTF8[4] = '>';
|
||||
outUTF8[5] = '\0';
|
||||
return 5;
|
||||
}
|
||||
if (((unsigned char)c) <= 31) {
|
||||
const char * tmp = ControlCodeTable[(unsigned char)c];
|
||||
*outUTF8++ = '<';
|
||||
while (*tmp!='\0') {
|
||||
*outUTF8++ = *tmp;
|
||||
tmp++;
|
||||
}
|
||||
*outUTF8++ = '>';
|
||||
*outUTF8++ = '\0';
|
||||
return ControlCodeTable[(unsigned char)c] - tmp + 2;
|
||||
} else if (c == 127) {
|
||||
outUTF8[0] = '<';
|
||||
outUTF8[1] = 'd';
|
||||
outUTF8[2] = 'e';
|
||||
outUTF8[3] = 'l';
|
||||
outUTF8[4] = '>';
|
||||
outUTF8[5] = '\0';
|
||||
return 5;
|
||||
}
|
||||
|
||||
// Otherwise, just return the character
|
||||
// *outStr = c; // deprecated
|
||||
convertIsoToUtf8(EDN_CHARSET_ISO_8859_15, c, outUTF8);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Generate the size of the display of one element
|
||||
*
|
||||
* @param[in] c Char that might be converted
|
||||
* @param[in] indent Curent indentation befor the curent char
|
||||
*
|
||||
* @return size of the display
|
||||
*
|
||||
*/
|
||||
int32_t EdnBuf::CharWidth(char c, int32_t indent)
|
||||
{
|
||||
/* Note, this code must parallel that in ExpandCharacter */
|
||||
if (c == '\0') {
|
||||
return 5;
|
||||
} else if (c == '\t') {
|
||||
return m_tabDist - (indent % m_tabDist);
|
||||
} else if (((unsigned char)c) <= 31) {
|
||||
return strlen(ControlCodeTable[(unsigned char)c]) + 2;
|
||||
} else if (c == 127) {
|
||||
return 5;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Count the number of displayed characters between buffer position
|
||||
*
|
||||
* Displayed characters are the characters shown on the screen to represent characters in the
|
||||
* buffer, where tabs and control characters are expanded
|
||||
*
|
||||
* @param[in] lineStartPos Start position in the line
|
||||
* @param[in] targetPos Displayed target position in char
|
||||
*
|
||||
* @return the ID in the buffer of the requested char
|
||||
*
|
||||
*/
|
||||
int32_t EdnBuf::CountDispChars(int32_t lineStartPos, int32_t targetPos)
|
||||
{
|
||||
EdnVectorBuf::Iterator myPosIt = m_data.Position(lineStartPos);
|
||||
int32_t charCount = 0;
|
||||
|
||||
char expandedChar[MAX_EXP_CHAR_LEN];
|
||||
//EDN_DEBUG("lineStartPos="<< lineStartPos << " targetPos=" << targetPos);
|
||||
while( myPosIt
|
||||
&& myPosIt.Position() < targetPos )
|
||||
{
|
||||
charCount += ExpandCharacter(*myPosIt, charCount, expandedChar);
|
||||
myPosIt++;
|
||||
}
|
||||
//EDN_DEBUG(" result=" << charCount);
|
||||
return charCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the position of the nth diplaye char
|
||||
*
|
||||
* @param[in] lineStartPos Position of the start of the line
|
||||
* @param[in] nChars search in the next nChars elements
|
||||
*
|
||||
* @return number of diaplay char
|
||||
*
|
||||
*/
|
||||
int32_t EdnBuf::CountForwardDispChars(int32_t lineStartPos, int32_t nChars)
|
||||
{
|
||||
EdnVectorBuf::Iterator myPosIt = m_data.Position(lineStartPos);
|
||||
int32_t charCount = 0;
|
||||
char c;
|
||||
|
||||
while( charCount < nChars
|
||||
&& myPosIt)
|
||||
{
|
||||
c = *myPosIt;
|
||||
if (c == '\n') {
|
||||
return myPosIt.Position();
|
||||
}
|
||||
charCount += CharWidth(c, charCount);
|
||||
myPosIt++;
|
||||
}
|
||||
return myPosIt.Position();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Count the number of newlines ('\n') between startPos and endPos
|
||||
*
|
||||
* @param[in,out] startPos Fist position in the buffer
|
||||
* @param[in,out] endPos Last position in the buffer (not counted)
|
||||
*
|
||||
* @return ---
|
||||
*
|
||||
*/
|
||||
int32_t EdnBuf::CountLines(int32_t startPos, int32_t endPos)
|
||||
{
|
||||
EdnVectorBuf::Iterator myPosIt = m_data.Position(startPos);
|
||||
int32_t lineCount = 0;
|
||||
|
||||
while (myPosIt) {
|
||||
if (myPosIt.Position() == endPos) {
|
||||
return lineCount;
|
||||
}
|
||||
if ('\n' == *myPosIt) {
|
||||
lineCount++;
|
||||
}
|
||||
myPosIt++;
|
||||
}
|
||||
return lineCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief count the number of '\n' in the vector of elements
|
||||
*
|
||||
* @param[in] text Data to count the lines
|
||||
*
|
||||
* @return number of line found
|
||||
*
|
||||
*/
|
||||
int32_t EdnBuf::CountLines(EdnVectorBin<int8_t> &data)
|
||||
{
|
||||
EdnVectorBin<int8_t>::Iterator myPosIt = data.Begin();
|
||||
int32_t lineCount = 0;
|
||||
|
||||
while(myPosIt) {
|
||||
if ('\n' == *myPosIt) {
|
||||
lineCount++;
|
||||
}
|
||||
myPosIt++;
|
||||
}
|
||||
return lineCount;
|
||||
}
|
||||
|
||||
int32_t EdnBuf::CountLines(void)
|
||||
{
|
||||
EdnVectorBuf::Iterator myPosIt = m_data.Begin();
|
||||
int32_t lineCount = 0;
|
||||
|
||||
while(myPosIt) {
|
||||
if ('\n' == *myPosIt) {
|
||||
lineCount++;
|
||||
}
|
||||
myPosIt++;
|
||||
}
|
||||
return lineCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Calculate the number of line
|
||||
*
|
||||
* @param ---
|
||||
*
|
||||
* @return the number of line in the buffer [1..n]
|
||||
*
|
||||
*/
|
||||
void EdnBuf::CountNumberOfLines(void)
|
||||
{
|
||||
m_nbLine = CountLines(0, m_data.Size());
|
||||
m_nbLine++;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Find the first character of the line "nLines" forward
|
||||
*
|
||||
* @param[in,out] startPos Start position to count
|
||||
* @param[in,out] nLines number of line to count
|
||||
*
|
||||
* @return position of the starting the line
|
||||
*
|
||||
*/
|
||||
int32_t EdnBuf::CountForwardNLines(int32_t startPos, int32_t nLines)
|
||||
{
|
||||
if (nLines == 0) {
|
||||
return startPos;
|
||||
} else if (startPos > 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<int8_t> &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<dataLen - (searchLen-1); position++) {
|
||||
currentChar = m_data[position];
|
||||
if (true == charMatch(currentChar, searchVect[0], caseSensitive)) {
|
||||
int32_t i;
|
||||
bool found = true;
|
||||
for (i=1; i<searchLen; i++) {
|
||||
currentChar = m_data[position + i];
|
||||
if (false == charMatch(currentChar, searchVect[i], caseSensitive)) {
|
||||
found = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (true == found) {
|
||||
*foundPos = position;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
*foundPos = m_data.Size();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Search backwards in buffer
|
||||
*
|
||||
* @param[in] startPos Position to start the search
|
||||
* @param[in] searchChars String to search
|
||||
* @param[out] foundPos Current position founded
|
||||
*
|
||||
* @return true ==> found data
|
||||
* @return false ==> not found data
|
||||
*
|
||||
*/
|
||||
bool EdnBuf::SearchBackward(int32_t startPos, EdnVectorBin<int8_t> &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<m_data.Size(); endPos++) {
|
||||
currentChar = m_data[endPos];
|
||||
if( '\t' != currentChar
|
||||
&& ' ' != currentChar)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else if( true == isChar(currentChar)){
|
||||
EDN_DEBUG("select normal Char");
|
||||
// Search back
|
||||
for (beginPos=startPos; beginPos>=0; beginPos--) {
|
||||
currentChar = m_data[beginPos];
|
||||
if( false == isChar(currentChar)) {
|
||||
beginPos++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Search forward
|
||||
for (endPos=startPos; endPos<m_data.Size(); endPos++) {
|
||||
currentChar = m_data[endPos];
|
||||
if( false == isChar(currentChar)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
char comparechar = currentChar;
|
||||
EDN_DEBUG("select same char");
|
||||
// Search back
|
||||
for (beginPos=startPos; beginPos>=0; beginPos--) {
|
||||
currentChar = m_data[beginPos];
|
||||
if(comparechar != currentChar)
|
||||
{
|
||||
beginPos++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Search forward
|
||||
for (endPos=startPos; endPos<m_data.Size(); endPos++) {
|
||||
currentChar = m_data[endPos];
|
||||
if(comparechar != currentChar)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
beginPos = 0;
|
||||
endPos = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Insert data in the buffer binary and call all needed functions.
|
||||
*
|
||||
* @param[in] pos Position to insert data in the buffer.
|
||||
* @param[in] insertText Data to insert.
|
||||
*
|
||||
* @return number of element inserted.
|
||||
*
|
||||
*/
|
||||
int32_t EdnBuf::insert(int32_t pos, EdnVectorBin<int8_t> &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<int8_t> &deletedText)
|
||||
{
|
||||
if( 0 == deletedText.Size()
|
||||
&& 0 == nInserted)
|
||||
{
|
||||
// we do nothing ...
|
||||
//EDN_INFO("EdnBuf::eventModification(pos="<<pos<<", ... , nRestyled=" << nRestyled << ", deletedText=\"" << textDisplay << "\");");
|
||||
} else {
|
||||
EDN_INFO("(pos="<<pos<<", nDeleted="<<deletedText.Size()<<", nInserted=" << nInserted << ", deletedText=\"xx???xx\");");
|
||||
// update the number of lines :
|
||||
//CountNumberOfLines(); //==> 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<int8_t> &text, int32_t tabDist)
|
||||
{
|
||||
EDN_ERROR("REPROGRAM this fuction");
|
||||
/*
|
||||
EdnVectorBin<int8_t>::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;
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user