[DEV] change in etk::RegExp in std::regex

This commit is contained in:
Edouard DUPIN 2014-10-05 23:46:57 +02:00
parent 154351e629
commit 243d7e7494
8 changed files with 501 additions and 134 deletions

View File

@ -12,39 +12,39 @@
<pass1><!-- multiline section & parse all file (now) and when modification retrive previous modification -->
<rule name="my comment multiline doxygen">
<color>commentDoxygen</color>
<regex>/\*\*.*(\*/|\e)</regex>
<regex>/\*\*(.|\r|\n)*?\*/</regex>
</rule>
<rule name="code Review">
<color>SYNTAX_ERROR</color>
<regex>/\*[ \t]*TODO :.*(\*/|\e)</regex>
<regex>/\*[ \t]*TODO :(.|\r|\n)*?\*/</regex>
</rule>
<rule name="my comment multiline">
<color>comment</color>
<regex>/\*.*(\*/|\e)</regex>
<regex>/\*(.|\r|\n)*?\*/</regex>
</rule>
<rule name="my if 0">
<color>preprocesseur</color>
<regex>#[ \t]*if 0.*#(endif|else)</regex>
<regex>#[ \t]*if 0(.|\r|\n)*?#(endif|else)</regex>
</rule>
<rule name="my preprocesseur">
<color>preprocesseur</color>
<regex>#(\\[\\\n]|.)*$</regex>
<regex>#(\\[\\\n]|.)*</regex>
</rule>
<rule name="my comment doxygen">
<color>commentDoxygen</color>
<regex>//!.*$</regex>
<regex>//!.*</regex>
</rule>
<rule name="my todo comment">
<color>SYNTAX_ERROR</color>
<regex>//[ \t]*TODO[ \t]*:.*$</regex>
<regex>//[ \t]*TODO[ \t]*:.*</regex>
</rule>
<rule name="my comment">
<color>comment</color>
<regex>//.*$</regex>
<regex>//.*</regex>
</rule>
<rule name="doubleQuteText">
<color>doubleQuoteText</color>
<regex>"(\\[\\"]|.)*"</regex><!-- " -->
<regex>"(\\[\\"]|.)*"</regex>
</rule>
<rule name="simpleQuteText">
<color>doubleQuoteText</color>
@ -106,17 +106,15 @@
<color>functionName</color>
<regex>\@(\w|_)+[ \t]*\(</regex>
</rule>
-->
<rule name="condition">
<color>boolean</color>
<regex>==|&lt;=|&gt;=|!=|&lt;{1,2}|&gt;{1,2}|&amp;&amp;|\{|\}|</regex>
</rule>
<!-- With all elementes :
-->
<rule name="BIG LETTER">
<color>macro</color>
<regex>([A-Z]|_){4,500}</regex>
<elemSubColor id="1">doxElem</elemSubColor>
</rule>
-->
</pass2>
</EdnLang>

View File

@ -17,33 +17,101 @@
#undef __class__
#define __class__ "Buffer"
appl::Buffer::Iterator& appl::Buffer::Iterator::operator++ () {
m_value = u32char::Null;
if (m_current < 0) {
m_current = 0;
return *this;
}
if (m_data != nullptr) {
if (m_current < (int64_t)m_data->m_data.size() ) {
int8_t nbChar = utf8::theoricLen(m_data->m_data[m_current]);
if (nbChar != 0) {
m_current+=nbChar;
} else {
m_current++;
}
}
if (m_current >= (int64_t)m_data->m_data.size()) {
m_current = m_data->m_data.size();
}
}
return *this;
}
appl::Buffer::Iterator& appl::Buffer::Iterator::operator-- () {
m_value = u32char::Null;
if (m_data != nullptr) {
if (m_current > 0) {
int32_t iii = -1;
while( utf8::theoricFirst(m_data->m_data[m_current+iii]) == false
&& iii >= -6
&& m_current-iii>0) {
--iii;
};
m_current += iii;
} else {
m_current = -1;
}
return *this;
} else {
m_current = -1;
}
return *this;
}
char32_t appl::Buffer::Iterator::operator* () {
if (m_value != u32char::Null) {
return m_value;
}
if (m_data == nullptr) {
APPL_ERROR("request an element that iterator not link");
return m_value;
}
if ( m_current < 0
|| m_current >= (int64_t)m_data->m_data.size()) {
APPL_ERROR("request an element out of bounding !!! 0 <= " << m_current << " < " << m_data->m_data.size());
return m_value;
}
char tmpVal[5];
memset(tmpVal, 0, sizeof(tmpVal));
tmpVal[0] = m_data->m_data[m_current];
int8_t nbChar = utf8::theoricLen(tmpVal[0]);
for (int32_t iii=1; iii<nbChar && m_current+iii<(int64_t)m_data->m_data.size(); ++iii) {
tmpVal[iii] = m_data->m_data[m_current+iii];
}
// transform ...
m_value = utf8::convertChar32(tmpVal);
return m_value;
}
appl::Buffer::Iterator appl::Buffer::position(int64_t _pos) {
return m_data.begin() + _pos;
return appl::Buffer::Iterator(this, _pos);
}
appl::Buffer::Iterator appl::Buffer::begin() {
return m_data.begin();
return position(0);
}
appl::Buffer::Iterator appl::Buffer::end() {
// TODO : chek the validity of the char ...
return m_data.end();
return position( m_data.size() );
}
appl::Buffer::Iterator appl::Buffer::cursor() {
if (m_cursorPos<= 0) {
return m_data.begin();
return begin();
}
return m_data.begin() + m_cursorPos;
return position( m_cursorPos );
}
appl::Buffer::Iterator appl::Buffer::selectStart() {
return m_data.begin() + getStartSelectionPos();
return position( getStartSelectionPos() );
}
appl::Buffer::Iterator appl::Buffer::selectStop() {
return m_data.begin() + getStopSelectionPos();
return position( getStopSelectionPos() );
}
appl::Buffer::Buffer() :
@ -84,15 +152,20 @@ bool appl::Buffer::loadFile(const std::string& _name) {
m_cursorPos = 0;
setHighlightType("");
m_nbLines = 0;
etk::FSNode filee(m_fileName);
if (filee.exist() == true) {
m_data = file.fileReadAllU32String();
countNumberofLine();
tryFindHighlightType();
m_isModify = false;
return true;
if (file.exist() == false) {
APPL_ERROR("File : '" << m_fileName << "' does not exist...");
return false;
}
return false;
if (file.fileOpenRead() == false) {
APPL_ERROR("File : '" << m_fileName << "' Fail to open in read mode");
return false;
}
m_data = file.fileReadAllString();
file.fileClose();
countNumberofLine();
tryFindHighlightType();
m_isModify = false;
return true;
}
void appl::Buffer::setFileName(const std::string& _name) {
@ -109,8 +182,13 @@ void appl::Buffer::setFileName(const std::string& _name) {
}
bool appl::Buffer::storeFile() {
etk::FSNode filee(m_fileName);
filee.fileWriteAll(m_data);
etk::FSNode file(m_fileName);
if (file.fileOpenWrite() == false) {
APPL_ERROR("File : '" << m_fileName << "' Fail to open in write mode");
return false;
}
file.fileWriteAll(m_data);
file.fileClose();
APPL_INFO("saving file : " << m_fileName);
setModification(false);
return true;
@ -131,8 +209,10 @@ void appl::Buffer::setModification(bool _status) {
// TODO : Naming error
void appl::Buffer::countNumberofLine() {
m_nbLines = 1;
for (auto &it : m_data) {
if (it == u32char::Return) {
for (Iterator it = begin();
(bool)it == true;
++it) {
if (*it == u32char::Return) {
++m_nbLines;
}
}
@ -161,21 +241,21 @@ appl::Buffer::Iterator appl::Buffer::getEndLine(const appl::Buffer::Iterator& _p
bool appl::Buffer::search(const appl::Buffer::Iterator& _pos, const char32_t& _search, appl::Buffer::Iterator& _result) {
// move in the string
for (Iterator it = _pos;
it != m_data.end();
(bool)it == true;
++it) {
if (*it == _search) {
_result = it;
return true;
}
}
_result = m_data.end();
_result = end();
return false;
}
bool appl::Buffer::searchBack(const appl::Buffer::Iterator& _pos, const char32_t& _search, appl::Buffer::Iterator& _result) {
// move in the string
for (Iterator it = _pos - 1;
it != m_data.begin();
(bool)it == true;
--it) {
//APPL_DEBUG("compare : " << *it << " ?= " << _search);
if (*it == _search) {
@ -198,7 +278,7 @@ bool appl::Buffer::search(const appl::Buffer::Iterator& _pos,
if (_caseSensitive == true) {
// move in the string
for (Iterator it = _pos;
it == m_data.end();
(bool)it == true;
++it) {
if (*it == _search[0]) {
// find the first char ==> check next...
@ -210,7 +290,7 @@ bool appl::Buffer::search(const appl::Buffer::Iterator& _pos,
break;
}
++tmp;
if (tmp == m_data.end()) {
if ((bool)tmp == false) {
if (iii != _search.size()-1) {
find = false;
}
@ -227,7 +307,7 @@ bool appl::Buffer::search(const appl::Buffer::Iterator& _pos,
char32_t firstElement = tolower(_search[0]);
// move in the string
for (Iterator it = _pos;
it == m_data.end();
(bool)it == true;
++it) {
if ((char32_t)tolower(*it) == firstElement) {
// find the first char ==> check next...
@ -239,7 +319,7 @@ bool appl::Buffer::search(const appl::Buffer::Iterator& _pos,
break;
}
++tmp;
if (tmp != m_data.end()) {
if ((bool)tmp == false) {
if (iii != _search.size()-1) {
find = false;
}
@ -268,7 +348,7 @@ bool appl::Buffer::searchBack(const appl::Buffer::Iterator& _pos,
if (_caseSensitive == true) {
// move in the string
for (Iterator it = _pos - 1;
it != m_data.begin();
(bool)it == true;
--it) {
//APPL_DEBUG("compare : " << *it << " ?= " << _search);
if (*it == lastElement) {
@ -281,7 +361,7 @@ bool appl::Buffer::searchBack(const appl::Buffer::Iterator& _pos,
break;
}
--_result;
if (_result == m_data.begin()) {
if ((bool)_result == false) {
if (iii != 0) {
find = false;
}
@ -298,7 +378,7 @@ bool appl::Buffer::searchBack(const appl::Buffer::Iterator& _pos,
lastElement = tolower(lastElement);
// move in the string
for (Iterator it = _pos - 1;
it != m_data.begin();
(bool)it == true;
--it) {
//APPL_DEBUG("compare : " << *it << " ?= " << _search);
if ((char32_t)tolower(*it) == lastElement) {
@ -311,7 +391,7 @@ bool appl::Buffer::searchBack(const appl::Buffer::Iterator& _pos,
break;
}
--_result;
if (_result == m_data.begin()) {
if ((bool)_result == false) {
if (iii != 0) {
find = false;
}
@ -357,15 +437,15 @@ void appl::Buffer::moveCursor(int64_t _pos) {
bool appl::Buffer::getPosAround(const appl::Buffer::Iterator& _startPos,
appl::Buffer::Iterator &_beginPos,
appl::Buffer::Iterator &_endPos) {
char32_t currentValue = *_startPos;
char32_t currentValue = *position(_startPos);
_beginPos = begin();
_endPos = end();
if ( currentValue == u32char::Tabulation
|| currentValue == u32char::Space) {
APPL_DEBUG("select spacer");
// Search back
for (Iterator it = --Iterator(_startPos);
it != m_data.begin();
for (Iterator it = --position(_startPos);
(bool)it == true;
--it) {
currentValue = *it;
if ( currentValue != u32char::Tabulation
@ -375,8 +455,8 @@ bool appl::Buffer::getPosAround(const appl::Buffer::Iterator& _startPos,
}
}
// Search forward
for (Iterator it = _startPos;
it != m_data.end();
for (Iterator it = position(_startPos);
(bool)it == true;
++it) {
currentValue = *it;
if ( currentValue != u32char::Tabulation
@ -390,8 +470,8 @@ bool appl::Buffer::getPosAround(const appl::Buffer::Iterator& _startPos,
|| currentValue == '_') {
APPL_DEBUG("select normal Char");
// Search back
for (Iterator it = --Iterator(_startPos);
it == m_data.begin();
for (Iterator it = --position(_startPos);
(bool)it == true;
--it) {
currentValue = *it;
if ( currentValue != '_'
@ -401,8 +481,8 @@ bool appl::Buffer::getPosAround(const appl::Buffer::Iterator& _startPos,
}
}
// Search forward
for (Iterator it = _startPos;
it != m_data.end();
for (Iterator it = position(_startPos);
(bool)it == true;
++it) {
currentValue = *it;
if ( currentValue != '_'
@ -416,8 +496,8 @@ bool appl::Buffer::getPosAround(const appl::Buffer::Iterator& _startPos,
APPL_DEBUG("select same char");
char32_t comparechar = currentValue;
// Search back
for (Iterator it = --Iterator(_startPos);
it == m_data.begin();
for (Iterator it = --position(_startPos);
(bool)it == true;
--it) {
currentValue = *it;
if (comparechar != currentValue) {
@ -426,8 +506,8 @@ bool appl::Buffer::getPosAround(const appl::Buffer::Iterator& _startPos,
}
}
// Search forward
for (Iterator it = --Iterator(_startPos);
it != m_data.end();
for (Iterator it = position(_startPos);
(bool)it == true;
++it) {
currentValue = *it;
if (comparechar != currentValue) {
@ -437,13 +517,13 @@ bool appl::Buffer::getPosAround(const appl::Buffer::Iterator& _startPos,
}
return true;
}
_beginPos = m_data.begin();
_endPos = m_data.begin();
_beginPos = begin();
_endPos = begin();
return false;
}
void appl::Buffer::setSelectionPos(const appl::Buffer::Iterator& _pos) {
m_cursorSelectPos = std::distance(m_data.begin(), _pos);
m_cursorSelectPos = _pos;
signalSelectChange.emit();
}
@ -499,8 +579,8 @@ appl::Buffer::Iterator appl::Buffer::countForwardNLines(const appl::Buffer::Iter
char32_t value;
int32_t lineCount = 0;
//APPL_INFO("startPos=" << startPos << " nLines=" << nLines);
for (Iterator it = Iterator(_startPos);
it != m_data.end();
for (Iterator it = position(_startPos);
(bool)it == true;
++it) {
value = *it;
if (value == u32char::Return) {
@ -519,8 +599,8 @@ appl::Buffer::Iterator appl::Buffer::countBackwardNLines(const appl::Buffer::Ite
//APPL_INFO("startPos=" << startPos << " nLines=" << nLines);
char32_t value;
int32_t lineCount = 0;
for (Iterator it = --Iterator(_startPos);
it != m_data.begin();
for (Iterator it = --position(_startPos);
(bool)it == true;
--it) {
value = *it;
if (value == u32char::Return) {
@ -544,7 +624,7 @@ bool appl::Buffer::copy(std::string& _data) {
int32_t endPos = getStopSelectionPos();
for (Iterator it = position(startPos);
it != position(endPos) &&
it != m_data.end();
(bool)it == true;
++it) {
_data += *it;
}
@ -557,33 +637,39 @@ void appl::Buffer::copy(std::string& _data, const appl::Buffer::Iterator& _pos,
_data.clear();
for (Iterator it = _pos;
it != _posEnd &&
it != m_data.end();
(bool)it == true;
++it) {
_data += *it;
}
}
bool appl::Buffer::write(const std::string& _data, const appl::Buffer::Iterator& _pos) {
std::u32string data2 = utf8::convertUnicode(_data);
APPL_VERBOSE("write at pos: " << std::distance(m_data.begin(), _pos) << " data : " << data2);
m_data.insert(_pos, data2.begin(), data2.end());
int64_t position = (int64_t)_pos;
if (position < 0){
position = 0;
}
APPL_VERBOSE("write at pos: " << (int64_t)_pos << " ==> " << position << " data : " << _data);
m_data.insert((size_t)position, _data);
if (m_cursorPos < 0) {
m_cursorPos = 0;
}
regenerateHighLightAt(std::distance(m_data.begin(), _pos), 0, data2.size());
regenerateHighLightAt(position, 0, _data.size());
m_selectMode = false;
moveCursor(std::distance(m_data.begin(),_pos+data2.size()));
moveCursor(position+_data.size());
countNumberofLine(); // TODO : use more intelligent counter
setModification(true);
return true;
}
bool appl::Buffer::replace(const std::string& _data, const appl::Buffer::Iterator& _pos, const appl::Buffer::Iterator& _posEnd) {
std::u32string data2 = utf8::convertUnicode(_data);
m_data.replace(_pos, _posEnd, data2.c_str(), data2.size());
regenerateHighLightAt(std::distance(m_data.begin(),_pos), std::distance(m_data.begin(),_posEnd)-std::distance(m_data.begin(),_pos), data2.size());
int64_t position = (int64_t)_pos;
if (position < 0){
position = 0;
}
m_data.replace(m_data.begin() + position, m_data.begin() + (int64_t)_posEnd, _data.begin(), _data.end());
regenerateHighLightAt(position, (int64_t)_posEnd-(int64_t)_pos, _data.size());
m_selectMode = false;
moveCursor(std::distance(m_data.begin(),_pos+data2.size()));
moveCursor(position+_data.size());
countNumberofLine(); // TODO : use more intelligent counter
setModification(true);
return true;
@ -817,13 +903,13 @@ void appl::Buffer::hightlightGenerateLines(appl::DisplayHLData& _MData, const ap
//int64_t timeStart = ewol::getTime();
appl::Buffer::Iterator HLStartLine = getStartLine(_HLStart);
int64_t HLStartPos = std::distance(m_data.begin(),HLStartLine);
int64_t HLStartPos = (int64_t)HLStartLine;
_MData.HLData.clear();
int64_t HLStop = std::distance(m_data.begin(),countForwardNLines(HLStartLine, _nbLines));
int64_t HLStop = (int64_t)countForwardNLines(HLStartLine, _nbLines);
int64_t startId = 0;
int64_t stopId = 0;
// find element previous
findMainHighLightPosition(std::distance(m_data.begin(),_HLStart), HLStop, startId, stopId, true);
findMainHighLightPosition(_HLStart, HLStop, startId, stopId, true);
//APPL_DEBUG("List of section between : "<< startId << " & " << stopId);
int64_t endSearch = stopId+1;
@ -904,7 +990,7 @@ uint32_t appl::Buffer::getCursorLinesId() {
}
uint32_t line = 0;
for (Iterator it = begin();
it != m_data.end() && it <= cursor();
(bool)it == true && it <= cursor();
++it) {
if (*it == u32char::Return) {
++line;

View File

@ -29,7 +29,265 @@ namespace appl {
};
class Buffer : public ewol::Object {
public:
using Iterator = std::u32string::iterator;
class Iterator {
// Private data :
private:
int64_t m_current; //!< curent Id in the Buffer
appl::Buffer* m_data; //!< Pointer on the curent Buffer
char32_t m_value; //!< store vlue to prevent multiple calcule of getting the data
public:
/**
* @brief Basic itarator constructor with no link.
*/
Iterator():
m_current(0),
m_data(nullptr),
m_value(u32char::Null) {
// nothing to do ...
};
/**
* @brief Recopy constructor.
* @param[in] _obj The Iterator that might be copy
*/
Iterator(const Iterator & _obj):
m_current(_obj.m_current),
m_data(_obj.m_data),
m_value(u32char::Null) {
// nothing to do ...
};
/**
* @brief Asignation operator.
* @param[in] _otherIterator The Iterator that might be copy
* @return reference on the curent Iterator
*/
Iterator& operator=(const Iterator & _obj) {
m_current = _obj.m_current;
m_data = _obj.m_data;
m_value = u32char::Null;
return *this;
};
/**
* @brief Basic destructor
*/
virtual ~Iterator() {
m_current = 0;
m_data = nullptr;
m_value = u32char::Null;
};
/**
* @brief basic boolean cast
* @return true if the element is present in buffer
*/
operator bool () const {
if (m_data == nullptr) {
return false;
}
if (m_current >= (int64_t)m_data->m_data.size()) {
return false;
}
if (m_current < 0) {
return false;
}
return true;
};
/**
* @brief basic boolean cast
* @return true if the element is present in buffer
*/
operator int64_t () const {
if (m_data == nullptr) {
return 0;
}
if (m_current < 0) {
return 0;
}
if (m_current > (int64_t)m_data->m_data.size()) {
return (int64_t)m_data->m_data.size();
}
return m_current;
};
/**
* @brief Incremental operator
* @return Reference on the current iterator incremented
*/
Iterator& operator++ ();
/**
* @brief Decremental operator
* @return Reference on the current iterator decremented
*/
Iterator& operator-- ();
/**
* @brief Incremental operator
* @return Reference on a new iterator and increment the other one
*/
Iterator operator++ (int32_t) {
Iterator it(*this);
++(*this);
return it;
};
/**
* @brief Decremental operator
* @return Reference on a new iterator and decrement the other one
*/
Iterator operator-- (int32_t) {
Iterator it(*this);
--(*this);
return it;
};
/**
* @brief egality iterator
* @return true if the iterator is identical pos
*/
bool operator== (const Iterator& _obj) const {
if ( m_current == _obj.m_current
&& m_data == _obj.m_data) {
return true;
}
return false;
};
/**
* @brief egality iterator
* @return true if the iterator is identical pos
*/
bool operator!= (const Iterator& _obj) const {
if ( m_current != _obj.m_current
|| m_data != _obj.m_data) {
return true;
}
return false;
};
/**
* @brief <= iterator
* @return true if the iterator is identical pos
*/
bool operator<= (const Iterator& _obj) const {
if (m_data != _obj.m_data) {
return false;
}
if (m_current <= _obj.m_current) {
return true;
}
return false;
};
/**
* @brief >= iterator
* @return true if the iterator is identical pos
*/
bool operator>= (const Iterator& _obj) const {
if (m_data != _obj.m_data) {
return false;
}
if (m_current >= _obj.m_current) {
return true;
}
return false;
};
/**
* @brief < iterator
* @return true if the iterator is identical pos
*/
bool operator< (const Iterator& _obj) const {
if (m_data != _obj.m_data) {
return false;
}
if (m_current < _obj.m_current) {
return true;
}
return false;
};
/**
* @brief > iterator
* @return true if the iterator is identical pos
*/
bool operator> (const Iterator& _obj) const {
if (m_data != _obj.m_data) {
return false;
}
if (m_current > _obj.m_current) {
return true;
}
return false;
};
/**
* @brief Get the value on the current element
* @return The request element value
*/
char32_t operator* ();
/**
* @brief Get the position in the buffer
* @return The requested position.
*/
int64_t getPos() const {
if (m_data == nullptr) {
return 0;
}
if (m_current < 0) {
return 0;
}
if (m_current >= (int64_t)m_data->m_data.size()) {
return m_data->m_data.size()-1;
}
return m_current;
};
/**
* @brief move the element position
* @return a new iterator.
*/
Iterator operator+ (const int64_t _val) const {
Iterator tmpp(*this);
for (int64_t iii=0; iii<_val; ++iii) {
++tmpp;
}
return tmpp;
};
Iterator operator+ (const int32_t _val) const {
Iterator tmpp(*this);
for (int64_t iii=0; iii<_val; ++iii) {
++tmpp;
}
return tmpp;
};
Iterator operator+ (const size_t _val) const {
Iterator tmpp(*this);
for (int64_t iii=0; iii<(int64_t)_val; ++iii) {
++tmpp;
}
return tmpp;
};
/**
* @brief move the element position
* @return a new iterator.
*/
Iterator operator- (const int64_t _val) const {
Iterator tmpp(*this);
for (int64_t iii=0; iii<_val; ++iii) {
--tmpp;
}
return tmpp;
};
Iterator operator- (const int32_t _val) const {
Iterator tmpp(*this);
for (int64_t iii=0; iii<_val; ++iii) {
--tmpp;
}
return tmpp;
};
Iterator operator- (const size_t _val) const {
Iterator tmpp(*this);
for (int64_t iii=0; iii<(int64_t)_val; ++iii) {
--tmpp;
}
return tmpp;
};
private:
Iterator(Buffer* _obj, int64_t _pos) :
m_current(_pos),
m_data(_obj),
m_value(u32char::Null) {
// nothing to do ...
};
friend class Buffer;
};
public:
ewol::object::Signal<void> signalIsModify;
ewol::object::Signal<void> signalIsSave;
@ -90,9 +348,9 @@ namespace appl {
*/
void setModification(bool _status);
protected:
std::u32string m_data; //!< copy of the file buffer
std::string m_data; //!< copy of the file buffer
public:
std::u32string& getData() {
std::string& getData() {
return m_data;
};
protected:

View File

@ -222,7 +222,7 @@ void appl::TextViewer::onRegenerateDisplay() {
int64_t startLineId = 0;
if (m_size.y() < m_displayText.getPos().y()) {
for (startingIt = m_buffer->begin();
startingIt != m_buffer->end();
(bool)startingIt == true;
++startingIt) {
if (*startingIt == u32char::Return) {
++startLineId;
@ -275,7 +275,7 @@ void appl::TextViewer::onRegenerateDisplay() {
bool DisplayCursorAndSelection = isSelectedLast();
appl::Buffer::Iterator it;
for (it = startingIt;
it != m_buffer->end();
(bool)it == true;
++it) {
if (it == m_buffer->cursor()) {
// need to display the cursor :
@ -307,7 +307,7 @@ void appl::TextViewer::onRegenerateDisplay() {
}
continue;
}
HLColor = m_buffer->getElementColorAtPosition(displayLocalSyntax, std::distance(m_buffer->begin(),it));
HLColor = m_buffer->getElementColorAtPosition(displayLocalSyntax, (int64_t)it);
bool haveBackground = false;
if ( HLColor != nullptr
&& HLColor->patern != nullptr) {
@ -639,7 +639,7 @@ appl::Buffer::Iterator appl::TextViewer::getMousePosition(const vec2& _relativeP
m_displayText.forceLineReturn();
positionCurentDisplay = m_displayText.getPos();
for (appl::Buffer::Iterator it = m_buffer->begin();
it != m_buffer->end();
(bool)it == true;
++it) {
currentValue = *it;
if (currentValue == u32char::Return) {
@ -756,7 +756,7 @@ bool appl::TextViewer::moveCursor(const appl::Buffer::Iterator& _pos) {
updateScrolling();
return true;
}
m_buffer->moveCursor(std::distance(m_buffer->begin(),_pos));
m_buffer->moveCursor((int64_t)_pos);
updateScrolling();
return true;
}
@ -937,7 +937,7 @@ appl::Buffer::Iterator appl::TextViewer::getPosSize(const appl::Buffer::Iterator
m_displayText.clear();
m_displayText.forceLineReturn();
for (appl::Buffer::Iterator it = _startLinePos;
it != m_buffer->end();
(bool)it == true;
++it) {
currentValue = *it;
m_buffer->expand(countColomn, currentValue, stringToDisplay);
@ -965,7 +965,7 @@ float appl::TextViewer::getScreenSize(const appl::Buffer::Iterator& _startLinePo
m_displayText.clear();
for (appl::Buffer::Iterator it = _startLinePos;
it != m_buffer->end() && it <= _stopPos;
(bool)it == true && it <= _stopPos;
++it) {
currentValue = *it;
//APPL_DEBUG("parse : " << currentValue);

View File

@ -168,7 +168,7 @@ void appl::Highlight::parse(int64_t _start,
int64_t _stop,
std::vector<appl::HighlightInfo> & _metaData,
int64_t _addingPos,
std::u32string& _buffer) {
std::string& _buffer) {
if (0 > _addingPos) {
_addingPos = 0;
}
@ -178,6 +178,8 @@ void appl::Highlight::parse(int64_t _start,
appl::HighlightInfo resultat;
while (elementStart <= elementStop) {
HL_DEBUG("Parse element in the buffer pos=" << elementStart);
appl::HighlightInfo resultatLast;
int64_t findAnOtherId = -1;
//try to fond the HL in ALL of we have
for (int64_t jjj=0; jjj<(int64_t)m_listHighlightPass1.size(); jjj++){
enum resultFind ret = HLP_FIND_OK;
@ -185,38 +187,53 @@ void appl::Highlight::parse(int64_t _start,
// 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) {
HL_DEBUG("Find Pattern in the Buffer : (" << resultat.start << "," << resultat.stop << ")" );
// remove element in the current List where the current Element have a end inside the next...
int64_t kkk=_addingPos;
while(kkk < (int64_t)_metaData.size() ) {
if (_metaData[kkk].start <= resultat.stop) {
// remove element
HL_DEBUG("Erase element=" << kkk);
_metaData.erase(_metaData.begin()+kkk, _metaData.begin()+kkk+1);
// Increase the end of search
if (kkk < (int64_t)_metaData.size()) {
// just befor the end of the next element
elementStop = _metaData[kkk].start-1;
} else {
// end of the buffer
elementStop = _buffer.size();
}
} else {
// Not find == > exit the cycle :
break;
if (elementStart == resultat.start) {
APPL_DEBUG("Find Pattern in the Buffer : (" << resultat.start << "," << resultat.stop << ") startPos=" << elementStart );
findAnOtherId = jjj;
resultatLast = resultat;
break;
} else {
// stack last find to prevent a unneded seach:
if ( findAnOtherId == -1
|| resultat.start < resultatLast.start) {
findAnOtherId = jjj;
resultatLast = resultat;
}
}
// add curent element in the list ...
_metaData.insert(_metaData.begin()+_addingPos, resultat);
HL_DEBUG("INSERT at "<< _addingPos << " S=" << resultat.start << " E=" << resultat.stop );
// update the current research starting element: (set position at the end of the current element
elementStart = resultat.stop-1;
// increment the position of insertion:
_addingPos++;
// We find a pattern == > Stop search for the current element
break;
}
}
if (findAnOtherId != -1) {
// remove element in the current List where the current Element have a end inside the next...
int64_t kkk=_addingPos;
while(kkk < (int64_t)_metaData.size() ) {
if (_metaData[kkk].start <= resultatLast.stop) {
// remove element
HL_DEBUG("Erase element=" << kkk);
_metaData.erase(_metaData.begin()+kkk, _metaData.begin()+kkk+1);
// Increase the end of search
if (kkk < (int64_t)_metaData.size()) {
// just befor the end of the next element
elementStop = _metaData[kkk].start-1;
} else {
// end of the buffer
elementStop = _buffer.size();
}
} else {
// Not find == > exit the cycle :
break;
}
}
// add curent element in the list ...
_metaData.insert(_metaData.begin()+_addingPos, resultatLast);
HL_DEBUG("INSERT at "<< _addingPos << " S=" << resultatLast.start << " E=" << resultatLast.stop );
// update the current research starting element: (set position at the end of the current element
elementStart = resultatLast.stop-1;
// increment the position of insertion:
_addingPos++;
// We find a pattern == > Stop search for the current element
} else {
break;
}
// Go to the next element (and search again ...).
elementStart++;
}
@ -230,7 +247,7 @@ void appl::Highlight::parse(int64_t _start,
void appl::Highlight::parse2(int64_t _start,
int64_t _stop,
std::vector<appl::HighlightInfo> &_metaData,
std::u32string&_buffer) {
std::string&_buffer) {
HL2_DEBUG("Parse element 0 => " << m_listHighlightPass2.size() <<
" == > position search: (" << _start << "," << _stop << ")" );
int64_t elementStart = _start;

View File

@ -55,11 +55,11 @@ namespace appl {
int64_t _stop,
std::vector<appl::HighlightInfo> &_metaData,
int64_t _addingPos,
std::u32string &_buffer);
std::string &_buffer);
void parse2(int64_t _start,
int64_t _stop,
std::vector<appl::HighlightInfo> &_metaData,
std::u32string &_buffer);
std::string &_buffer);
private:
void parseRules(exml::Element* _child,
std::vector<std::unique_ptr<HighlightPattern>> &_mListPatern,

View File

@ -16,6 +16,8 @@
appl::HighlightPattern::HighlightPattern(const std::shared_ptr<appl::GlyphPainting>& _glyphPainting) :
m_glyphPainting(_glyphPainting),
m_paternName(""),
m_hasParsingError(true),
m_regexValue(""),
m_regExp(),
m_colorName(""),
m_level(0) {
@ -28,13 +30,13 @@ appl::HighlightPattern::~HighlightPattern() {
void appl::HighlightPattern::setPatern(const std::string& _regExp, bool forceMaximize) {
m_regexValue = _regExp;
const std::u32string data = utf8::convertUnicode(_regExp);
const std::u32string data2 = U"kjhkjhk";
const std::string data3 = "kjhkjhk";
//std::basic_regex<char32_t, std::u32string> regexp(data2);
std::basic_regex<char32_t> regexp((const char32_t*)data2.c_str());
//m_regExp.assign((const std::u32string)data);
//m_regExp.assign(_regExp);
try {
m_regExp.assign(_regExp);
m_hasParsingError = false;
} catch (std::regex_error e) {
m_hasParsingError = true;
APPL_ERROR("can not parse regExp : '" << e.what() << "' for : " << _regExp);
}
//m_regExp.setMaximize(forceMaximize);
}
std::string appl::HighlightPattern::getPaternString() {
@ -97,17 +99,20 @@ void appl::HighlightPattern::parseRules(exml::Element* _child, int32_t _level, b
}
}
typedef std::match_results<std::u32string::const_iterator> s32match;
enum resultFind appl::HighlightPattern::find(int32_t _start,
int32_t _stop,
appl::HighlightInfo& _resultat,
const std::u32string& _buffer) {
int32_t _stop,
appl::HighlightInfo& _resultat,
const std::string& _buffer) {
//APPL_DEBUG(" try to find the element");
_resultat.start = -1;
_resultat.stop = -1;
_resultat.notEnded = false;
_resultat.patern = this;
if (m_hasParsingError == true) {
return HLP_FIND_ERROR;
}
/*
// when we have only one element:
if (true == m_regExp.processOneElement(_buffer, _start, _stop)) {
@ -119,11 +124,13 @@ enum resultFind appl::HighlightPattern::find(int32_t _start,
return HLP_FIND_ERROR;
*/
s32match resultMatch;
std::regex_search(_buffer, resultMatch, m_regExp);
std::smatch resultMatch;
//APPL_DEBUG("find data at : start=" << _start << " stop=" << _stop << " regex='" << m_regexValue << "'");
std::regex_search(_buffer.begin() + _start, _buffer.begin() + _stop, resultMatch, m_regExp);
if (resultMatch.size() > 0) {
_resultat.start = std::distance(_buffer.begin(), resultMatch[0].first);;
_resultat.stop = std::distance(_buffer.begin(), resultMatch[0].second);
//APPL_DEBUG("find data at : start=" << _resultat.start << " stop=" << _resultat.stop << " data='" <<std::string(_buffer, _resultat.start, _resultat.stop-_resultat.start) << "'" );
/*
if (false){
TK_DEBUG("in line : '" << etk::to_string(_buffer) << "'");

View File

@ -44,8 +44,9 @@ namespace appl {
return m_paternName;
};
private:
bool m_hasParsingError;
std::string m_regexValue;
std::basic_regex<char32_t> m_regExp; //!< Start of Regular expression
std::regex m_regExp; //!< Start of Regular expression
public:
void setPatern(const std::string& _regExp, bool forceMaximize=false);
std::string getPaternString();
@ -83,7 +84,7 @@ namespace appl {
enum resultFind find(int32_t _start,
int32_t _stop,
appl::HighlightInfo& _resultat,
const std::u32string& _buffer);
const std::string& _buffer);
void parseRules(exml::Element* _child, int32_t _level, bool forceMaximize=false);
};