[DEV] add parsing of &"'<> spacial value in generic text.
This commit is contained in:
parent
d97fe2efa7
commit
ab6fbbdfed
@ -137,11 +137,18 @@ void exml::Element::append(exml::Node* _node) {
|
||||
}
|
||||
|
||||
std::string exml::Element::getText() {
|
||||
// TODO : add more capabilities ...
|
||||
std::string res;
|
||||
for (size_t iii=0; iii<m_listSub.size(); iii++) {
|
||||
if (NULL!=m_listSub[iii]) {
|
||||
m_listSub[iii]->iGenerate(res, 0);
|
||||
if (m_listSub.size() == 1) {
|
||||
if (m_listSub[0]->getType() == typeText) {
|
||||
res = m_listSub[0]->getValue();
|
||||
} else {
|
||||
m_listSub[0]->iGenerate(res, 0);
|
||||
}
|
||||
} else {
|
||||
for (size_t iii=0; iii<m_listSub.size(); iii++) {
|
||||
if (NULL!=m_listSub[iii]) {
|
||||
m_listSub[iii]->iGenerate(res, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
@ -309,7 +316,6 @@ bool exml::Element::subParse(const std::string& _data, int32_t& _pos, bool _case
|
||||
CREATE_ERROR(_doc, _data, _pos, _filePos, std::string("End file with '<!") + _data[iii+white+2] + "' chars == > invalide XML");
|
||||
return false;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
if(_data[iii+white+1] == '/') {
|
||||
|
@ -77,7 +77,7 @@ namespace exml {
|
||||
const Element* getNamed(const std::string& _name) const;
|
||||
/**
|
||||
* @brief get the internal data of the element (if the element has some sub node thay are converted in xml string == > like this it is not needed to use <![CDATA[...]]>
|
||||
* @return the curent data string.
|
||||
* @return the curent data string. if Only one text node, then we get the parssed data (no & ...) if more than one node, then we transform &,",',<,> in xml normal text...
|
||||
*/
|
||||
std::string getText();
|
||||
protected:
|
||||
|
@ -9,11 +9,50 @@
|
||||
#include <exml/Text.h>
|
||||
#include <exml/debug.h>
|
||||
#include <exml/Document.h>
|
||||
#include <regex>
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "Text"
|
||||
|
||||
|
||||
// transform the Text with :
|
||||
// "<" == "<"
|
||||
// ">" == ">"
|
||||
// "&" == "&"
|
||||
// "'" == "'"
|
||||
// """ == """
|
||||
static std::string replaceSpecialChar(const std::string& _inval) {
|
||||
std::string out;
|
||||
static std::regex regexLT("<");
|
||||
static std::regex regexGT(">");
|
||||
static std::regex regexAPOS("'");
|
||||
static std::regex regexQUOT(""");
|
||||
static std::regex regexAMP("&");
|
||||
|
||||
out = std::regex_replace(_inval, regexLT, "<");
|
||||
out = std::regex_replace(out, regexGT, ">");
|
||||
out = std::regex_replace(out, regexAPOS, "'");
|
||||
out = std::regex_replace(out, regexQUOT, "\"");
|
||||
out = std::regex_replace(out, regexAMP, "&");
|
||||
//EXML_ERROR("plop "<< _inval << " => " << out);
|
||||
return out;
|
||||
}
|
||||
static std::string replaceSpecialCharOut(const std::string& _inval) {
|
||||
std::string out;
|
||||
static std::regex regexLT("<");
|
||||
static std::regex regexGT(">;");
|
||||
static std::regex regexAMP("&");
|
||||
static std::regex regexAPOS("'");
|
||||
static std::regex regexQUOT("\"");
|
||||
|
||||
out = std::regex_replace(_inval, regexAMP, "&");
|
||||
out = std::regex_replace(out, regexQUOT, """);
|
||||
out = std::regex_replace(out, regexAPOS, "'");
|
||||
out = std::regex_replace(out, regexGT, ">");
|
||||
out = std::regex_replace(out, regexLT, "<");
|
||||
return out;
|
||||
}
|
||||
|
||||
static bool isWhiteChar(char32_t _val) {
|
||||
if( _val == ' '
|
||||
|| _val == '\t'
|
||||
@ -25,7 +64,7 @@ static bool isWhiteChar(char32_t _val) {
|
||||
}
|
||||
|
||||
bool exml::Text::iGenerate(std::string& _data, int32_t _indent) const {
|
||||
_data += m_value;
|
||||
_data += replaceSpecialCharOut(m_value);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -65,6 +104,7 @@ bool exml::Text::iParse(const std::string& _data, int32_t& _pos, bool _caseSensi
|
||||
m_value = std::string(_data, _pos, newEnd-(_pos));
|
||||
EXML_VERBOSE(" find text '" << m_value << "'");
|
||||
_pos = iii-1;
|
||||
m_value = replaceSpecialChar(m_value);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -73,6 +113,11 @@ bool exml::Text::iParse(const std::string& _data, int32_t& _pos, bool _caseSensi
|
||||
return false;
|
||||
}
|
||||
|
||||
bool exml::TextCDATA::iGenerate(std::string& _data, int32_t _indent) const {
|
||||
_data += "<![CDATA[" + m_value +"]]>";
|
||||
return true;
|
||||
}
|
||||
|
||||
bool exml::TextCDATA::iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc) {
|
||||
EXML_VERBOSE("start parse : 'text::CDATA'");
|
||||
m_pos = _filePos;
|
||||
|
@ -58,6 +58,7 @@ namespace exml {
|
||||
virtual ~TextCDATA() { };
|
||||
public: // herited function:
|
||||
virtual bool iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc);
|
||||
virtual bool iGenerate(std::string& _data, int32_t _indent) const;
|
||||
};
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user