summaryrefslogtreecommitdiff
path: root/src/bridge
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2015-09-01 14:47:57 +0200
committerFlorent Le Coz <louiz@louiz.org>2015-09-01 14:47:57 +0200
commitf3b3d937ae274d0eec4a737d11ba19a7f4ceef03 (patch)
treec8dbd17073d8247c1d292050c1fff2f12c2114b1 /src/bridge
parent38564d77c7679dd4de4562d321146322b6211d61 (diff)
downloadbiboumi-f3b3d937ae274d0eec4a737d11ba19a7f4ceef03.tar.gz
biboumi-f3b3d937ae274d0eec4a737d11ba19a7f4ceef03.tar.bz2
biboumi-f3b3d937ae274d0eec4a737d11ba19a7f4ceef03.tar.xz
biboumi-f3b3d937ae274d0eec4a737d11ba19a7f4ceef03.zip
Use unique_ptr to store the XmlNode’s children
Also fix some constness things
Diffstat (limited to 'src/bridge')
-rw-r--r--src/bridge/colors.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/bridge/colors.cpp b/src/bridge/colors.cpp
index bdc34bf..66f51ee 100644
--- a/src/bridge/colors.cpp
+++ b/src/bridge/colors.cpp
@@ -62,7 +62,9 @@ Xmpp::body irc_format_to_xhtmlim(const std::string& s)
std::unique_ptr<XmlNode> result = std::make_unique<XmlNode>("body");
(*result)["xmlns"] = XHTML_NS;
+ std::unique_ptr<XmlNode> current_node_up;
XmlNode* current_node = result.get();
+
std::string::size_type pos_start = 0;
std::string::size_type pos_end;
@@ -79,8 +81,7 @@ Xmpp::body irc_format_to_xhtmlim(const std::string& s)
styles.strong = !styles.strong;
else if (s[pos_end] == IRC_FORMAT_NEWLINE_CHAR)
{
- XmlNode* br_node = new XmlNode("br");
- current_node->add_child(br_node);
+ current_node->add_child(std::make_unique<XmlNode>("br"));
cleaned += '\n';
}
else if (s[pos_end] == IRC_FORMAT_UNDERLINE_CHAR)
@@ -125,7 +126,7 @@ Xmpp::body irc_format_to_xhtmlim(const std::string& s)
// close opened span, if any
if (current_node != result.get())
{
- result->add_child(current_node);
+ result->add_child(std::move(current_node_up));
current_node = result.get();
}
// Take all currently-applied style and create a new span with it
@@ -144,7 +145,8 @@ Xmpp::body irc_format_to_xhtmlim(const std::string& s)
irc_colors_to_css[styles.bg % IRC_NUM_COLORS] + ";";
if (!styles_str.empty())
{
- current_node = new XmlNode("span");
+ current_node_up = std::make_unique<XmlNode>("span");
+ current_node = current_node_up.get();
(*current_node)["style"] = styles_str;
}
@@ -161,7 +163,7 @@ Xmpp::body irc_format_to_xhtmlim(const std::string& s)
current_node->add_to_inner(txt);
if (current_node != result.get())
- result->add_child(current_node);
+ result->add_child(std::move(current_node_up));
Xmpp::body body_res = std::make_tuple(cleaned, std::move(result));
return body_res;