summaryrefslogtreecommitdiff
path: root/louloulibs/xmpp
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2015-12-22 21:37:29 +0100
committerFlorent Le Coz <louiz@louiz.org>2015-12-23 11:05:55 +0100
commit9ac0d3a5766494c9c0c2074c4a21542eea195a29 (patch)
tree3cdc18699373eb5c6e2b68cb6686de997ff8bbe3 /louloulibs/xmpp
parent9167cdf1269c1956b72db1e8dfdbfd61cbf66bb9 (diff)
downloadbiboumi-9ac0d3a5766494c9c0c2074c4a21542eea195a29.tar.gz
biboumi-9ac0d3a5766494c9c0c2074c4a21542eea195a29.tar.bz2
biboumi-9ac0d3a5766494c9c0c2074c4a21542eea195a29.tar.xz
biboumi-9ac0d3a5766494c9c0c2074c4a21542eea195a29.zip
A few cleanups, and make a few things more modern
Diffstat (limited to 'louloulibs/xmpp')
-rw-r--r--louloulibs/xmpp/xmpp_parser.cpp6
-rw-r--r--louloulibs/xmpp/xmpp_parser.hpp2
-rw-r--r--louloulibs/xmpp/xmpp_stanza.cpp10
-rw-r--r--louloulibs/xmpp/xmpp_stanza.hpp9
4 files changed, 17 insertions, 10 deletions
diff --git a/louloulibs/xmpp/xmpp_parser.cpp b/louloulibs/xmpp/xmpp_parser.cpp
index 25f2876..69de145 100644
--- a/louloulibs/xmpp/xmpp_parser.cpp
+++ b/louloulibs/xmpp/xmpp_parser.cpp
@@ -124,12 +124,12 @@ void XmppParser::end_element(const XML_Char*)
}
}
-void XmppParser::char_data(const XML_Char* data, int len)
+void XmppParser::char_data(const XML_Char* data, const size_t len)
{
if (this->current_node->has_children())
- this->current_node->get_last_child()->add_to_tail(std::string(data, len));
+ this->current_node->get_last_child()->add_to_tail({data, len});
else
- this->current_node->add_to_inner(std::string(data, len));
+ this->current_node->add_to_inner({data, len});
}
void XmppParser::stanza_event(const Stanza& stanza) const
diff --git a/louloulibs/xmpp/xmpp_parser.hpp b/louloulibs/xmpp/xmpp_parser.hpp
index 4de639d..3474b13 100644
--- a/louloulibs/xmpp/xmpp_parser.hpp
+++ b/louloulibs/xmpp/xmpp_parser.hpp
@@ -82,7 +82,7 @@ public:
/**
* Some inner or tail data has been parsed
*/
- void char_data(const XML_Char* data, int len);
+ void char_data(const XML_Char* data, const size_t len);
/**
* Calls all the stanza_callbacks one by one.
*/
diff --git a/louloulibs/xmpp/xmpp_stanza.cpp b/louloulibs/xmpp/xmpp_stanza.cpp
index d1c2e0f..f247436 100644
--- a/louloulibs/xmpp/xmpp_stanza.cpp
+++ b/louloulibs/xmpp/xmpp_stanza.cpp
@@ -199,6 +199,11 @@ void XmlNode::set_name(const std::string& name)
this->name = name;
}
+void XmlNode::set_name(std::string&& name)
+{
+ this->name = std::move(name);
+}
+
const std::string XmlNode::get_name() const
{
return this->name;
@@ -228,7 +233,7 @@ bool XmlNode::has_children() const
return !this->children.empty();
}
-const std::string XmlNode::get_tag(const std::string& name) const
+const std::string& XmlNode::get_tag(const std::string& name) const
{
try
{
@@ -237,7 +242,8 @@ const std::string XmlNode::get_tag(const std::string& name) const
}
catch (const std::out_of_range& e)
{
- return "";
+ static const std::string def{};
+ return def;
}
}
diff --git a/louloulibs/xmpp/xmpp_stanza.hpp b/louloulibs/xmpp/xmpp_stanza.hpp
index b1ba54a..bdc937f 100644
--- a/louloulibs/xmpp/xmpp_stanza.hpp
+++ b/louloulibs/xmpp/xmpp_stanza.hpp
@@ -96,6 +96,7 @@ public:
XmlNode* get_last_child() const;
XmlNode* get_parent() const;
void set_name(const std::string& name);
+ void set_name(std::string&& name);
const std::string get_name() const;
/**
* Serialize the stanza into a string
@@ -110,7 +111,7 @@ public:
* Gets the value for the given attribute, returns an empty string if the
* node as no such attribute.
*/
- const std::string get_tag(const std::string& name) const;
+ const std::string& get_tag(const std::string& name) const;
/**
* Remove the attribute of the node. Does nothing if that attribute is not
* present. Returns true if the tag was removed, false if it was absent.
@@ -133,13 +134,13 @@ private:
XmlNode& operator=(XmlNode&&) = delete;
};
+std::ostream& operator<<(std::ostream& os, const XmlNode& node);
+
/**
* An XMPP stanza is just an XML node of level 2 in the XMPP document (the
* level 1 ones are the <stream::stream/>, and the ones above 2 are just the
* content of the stanzas)
*/
-typedef XmlNode Stanza;
-
-std::ostream& operator<<(std::ostream& os, const XmlNode& node);
+using Stanza = XmlNode;
#endif // XMPP_STANZA_INCLUDED