Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/myxmlpp/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/myxmlpp/include/Attribute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace myxmlpp {
* @param key the key of the attribute
* @param value the value of the attribute
*/
Attribute(const std::string& key, const std::string& value);
Attribute(std::string key, std::string value);

/**
* Construct and attribute by a string with a attrName="attrValue"
Expand Down
6 changes: 3 additions & 3 deletions lib/myxmlpp/include/Doc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace myxmlpp {
std::shared_ptr<Node> _root;

/**
* Check commons file openning errors and throw the correct exception
* Check commons file opening errors and throw the correct exception
* @throws NoFileException if the required file does not exists
* @throws PermissionDeniedException if there is not enough permissions to work with the file
* @throws FileException Default exception for other errors
Expand All @@ -68,11 +68,11 @@ namespace myxmlpp {
* @param filepath path to the xml file
* @param keepOpen keep the file stream opened
* @throws NoFileException if the required file does not exists
* @throws PermissionDeniedException if ther is not enough permissions to work with the file
* @throws PermissionDeniedException if there is not enough permissions to work with the file
* @throws FileException Default exception for other errors
* @throws ParsingException If the file is not correctly formatted
*/
Doc(const std::string& filepath, bool keepOpen = false);
explicit Doc(const std::string& filepath, bool keepOpen = false);

/**
* @details This method will write all the doc structure to a file in a minified way (only necessary spaces)
Expand Down
8 changes: 4 additions & 4 deletions lib/myxmlpp/include/Node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace myxmlpp {
int depth) const;

static std::vector<std::string> _split(const std::string &str,
char delim);
char delimiter);

static std::shared_ptr<Node>
_searchChild(const Node *current,
Expand Down Expand Up @@ -99,7 +99,7 @@ namespace myxmlpp {
* @param indent the number of tab to return
* @return the indentation helper string
*/
static std::string _strIdent(std::size_t indent);
static std::string _strIndent(std::size_t indent);

/**
* @details This method will return all the attributes serialized
Expand All @@ -123,7 +123,7 @@ namespace myxmlpp {
* @param tag the tag of the node.
* @return the created node.
*/
Node(Node *parent) noexcept;
explicit Node(Node *parent) noexcept;

/**
* Method to create a node with its tag and its children.
Expand Down Expand Up @@ -257,7 +257,7 @@ namespace myxmlpp {
{
return _children.end();
}

/**
* Method to find a child node by its tag.
* This method will return the first matched node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace myxmlpp {
std::string _key;

public:
AttributeNotFoundException(const std::string& key,
AttributeNotFoundException(std::string key,
const std::string& file,
int line,
const std::string& description="") noexcept;
Expand Down
8 changes: 4 additions & 4 deletions lib/myxmlpp/include/exceptions/Exception.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

namespace myxmlpp {
/**
* Base exception for the lib, only containing mandatory informations to debug
* Base exception for the lib, only containing mandatory information to debug
*/
class Exception: public std::exception {
protected:
/**
* Short descripition of the error
* Short description of the error
*/
std::string _description;

Expand All @@ -32,7 +32,7 @@ namespace myxmlpp {
* Line at which the error was raised
*/
std::string _line;

/**
* Complete error message
*/
Expand All @@ -47,7 +47,7 @@ namespace myxmlpp {
* @return error message
*/
const char *what() const noexcept override;

void build() noexcept;

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/myxmlpp/include/exceptions/FileException.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace myxmlpp {
std::string _filepath;

public:
FileException(const std::string& filepath,
FileException(std::string filepath,
const std::string& file,
int line,
const std::string& description="") noexcept;
Expand Down
2 changes: 1 addition & 1 deletion lib/myxmlpp/include/exceptions/NodeNotFoundException.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace myxmlpp {
std::string _tag;

public:
NodeNotFoundException(const std::string& tag,
NodeNotFoundException(std::string tag,
const std::string& file,
int line,
const std::string& description="") noexcept;
Expand Down
7 changes: 4 additions & 3 deletions lib/myxmlpp/src/Attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <fstream>
#include <sstream>
#include <utility>
#include "IllegalValueException.hpp"
#include "FileException.hpp"
#include "Attribute.hpp"
Expand All @@ -15,9 +16,9 @@

namespace myxmlpp {

Attribute::Attribute(const std::string &key,
const std::string &value)
: _key(key), _value(value)
Attribute::Attribute(std::string key,
std::string value)
: _key(std::move(key)), _value(std::move(value))
{}

Attribute::Attribute(std::string &fileContent)
Expand Down
2 changes: 0 additions & 2 deletions lib/myxmlpp/src/Node/Node_addChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
** Node_addChild.cpp
*/

#include <utility>

#include "Node.hpp"

void myxmlpp::Node::addChild(const std::shared_ptr<Node>& child) noexcept
Expand Down
4 changes: 2 additions & 2 deletions lib/myxmlpp/src/Node/Node_children.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ unsigned int myxmlpp::Node::getNbChildrenR() const noexcept
{
size_t total = _children.size();

for (auto it = _children.begin(); it != _children.end(); ++it)
total += (*it)->getNbChildrenR();
for (const auto & child : _children)
total += child->getNbChildrenR();
return total;
}

Expand Down
11 changes: 6 additions & 5 deletions lib/myxmlpp/src/Node/Node_parseUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
** Node_parseUtils.cpp
*/

#include <memory>
#include <regex>
#include "Node.hpp"
#include "ParsingException.hpp"

bool myxmlpp::Node::_isEndOfNode(std::string &str)
{
std::string rgx("[\r\n\t\f\v ]*(?:(?:<[a-zA-Z0-9_\\-]*"
"(?:[\r\n\t\f\v ].*\"[\r\n\t\f\v ]*?)*\/?>)|(?:<(\/).*>))");
"(?:[\r\n\t\f\v ].*\"[\r\n\t\f\v ]*?)*/?>)|(?:<(/).*>))");
std::smatch matches;

if (!_performRegex(matches, rgx, str, nullptr))
Expand All @@ -26,7 +27,7 @@ bool myxmlpp::Node::_isEndOfNode(std::string &str)
void myxmlpp::Node::_checkEndOfNode(std::string &str,
std::string &remaining) noexcept
{
std::string rgx("[\r\n\t\f\v ]*<\/(.*)>");
std::string rgx("[\r\n\t\f\v ]*</(.*)>");
std::smatch matches;

if (!_performRegex(matches, rgx, str, &remaining) || matches[1].str() != _tag)
Expand All @@ -45,7 +46,7 @@ bool myxmlpp::Node::_performRegex(std::smatch &matches, std::string &regexStr,
if (remaining) {
if (!std::regex_search(*remaining, remainingMatches, rgx))
throw myxmlpp::ParsingException(*remaining, MYXMLPP_ERROR_LOCATION,
"Malformated file");
"Malformed file");
remaining->replace(remainingMatches.position(),
remainingMatches.length(),
"");
Expand All @@ -56,7 +57,7 @@ bool myxmlpp::Node::_performRegex(std::smatch &matches, std::string &regexStr,
void myxmlpp::Node::_parseNodeString(std::string &str, std::string &remaining)
{
std::string rgx("[\r\n\t\f\v ]*(<([a-zA-Z0-9_\\-]*)"
"(?:[\r\n\t\f\v ](.*\")[\r\n\t\f\v ]*?)*(\/?)>)");
"(?:[\r\n\t\f\v ](.*\")[\r\n\t\f\v ]*?)*(/?)>)");
std::smatch matches;

if (!_performRegex(matches, rgx, str, &remaining))
Expand All @@ -82,7 +83,7 @@ void myxmlpp::Node::_extractAttributes(std::string &str) noexcept

while (std::regex_search(str, matches, rgx)) {
_attributes.push_back(
std::unique_ptr<Attribute>(new Attribute(matches[1], matches[2]))
std::make_unique<Attribute>(matches[1], matches[2])
);
str = matches.suffix().str();
}
Expand Down
14 changes: 7 additions & 7 deletions lib/myxmlpp/src/Node/Node_writeUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

#include <Node.hpp>

std::string myxmlpp::Node::_strIdent(std::size_t indent) {
std::string tab = "";
std::string myxmlpp::Node::_strIndent(std::size_t indent) {
std::string tab;

for (std::size_t i = 0; i < indent; ++i)
tab += '\t';
Expand Down Expand Up @@ -63,7 +63,7 @@ std::string myxmlpp::Node::asString(bool includeChildren) const noexcept {

std::string
myxmlpp::Node::asFString(size_t indent, bool includeChildren) const noexcept {
std::string str = includeChildren ? _strIdent(indent) + "<" : "<";
std::string str = includeChildren ? _strIndent(indent) + "<" : "<";

str += _tag;
str += _dumpAttrsF();
Expand All @@ -75,10 +75,10 @@ myxmlpp::Node::asFString(size_t indent, bool includeChildren) const noexcept {
str += ">\n";
for (auto &c : _children)
str += c->asFString(indent + 1);
str += _strIdent(indent)
+ std::string("</")
+ _tag
+ (_parent ? ">\n" : ">");
str += _strIndent(indent)
+ std::string("</")
+ _tag
+ (_parent ? ">\n" : ">");
} else
str += _parent ? "/>\n" : "/>";
return str;
Expand Down
5 changes: 2 additions & 3 deletions lib/myxmlpp/src/Node/delete/pop/Node_popChildrenR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ myxmlpp::Node::_popChildrenRecurs(std::vector<std::shared_ptr<Node>> &children,
children.push_back(**it);
_children.erase(*it);
}
for (auto it = _children.begin();
it != _children.end(); ++it)
(*it)->_popChildrenRecurs(children, tag, depth - 1);
for (auto & it : _children)
it->_popChildrenRecurs(children, tag, depth - 1);
}

std::vector<std::shared_ptr<myxmlpp::Node>>
Expand Down
4 changes: 2 additions & 2 deletions lib/myxmlpp/src/Node/find/Node_findChildByPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
#include "Node.hpp"

std::vector<std::string> myxmlpp::Node::_split(const std::string &str,
char delim)
char delimiter)
{
std::vector<std::string> result;
std::stringstream ss (str);
std::string item;

while (getline(ss, item, delim)) {
while (getline(ss, item, delimiter)) {
result.push_back (item);
}

Expand Down
6 changes: 4 additions & 2 deletions lib/myxmlpp/src/exceptions/AttributeNotFoundException.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@

#include "AttributeNotFoundException.hpp"

#include <utility>

myxmlpp::AttributeNotFoundException::AttributeNotFoundException(
const std::string& key,
std::string key,
const std::string& file,
int line,
const std::string& description) noexcept
: _key(key), Exception(file, line, description)
: _key(std::move(key)), Exception(file, line, description)
{
build();
}
Expand Down
4 changes: 2 additions & 2 deletions lib/myxmlpp/src/exceptions/Exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ std::string myxmlpp::Exception::baseWhat() const noexcept{

std::string myxmlpp::Exception::details() const noexcept {
if (!_description.empty())
return std::string("\nOptionnal details : ")
return std::string("\nOptional details : ")
+ _description
+ std::string("\n");
else
return std::string("\n");
return "\n";
}

const std::string &myxmlpp::Exception::getFile() const noexcept {
Expand Down
6 changes: 4 additions & 2 deletions lib/myxmlpp/src/exceptions/FileException.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@

#include "FileException.hpp"

myxmlpp::FileException::FileException(const std::string &filepath,
#include <utility>

myxmlpp::FileException::FileException(std::string filepath,
const std::string &file,
int line,
const std::string &description) noexcept
: _filepath(filepath), Exception(file, line, description)
: _filepath(std::move(filepath)), Exception(file, line, description)
{
build();
}
Expand Down
6 changes: 4 additions & 2 deletions lib/myxmlpp/src/exceptions/NodeNotFoundException.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@

#include "NodeNotFoundException.hpp"

myxmlpp::NodeNotFoundException::NodeNotFoundException(const std::string& tag,
#include <utility>

myxmlpp::NodeNotFoundException::NodeNotFoundException(std::string tag,
const std::string& file,
int line,
const std::string& description) noexcept
: _tag(tag), Exception(file, line, description)
: _tag(std::move(tag)), Exception(file, line, description)
{
build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ Test(Attribute_getValueBool, illegal)
std::string k = "key";
std::string v = "1kappa";
myxmlpp::Attribute a(k, v);

try {
bool i = a.getValueBool();
(void)a.getValueBool();
cr_expect(0);
} catch (const myxmlpp::IllegalValueException) {
} catch (const myxmlpp::IllegalValueException &e) {
cr_expect(1);
}
}
Expand All @@ -84,9 +84,9 @@ Test(Attribute_getValueBool, illegal_overriden)
myxmlpp::Attribute a(k, v);

try {
bool i = a.getValueBool("TRUE");
(void)a.getValueBool("TRUE");
cr_expect(0);
} catch (const myxmlpp::IllegalValueException) {
} catch (const myxmlpp::IllegalValueException &e) {
cr_expect(1);
}
}
Loading