[DEV] {remove etk regexp dependency} big rework in progress to simplify code and use real std::regex templates

This commit is contained in:
Edouard DUPIN 2014-10-03 00:49:26 +02:00
parent b890f931ca
commit febbaffdf4
2 changed files with 31 additions and 358 deletions

View File

@ -17,101 +17,33 @@
#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 < 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 >= 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 >= 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<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 appl::Buffer::Iterator(this, _pos);
return m_data.begin() + _pos;
}
appl::Buffer::Iterator appl::Buffer::begin() {
return position(0);
return m_data.begin();
}
appl::Buffer::Iterator appl::Buffer::end() {
// TODO : chek the validity of the char ...
return position( m_data.size() );
return m_data.end();
}
appl::Buffer::Iterator appl::Buffer::cursor() {
if (m_cursorPos<= 0) {
return begin();
return m_data.begin();
}
return position( m_cursorPos );
return m_data.begin() + m_cursorPos;
}
appl::Buffer::Iterator appl::Buffer::selectStart() {
return position( getStartSelectionPos() );
return m_data.begin() + getStartSelectionPos();
}
appl::Buffer::Iterator appl::Buffer::selectStop() {
return position( getStopSelectionPos() );
return m_data.begin() + getStopSelectionPos();
}
appl::Buffer::Buffer() :
@ -152,7 +84,9 @@ bool appl::Buffer::loadFile(const std::string& _name) {
m_cursorPos = 0;
setHighlightType("");
m_nbLines = 0;
if (m_data.dumpFrom(m_fileName) == true ) {
etk::FSNode filee(m_fileName);
if (filee.exist() == true) {
m_data = file.fileReadAllU32String();
countNumberofLine();
tryFindHighlightType();
m_isModify = false;
@ -175,12 +109,11 @@ void appl::Buffer::setFileName(const std::string& _name) {
}
bool appl::Buffer::storeFile() {
if (m_data.dumpIn(m_fileName) == true) {
APPL_INFO("saving file : " << m_fileName);
setModification(false);
return true;
}
return false;
etk::FSNode filee(m_fileName);
filee.fileWriteAll(m_data);
APPL_INFO("saving file : " << m_fileName);
setModification(false);
return true;
}
void appl::Buffer::setModification(bool _status) {
@ -198,10 +131,8 @@ void appl::Buffer::setModification(bool _status) {
// TODO : Naming error
void appl::Buffer::countNumberofLine() {
m_nbLines = 1;
for (Iterator it = begin();
(bool)it == true;
++it) {
if (*it == u32char::Return) {
for (auto &it : m_data) {
if (it == u32char::Return) {
++m_nbLines;
}
}
@ -230,21 +161,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;
(bool)it == true;
it != m_data.end();
++it) {
if (*it == _search) {
_result = it;
return true;
}
}
_result = end();
_result = m_data.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;
(bool)it == true;
it != m_data.begin();
--it) {
//APPL_DEBUG("compare : " << *it << " ?= " << _search);
if (*it == _search) {
@ -267,7 +198,7 @@ bool appl::Buffer::search(const appl::Buffer::Iterator& _pos,
if (_caseSensitive == true) {
// move in the string
for (Iterator it = _pos;
(bool)it == true;
it == m_data.end();
++it) {
if (*it == _search[0]) {
// find the first char ==> check next...
@ -279,7 +210,7 @@ bool appl::Buffer::search(const appl::Buffer::Iterator& _pos,
break;
}
++tmp;
if ((bool)tmp == false) {
if (tmp == m_data.end()) {
if (iii != _search.size()-1) {
find = false;
}
@ -296,7 +227,7 @@ bool appl::Buffer::search(const appl::Buffer::Iterator& _pos,
char32_t firstElement = tolower(_search[0]);
// move in the string
for (Iterator it = _pos;
(bool)it == true;
it == m_data.end();
++it) {
if ((char32_t)tolower(*it) == firstElement) {
// find the first char ==> check next...
@ -308,7 +239,7 @@ bool appl::Buffer::search(const appl::Buffer::Iterator& _pos,
break;
}
++tmp;
if ((bool)tmp == false) {
if (tmp != m_data.end()) {
if (iii != _search.size()-1) {
find = false;
}
@ -337,7 +268,7 @@ bool appl::Buffer::searchBack(const appl::Buffer::Iterator& _pos,
if (_caseSensitive == true) {
// move in the string
for (Iterator it = _pos - 1;
(bool)it == true;
it != m_data.begin();
--it) {
//APPL_DEBUG("compare : " << *it << " ?= " << _search);
if (*it == lastElement) {
@ -350,7 +281,7 @@ bool appl::Buffer::searchBack(const appl::Buffer::Iterator& _pos,
break;
}
--_result;
if ((bool)_result == false) {
if (_result == m_data.begin()) {
if (iii != 0) {
find = false;
}
@ -367,7 +298,7 @@ bool appl::Buffer::searchBack(const appl::Buffer::Iterator& _pos,
lastElement = tolower(lastElement);
// move in the string
for (Iterator it = _pos - 1;
(bool)it == true;
it != m_data.begin();
--it) {
//APPL_DEBUG("compare : " << *it << " ?= " << _search);
if ((char32_t)tolower(*it) == lastElement) {
@ -380,7 +311,7 @@ bool appl::Buffer::searchBack(const appl::Buffer::Iterator& _pos,
break;
}
--_result;
if ((bool)_result == false) {
if (_result == m_data.begin()) {
if (iii != 0) {
find = false;
}

View File

@ -29,265 +29,7 @@ namespace appl {
};
class Buffer : public ewol::Object {
public:
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 >= 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 > m_data->m_data.size()) {
return 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 >= 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;
};
using Iterator = std::u32string::iterator;
public:
ewol::object::Signal<void> signalIsModify;
ewol::object::Signal<void> signalIsSave;
@ -348,9 +90,9 @@ namespace appl {
*/
void setModification(bool _status);
protected:
etk::Buffer m_data; //!< copy of the file buffer
std::u32string m_data; //!< copy of the file buffer
public:
etk::Buffer& getData() {
std::u32string& getData() {
return m_data;
};
protected: