2011-07-20 10:33:24 +02:00
|
|
|
/**
|
|
|
|
* @author Edouard DUPIN
|
2012-11-25 11:55:06 +01:00
|
|
|
*
|
|
|
|
* @copyright 2010, Edouard DUPIN, all right reserved
|
|
|
|
*
|
|
|
|
* @license GPL v3 (see license file)
|
2011-07-20 10:33:24 +02:00
|
|
|
*/
|
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>
|
2011-07-20 10:33:24 +02:00
|
|
|
|
|
|
|
#undef __class__
|
2013-10-09 22:00:24 +02:00
|
|
|
#define __class__ "HighlightPattern"
|
2011-07-20 10:33:24 +02:00
|
|
|
|
2014-08-07 23:41:48 +02:00
|
|
|
appl::HighlightPattern::HighlightPattern(const std::shared_ptr<appl::GlyphPainting>& _glyphPainting) :
|
2013-10-25 22:12:34 +02:00
|
|
|
m_glyphPainting(_glyphPainting),
|
|
|
|
m_paternName(""),
|
2014-07-29 15:36:12 +02:00
|
|
|
m_regExp(nullptr),
|
2013-10-25 22:12:34 +02:00
|
|
|
m_colorName(""),
|
|
|
|
m_level(0) {
|
2014-07-29 15:36:12 +02:00
|
|
|
m_regExp = std::unique_ptr<etk::RegExp<etk::Buffer>>(new etk::RegExp<etk::Buffer>());
|
2011-07-20 10:33:24 +02:00
|
|
|
}
|
|
|
|
|
2014-05-15 21:37:39 +02:00
|
|
|
appl::HighlightPattern::~HighlightPattern() {
|
2014-05-27 21:43:02 +02:00
|
|
|
|
2011-07-20 10:33:24 +02:00
|
|
|
}
|
|
|
|
|
2014-10-02 22:40:40 +02:00
|
|
|
void appl::HighlightPattern::setPatern(std::string& _regExp, bool forceMaximize) {
|
2014-07-29 15:36:12 +02:00
|
|
|
if (m_regExp == nullptr) {
|
2013-10-25 22:12:34 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-07-29 15:36:12 +02:00
|
|
|
m_regExp->compile(_regExp);
|
2014-10-02 22:40:40 +02:00
|
|
|
m_regExp->setMaximize(forceMaximize);
|
2011-07-20 10:33:24 +02:00
|
|
|
}
|
2014-07-30 23:24:26 +02:00
|
|
|
std::string appl::HighlightPattern::getPaternString() {
|
|
|
|
return m_regExp->getRegExDecorated();
|
|
|
|
}
|
2011-07-20 10:33:24 +02:00
|
|
|
|
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);
|
2013-10-28 21:47:51 +01:00
|
|
|
APPL_VERBOSE("Resuest color name '" << m_colorName << "' => id=" << m_colorId);
|
2011-07-20 10:33:24 +02:00
|
|
|
}
|
|
|
|
|
2014-05-15 21:37:39 +02:00
|
|
|
void appl::HighlightPattern::display() {
|
2014-07-29 15:36:12 +02:00
|
|
|
APPL_INFO("patern : '" << m_paternName << "' level=" << m_level );
|
|
|
|
APPL_INFO(" == > colorName '" << m_colorName << "'");
|
|
|
|
APPL_INFO(" == > regExp '" << m_regExp->getRegExp() << "'");
|
2011-07-20 10:33:24 +02:00
|
|
|
}
|
2013-10-09 22:00:24 +02:00
|
|
|
|
2014-10-02 22:40:40 +02:00
|
|
|
void appl::HighlightPattern::parseRules(exml::Element* _child, int32_t _level, bool forceMaximize) {
|
2011-07-20 10:33:24 +02:00
|
|
|
//--------------------------------------------------------------------------------------------
|
|
|
|
/*
|
|
|
|
<rule name="my preprocesseur">
|
|
|
|
<color>preprocesseur</color>
|
2014-07-29 15:36:12 +02:00
|
|
|
<regex>#</regex>
|
2014-10-02 22:40:40 +02:00
|
|
|
<max>false</max>
|
2011-07-20 10:33:24 +02:00
|
|
|
</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) {
|
2011-07-20 10:33:24 +02:00
|
|
|
myEdnDataTmp = highLightName;
|
|
|
|
}
|
2013-10-07 22:04:21 +02:00
|
|
|
setName(myEdnDataTmp);
|
2013-10-25 22:12:34 +02:00
|
|
|
setLevel(_level);
|
2011-07-20 10:33:24 +02:00
|
|
|
|
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);
|
2011-07-20 10:33:24 +02:00
|
|
|
}
|
|
|
|
}
|
2014-10-02 22:40:40 +02:00
|
|
|
xChild = _child->getNamed("max");
|
|
|
|
if (nullptr != xChild) {
|
|
|
|
forceMaximize = etk::string_to_bool(xChild->getText());
|
|
|
|
}
|
2014-07-29 15:36:12 +02:00
|
|
|
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;
|
2014-10-02 22:40:40 +02:00
|
|
|
setPatern(myEdnData, forceMaximize);
|
2011-07-20 10:33:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-08 10:24:24 +02:00
|
|
|
|
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");
|
2014-07-29 15:36:12 +02:00
|
|
|
_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:
|
2014-07-29 15:36:12 +02:00
|
|
|
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
|
|
|
}
|
2014-07-29 15:36:12 +02:00
|
|
|
//APPL_DEBUG("NOT find hightlightpatern ...");
|
2011-08-07 22:34:27 +02:00
|
|
|
return HLP_FIND_ERROR;
|
|
|
|
}
|