[ERROR] Abandonned version in std::u32string ==> unexistant regexp

This commit is contained in:
Edouard DUPIN 2014-10-03 21:44:13 +02:00
parent febbaffdf4
commit 154351e629
6 changed files with 94 additions and 70 deletions

View File

@ -357,15 +357,15 @@ void appl::Buffer::moveCursor(int64_t _pos) {
bool appl::Buffer::getPosAround(const appl::Buffer::Iterator& _startPos, bool appl::Buffer::getPosAround(const appl::Buffer::Iterator& _startPos,
appl::Buffer::Iterator &_beginPos, appl::Buffer::Iterator &_beginPos,
appl::Buffer::Iterator &_endPos) { appl::Buffer::Iterator &_endPos) {
char32_t currentValue = *position(_startPos); char32_t currentValue = *_startPos;
_beginPos = begin(); _beginPos = begin();
_endPos = end(); _endPos = end();
if ( currentValue == u32char::Tabulation if ( currentValue == u32char::Tabulation
|| currentValue == u32char::Space) { || currentValue == u32char::Space) {
APPL_DEBUG("select spacer"); APPL_DEBUG("select spacer");
// Search back // Search back
for (Iterator it = --position(_startPos); for (Iterator it = --Iterator(_startPos);
(bool)it == true; it != m_data.begin();
--it) { --it) {
currentValue = *it; currentValue = *it;
if ( currentValue != u32char::Tabulation if ( currentValue != u32char::Tabulation
@ -375,8 +375,8 @@ bool appl::Buffer::getPosAround(const appl::Buffer::Iterator& _startPos,
} }
} }
// Search forward // Search forward
for (Iterator it = position(_startPos); for (Iterator it = _startPos;
(bool)it == true; it != m_data.end();
++it) { ++it) {
currentValue = *it; currentValue = *it;
if ( currentValue != u32char::Tabulation if ( currentValue != u32char::Tabulation
@ -390,8 +390,8 @@ bool appl::Buffer::getPosAround(const appl::Buffer::Iterator& _startPos,
|| currentValue == '_') { || currentValue == '_') {
APPL_DEBUG("select normal Char"); APPL_DEBUG("select normal Char");
// Search back // Search back
for (Iterator it = --position(_startPos); for (Iterator it = --Iterator(_startPos);
(bool)it == true; it == m_data.begin();
--it) { --it) {
currentValue = *it; currentValue = *it;
if ( currentValue != '_' if ( currentValue != '_'
@ -401,8 +401,8 @@ bool appl::Buffer::getPosAround(const appl::Buffer::Iterator& _startPos,
} }
} }
// Search forward // Search forward
for (Iterator it = position(_startPos); for (Iterator it = _startPos;
(bool)it == true; it != m_data.end();
++it) { ++it) {
currentValue = *it; currentValue = *it;
if ( currentValue != '_' if ( currentValue != '_'
@ -416,8 +416,8 @@ bool appl::Buffer::getPosAround(const appl::Buffer::Iterator& _startPos,
APPL_DEBUG("select same char"); APPL_DEBUG("select same char");
char32_t comparechar = currentValue; char32_t comparechar = currentValue;
// Search back // Search back
for (Iterator it = --position(_startPos); for (Iterator it = --Iterator(_startPos);
(bool)it == true; it == m_data.begin();
--it) { --it) {
currentValue = *it; currentValue = *it;
if (comparechar != currentValue) { if (comparechar != currentValue) {
@ -426,8 +426,8 @@ bool appl::Buffer::getPosAround(const appl::Buffer::Iterator& _startPos,
} }
} }
// Search forward // Search forward
for (Iterator it = position(_startPos); for (Iterator it = --Iterator(_startPos);
(bool)it == true; it != m_data.end();
++it) { ++it) {
currentValue = *it; currentValue = *it;
if (comparechar != currentValue) { if (comparechar != currentValue) {
@ -437,13 +437,13 @@ bool appl::Buffer::getPosAround(const appl::Buffer::Iterator& _startPos,
} }
return true; return true;
} }
_beginPos = begin(); _beginPos = m_data.begin();
_endPos = begin(); _endPos = m_data.begin();
return false; return false;
} }
void appl::Buffer::setSelectionPos(const appl::Buffer::Iterator& _pos) { void appl::Buffer::setSelectionPos(const appl::Buffer::Iterator& _pos) {
m_cursorSelectPos = _pos; m_cursorSelectPos = std::distance(m_data.begin(), _pos);
signalSelectChange.emit(); signalSelectChange.emit();
} }
@ -499,8 +499,8 @@ appl::Buffer::Iterator appl::Buffer::countForwardNLines(const appl::Buffer::Iter
char32_t value; char32_t value;
int32_t lineCount = 0; int32_t lineCount = 0;
//APPL_INFO("startPos=" << startPos << " nLines=" << nLines); //APPL_INFO("startPos=" << startPos << " nLines=" << nLines);
for (Iterator it = position(_startPos); for (Iterator it = Iterator(_startPos);
(bool)it == true; it != m_data.end();
++it) { ++it) {
value = *it; value = *it;
if (value == u32char::Return) { if (value == u32char::Return) {
@ -519,8 +519,8 @@ appl::Buffer::Iterator appl::Buffer::countBackwardNLines(const appl::Buffer::Ite
//APPL_INFO("startPos=" << startPos << " nLines=" << nLines); //APPL_INFO("startPos=" << startPos << " nLines=" << nLines);
char32_t value; char32_t value;
int32_t lineCount = 0; int32_t lineCount = 0;
for (Iterator it = --position(_startPos); for (Iterator it = --Iterator(_startPos);
(bool)it == true; it != m_data.begin();
--it) { --it) {
value = *it; value = *it;
if (value == u32char::Return) { if (value == u32char::Return) {
@ -544,7 +544,7 @@ bool appl::Buffer::copy(std::string& _data) {
int32_t endPos = getStopSelectionPos(); int32_t endPos = getStopSelectionPos();
for (Iterator it = position(startPos); for (Iterator it = position(startPos);
it != position(endPos) && it != position(endPos) &&
(bool)it == true; it != m_data.end();
++it) { ++it) {
_data += *it; _data += *it;
} }
@ -557,39 +557,33 @@ void appl::Buffer::copy(std::string& _data, const appl::Buffer::Iterator& _pos,
_data.clear(); _data.clear();
for (Iterator it = _pos; for (Iterator it = _pos;
it != _posEnd && it != _posEnd &&
(bool)it == true; it != m_data.end();
++it) { ++it) {
_data += *it; _data += *it;
} }
} }
bool appl::Buffer::write(const std::string& _data, const appl::Buffer::Iterator& _pos) { bool appl::Buffer::write(const std::string& _data, const appl::Buffer::Iterator& _pos) {
int64_t position = (int64_t)_pos; std::u32string data2 = utf8::convertUnicode(_data);
if (position < 0){ APPL_VERBOSE("write at pos: " << std::distance(m_data.begin(), _pos) << " data : " << data2);
position = 0; m_data.insert(_pos, data2.begin(), data2.end());
}
APPL_VERBOSE("write at pos: " << (int64_t)_pos << " ==> " << position << " data : " << _data);
m_data.insert(position, (int8_t*)(_data.c_str()), _data.size());
if (m_cursorPos < 0) { if (m_cursorPos < 0) {
m_cursorPos = 0; m_cursorPos = 0;
} }
regenerateHighLightAt(position, 0, _data.size()); regenerateHighLightAt(std::distance(m_data.begin(), _pos), 0, data2.size());
m_selectMode = false; m_selectMode = false;
moveCursor(position+_data.size()); moveCursor(std::distance(m_data.begin(),_pos+data2.size()));
countNumberofLine(); // TODO : use more intelligent counter countNumberofLine(); // TODO : use more intelligent counter
setModification(true); setModification(true);
return true; return true;
} }
bool appl::Buffer::replace(const std::string& _data, const appl::Buffer::Iterator& _pos, const appl::Buffer::Iterator& _posEnd) { bool appl::Buffer::replace(const std::string& _data, const appl::Buffer::Iterator& _pos, const appl::Buffer::Iterator& _posEnd) {
int64_t position = (int64_t)_pos; std::u32string data2 = utf8::convertUnicode(_data);
if (position < 0){ m_data.replace(_pos, _posEnd, data2.c_str(), data2.size());
position = 0; regenerateHighLightAt(std::distance(m_data.begin(),_pos), std::distance(m_data.begin(),_posEnd)-std::distance(m_data.begin(),_pos), data2.size());
}
m_data.replace(position, (int64_t)_posEnd-(int64_t)_pos, (int8_t*)(_data.c_str()), _data.size());
regenerateHighLightAt(position, (int64_t)_posEnd-(int64_t)_pos, _data.size());
m_selectMode = false; m_selectMode = false;
moveCursor(position+_data.size()); moveCursor(std::distance(m_data.begin(),_pos+data2.size()));
countNumberofLine(); // TODO : use more intelligent counter countNumberofLine(); // TODO : use more intelligent counter
setModification(true); setModification(true);
return true; return true;
@ -601,7 +595,7 @@ void appl::Buffer::removeSelection() {
} }
int64_t startPos = getStartSelectionPos(); int64_t startPos = getStartSelectionPos();
int64_t endPos = getStopSelectionPos(); int64_t endPos = getStopSelectionPos();
m_data.remove(startPos, endPos-startPos); m_data.erase(startPos, endPos-startPos);
regenerateHighLightAt(startPos, endPos-startPos, 0); regenerateHighLightAt(startPos, endPos-startPos, 0);
m_selectMode = false; m_selectMode = false;
moveCursor(startPos); moveCursor(startPos);
@ -823,13 +817,13 @@ void appl::Buffer::hightlightGenerateLines(appl::DisplayHLData& _MData, const ap
//int64_t timeStart = ewol::getTime(); //int64_t timeStart = ewol::getTime();
appl::Buffer::Iterator HLStartLine = getStartLine(_HLStart); appl::Buffer::Iterator HLStartLine = getStartLine(_HLStart);
int64_t HLStartPos = (int64_t)HLStartLine; int64_t HLStartPos = std::distance(m_data.begin(),HLStartLine);
_MData.HLData.clear(); _MData.HLData.clear();
int64_t HLStop = (int64_t)countForwardNLines(HLStartLine, _nbLines); int64_t HLStop = std::distance(m_data.begin(),countForwardNLines(HLStartLine, _nbLines));
int64_t startId = 0; int64_t startId = 0;
int64_t stopId = 0; int64_t stopId = 0;
// find element previous // find element previous
findMainHighLightPosition(_HLStart, HLStop, startId, stopId, true); findMainHighLightPosition(std::distance(m_data.begin(),_HLStart), HLStop, startId, stopId, true);
//APPL_DEBUG("List of section between : "<< startId << " & " << stopId); //APPL_DEBUG("List of section between : "<< startId << " & " << stopId);
int64_t endSearch = stopId+1; int64_t endSearch = stopId+1;
@ -910,7 +904,7 @@ uint32_t appl::Buffer::getCursorLinesId() {
} }
uint32_t line = 0; uint32_t line = 0;
for (Iterator it = begin(); for (Iterator it = begin();
(bool)it == true && it <= cursor(); it != m_data.end() && it <= cursor();
++it) { ++it) {
if (*it == u32char::Return) { if (*it == u32char::Return) {
++line; ++line;

View File

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

View File

@ -168,7 +168,7 @@ void appl::Highlight::parse(int64_t _start,
int64_t _stop, int64_t _stop,
std::vector<appl::HighlightInfo> & _metaData, std::vector<appl::HighlightInfo> & _metaData,
int64_t _addingPos, int64_t _addingPos,
etk::Buffer & _buffer) { std::u32string& _buffer) {
if (0 > _addingPos) { if (0 > _addingPos) {
_addingPos = 0; _addingPos = 0;
} }
@ -230,7 +230,7 @@ void appl::Highlight::parse(int64_t _start,
void appl::Highlight::parse2(int64_t _start, void appl::Highlight::parse2(int64_t _start,
int64_t _stop, int64_t _stop,
std::vector<appl::HighlightInfo> &_metaData, std::vector<appl::HighlightInfo> &_metaData,
etk::Buffer &_buffer) { std::u32string&_buffer) {
HL2_DEBUG("Parse element 0 => " << m_listHighlightPass2.size() << HL2_DEBUG("Parse element 0 => " << m_listHighlightPass2.size() <<
" == > position search: (" << _start << "," << _stop << ")" ); " == > position search: (" << _start << "," << _stop << ")" );
int64_t elementStart = _start; int64_t elementStart = _start;

View File

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

View File

@ -16,25 +16,29 @@
appl::HighlightPattern::HighlightPattern(const std::shared_ptr<appl::GlyphPainting>& _glyphPainting) : appl::HighlightPattern::HighlightPattern(const std::shared_ptr<appl::GlyphPainting>& _glyphPainting) :
m_glyphPainting(_glyphPainting), m_glyphPainting(_glyphPainting),
m_paternName(""), m_paternName(""),
m_regExp(nullptr), m_regExp(),
m_colorName(""), m_colorName(""),
m_level(0) { m_level(0) {
m_regExp = std::unique_ptr<etk::RegExp<etk::Buffer>>(new etk::RegExp<etk::Buffer>());
} }
appl::HighlightPattern::~HighlightPattern() { appl::HighlightPattern::~HighlightPattern() {
} }
void appl::HighlightPattern::setPatern(std::string& _regExp, bool forceMaximize) { void appl::HighlightPattern::setPatern(const std::string& _regExp, bool forceMaximize) {
if (m_regExp == nullptr) { m_regexValue = _regExp;
return; const std::u32string data = utf8::convertUnicode(_regExp);
} const std::u32string data2 = U"kjhkjhk";
m_regExp->compile(_regExp); const std::string data3 = "kjhkjhk";
m_regExp->setMaximize(forceMaximize); //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);
//m_regExp.setMaximize(forceMaximize);
} }
std::string appl::HighlightPattern::getPaternString() { std::string appl::HighlightPattern::getPaternString() {
return m_regExp->getRegExDecorated(); return m_regexValue;
} }
void appl::HighlightPattern::setColorGlyph(std::string& _colorName) { void appl::HighlightPattern::setColorGlyph(std::string& _colorName) {
@ -46,7 +50,8 @@ void appl::HighlightPattern::setColorGlyph(std::string& _colorName) {
void appl::HighlightPattern::display() { void appl::HighlightPattern::display() {
APPL_INFO("patern : '" << m_paternName << "' level=" << m_level ); APPL_INFO("patern : '" << m_paternName << "' level=" << m_level );
APPL_INFO(" == > colorName '" << m_colorName << "'"); APPL_INFO(" == > colorName '" << m_colorName << "'");
APPL_INFO(" == > regExp '" << m_regExp->getRegExp() << "'"); //APPL_INFO(" == > regExp '" << m_regExp.getRegExp() << "'");
APPL_INFO(" == > regExp '" << m_regexValue << "'");
} }
void appl::HighlightPattern::parseRules(exml::Element* _child, int32_t _level, bool forceMaximize) { void appl::HighlightPattern::parseRules(exml::Element* _child, int32_t _level, bool forceMaximize) {
@ -92,23 +97,47 @@ 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, enum resultFind appl::HighlightPattern::find(int32_t _start,
int32_t _stop, int32_t _stop,
appl::HighlightInfo& _resultat, appl::HighlightInfo& _resultat,
etk::Buffer& _buffer) { const std::u32string& _buffer) {
//APPL_DEBUG(" try to find the element"); //APPL_DEBUG(" try to find the element");
_resultat.start = -1; _resultat.start = -1;
_resultat.stop = -1; _resultat.stop = -1;
_resultat.notEnded = false; _resultat.notEnded = false;
_resultat.patern = this; _resultat.patern = this;
/*
// when we have only one element: // when we have only one element:
if (true == m_regExp->processOneElement(_buffer, _start, _stop)) { if (true == m_regExp.processOneElement(_buffer, _start, _stop)) {
_resultat.start = m_regExp->start(); _resultat.start = m_regExp->start();
_resultat.stop = m_regExp->stop(); _resultat.stop = m_regExp->stop();
return HLP_FIND_OK; return HLP_FIND_OK;
} }
//APPL_DEBUG("NOT find hightlightpatern ..."); //APPL_DEBUG("NOT find hightlightpatern ...");
return HLP_FIND_ERROR; return HLP_FIND_ERROR;
*/
s32match resultMatch;
std::regex_search(_buffer, 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);
/*
if (false){
TK_DEBUG("in line : '" << etk::to_string(_buffer) << "'");
TK_DEBUG(" Find " << resultMatch.size() << " elements");
for (size_t iii=0; iii<resultMatch.size(); ++iii) {
int32_t posStart = std::distance(_buffer.begin(), resultMatch[iii].first);
int32_t posStop = std::distance(_buffer.begin(), resultMatch[iii].second);
TK_DEBUG(" [" << iii << "] " << *resultMatch[iii].first);
TK_DEBUG(" [" << iii << "] " << *resultMatch[iii].second);
TK_DEBUG(" [" << iii << "] " << etk::to_string(std::u32string(_buffer, posStart, posStop-posStart)));
}
}
*/
return HLP_FIND_OK;
}
return HLP_FIND_ERROR;
} }

View File

@ -14,9 +14,9 @@
class HighlightPattern; class HighlightPattern;
#include <etk/RegExp.h>
#include <appl/GlyphPainting.h> #include <appl/GlyphPainting.h>
#include <vector> #include <vector>
#include <regex>
#include <exml/exml.h> #include <exml/exml.h>
#include <etk/Buffer.h> #include <etk/Buffer.h>
@ -44,9 +44,10 @@ namespace appl {
return m_paternName; return m_paternName;
}; };
private: private:
std::unique_ptr<etk::RegExp<etk::Buffer>> m_regExp; //!< Start of Regular expression std::string m_regexValue;
std::basic_regex<char32_t> m_regExp; //!< Start of Regular expression
public: public:
void setPatern(std::string& _regExp, bool forceMaximize=false); void setPatern(const std::string& _regExp, bool forceMaximize=false);
std::string getPaternString(); std::string getPaternString();
private: private:
std::string m_colorName; //!< Current color name std::string m_colorName; //!< Current color name
@ -82,7 +83,7 @@ namespace appl {
enum resultFind find(int32_t _start, enum resultFind find(int32_t _start,
int32_t _stop, int32_t _stop,
appl::HighlightInfo& _resultat, appl::HighlightInfo& _resultat,
etk::Buffer& _buffer); const std::u32string& _buffer);
void parseRules(exml::Element* _child, int32_t _level, bool forceMaximize=false); void parseRules(exml::Element* _child, int32_t _level, bool forceMaximize=false);
}; };