edn/sources/appl/HighlightPattern.cpp

115 lines
3.4 KiB
C++
Raw Normal View History

/**
* @author Edouard DUPIN
2012-11-25 11:55:06 +01:00
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
2012-11-25 11:55:06 +01:00
2013-10-25 20:49:26 +02:00
#include <appl/debug.h>
2012-04-24 09:42:14 +02:00
#include <appl/global.h>
2013-11-23 18:30:52 +01:00
#include <appl/HighlightPattern.h>
#undef __class__
2013-10-09 22:00:24 +02:00
#define __class__ "HighlightPattern"
appl::HighlightPattern::HighlightPattern(const std::shared_ptr<appl::GlyphPainting>& _glyphPainting) :
2013-10-25 22:12:34 +02:00
m_glyphPainting(_glyphPainting),
m_paternName(""),
m_regExp(nullptr),
2013-10-25 22:12:34 +02:00
m_colorName(""),
m_level(0) {
m_regExp = std::unique_ptr<etk::RegExp<etk::Buffer>>(new etk::RegExp<etk::Buffer>());
}
appl::HighlightPattern::~HighlightPattern() {
}
void appl::HighlightPattern::setPatern(std::string& _regExp, bool forceMaximize) {
if (m_regExp == nullptr) {
2013-10-25 22:12:34 +02:00
return;
}
m_regExp->compile(_regExp);
m_regExp->setMaximize(forceMaximize);
}
2014-07-30 23:24:26 +02:00
std::string appl::HighlightPattern::getPaternString() {
return m_regExp->getRegExDecorated();
}
2013-11-14 21:57:10 +01:00
void appl::HighlightPattern::setColorGlyph(std::string& _colorName) {
2013-10-09 22:00:24 +02:00
m_colorName = _colorName;
2013-10-25 22:12:34 +02:00
m_colorId = m_glyphPainting->request(m_colorName);
APPL_VERBOSE("Resuest color name '" << m_colorName << "' => id=" << m_colorId);
}
void appl::HighlightPattern::display() {
APPL_INFO("patern : '" << m_paternName << "' level=" << m_level );
APPL_INFO(" == > colorName '" << m_colorName << "'");
APPL_INFO(" == > regExp '" << m_regExp->getRegExp() << "'");
}
2013-10-09 22:00:24 +02:00
void appl::HighlightPattern::parseRules(exml::Element* _child, int32_t _level, bool forceMaximize) {
//--------------------------------------------------------------------------------------------
/*
<rule name="my preprocesseur">
<color>preprocesseur</color>
<regex>#</regex>
<max>false</max>
</rule>
*/
//--------------------------------------------------------------------------------------------
// process attribute
2013-11-14 21:57:10 +01:00
std::string highLightName = _child->getAttribute("name");
std::string myEdnDataTmp = "???";
2013-10-07 22:04:21 +02:00
if (highLightName.size()!=0) {
myEdnDataTmp = highLightName;
}
2013-10-07 22:04:21 +02:00
setName(myEdnDataTmp);
2013-10-25 22:12:34 +02:00
setLevel(_level);
2013-10-25 22:12:34 +02:00
exml::Element* xChild = _child->getNamed("color");
2014-06-05 22:01:24 +02:00
if (nullptr != xChild) {
2013-11-14 21:57:10 +01:00
std::string myData = xChild->getText();
2013-10-25 22:12:34 +02:00
if (myData.size() != 0) {
2012-04-23 10:15:43 +02:00
//APPL_INFO(PFX"(l %d) node fined : %s=\"%s\"", xChild->Row(), xChild->Value() , myData);
2013-11-14 21:57:10 +01:00
std::string myEdnData = myData;
2013-10-25 22:12:34 +02:00
setColorGlyph(myEdnData);
}
}
xChild = _child->getNamed("max");
if (nullptr != xChild) {
forceMaximize = etk::string_to_bool(xChild->getText());
}
xChild = _child->getNamed("regex");
2014-06-05 22:01:24 +02:00
if (nullptr != xChild) {
2013-11-14 21:57:10 +01:00
std::string myData = xChild->getText();
2013-10-25 22:12:34 +02:00
if (myData.size() != 0) {
2012-04-23 10:15:43 +02:00
//APPL_INFO(PFX"(l %d) node fined : %s=\"%s\"", xChild->Row(), xChild->Value() , myData);
2013-11-14 21:57:10 +01:00
std::string myEdnData = myData;
setPatern(myEdnData, forceMaximize);
}
}
}
2013-11-11 20:20:25 +01:00
enum resultFind appl::HighlightPattern::find(int32_t _start,
2013-10-25 22:12:34 +02:00
int32_t _stop,
2013-10-27 11:34:45 +01:00
appl::HighlightInfo& _resultat,
2013-10-25 22:12:34 +02:00
etk::Buffer& _buffer) {
2012-04-23 10:15:43 +02:00
//APPL_DEBUG(" try to find the element");
_resultat.start = -1;
_resultat.stop = -1;
2013-10-25 22:12:34 +02:00
_resultat.notEnded = false;
_resultat.patern = this;
2011-08-07 22:34:27 +02:00
2013-10-25 22:12:34 +02:00
// when we have only one element:
if (true == m_regExp->processOneElement(_buffer, _start, _stop)) {
_resultat.start = m_regExp->start();
_resultat.stop = m_regExp->stop();
2013-10-25 22:12:34 +02:00
return HLP_FIND_OK;
2011-08-07 22:34:27 +02:00
}
//APPL_DEBUG("NOT find hightlightpatern ...");
2011-08-07 22:34:27 +02:00
return HLP_FIND_ERROR;
}