#include <list>
#include <iostream>
#include <fstream>
+#include <fmt/format.h>
#include "biawebutil.hpp"
// classes to describe the a list of items and sidebar item containers which form part of
return this->sidebar_text;
}
void set_sidebar_text (std::string text) {
- this->sidebar_text = text;
+ this->sidebar_text = escape_html (text);
}
std::string get_sidebar_url () {
return this->sidebar_url;
}
void set_sidebar_url (std::string url) {
- this->sidebar_url = url;
+ this->sidebar_url = escape_html (url);
}
// output to HTML using a template directory specified
std::string to_html (std::string templatedir);
SideBarItem (std::string text = "", std::string url = "") {
- this->sidebar_text = text;
- this->sidebar_url = url;
+ this->sidebar_text = escape_html (text);
+ this->sidebar_url = escape_html (url);
}
};
std::string tpl_linkitem_str ( (std::istreambuf_iterator<char> (tpl_linkitem)),
(std::istreambuf_iterator<char> ()));
tpl_linkitem.close ();
- std::unique_ptr<char[]> linktxt (new char[tpl_linkitem_str.size()
- + this->sidebar_text.size ()
- + this->sidebar_url.size ()] );
- std::sprintf (linktxt.get(), tpl_linkitem_str.c_str (),
- this->sidebar_url.c_str (),
- this->sidebar_text.c_str ());
- html.append (linktxt.get ());
+ html = fmt::format (tpl_linkitem_str,
+ fmt::arg ("itemurl", this->sidebar_url),
+ fmt::arg ("itemtext", this->sidebar_text));
}
// no text or url - item is empty - so it should be blank
else
std::string tpl_item_str ( (std::istreambuf_iterator<char> (tpl_item)),
(std::istreambuf_iterator<char> ()));
tpl_item.close ();
- std::unique_ptr<char[]> txt (new char [tpl_item_str.size () +
- this->sidebar_text.size ()]);
- std::sprintf (txt.get (), tpl_item_str.c_str(), this->sidebar_text.c_str());
- html.append (txt.get ());
+ html = fmt::format (tpl_item_str, fmt::arg ("itemtext", this->sidebar_text) );
}
return html;
}
std::string sidetpl_str ( ( std::istreambuf_iterator<char> (sidetpl)) ,
(std::istreambuf_iterator<char> ()));
sidetpl.close ();
- std::string listitem;
+ std::string listitems;
// first get the sidebar items and render them to HTML
for (SideBarItem item : this->items) {
- listitem += item.to_html (templatedir);
+ listitems += item.to_html (templatedir);
}
-
- std::unique_ptr<char[]> tpl_final (new char[sidetpl_str.size() +
- this->sidebar_title.size () +
- listitem.size () ]);
- std::string html;
- // if there are items, sidebar should be rendered
+ std::string html = "";
+ // if there are items, sidebar should be rendered otherwise not needed
if (items.size () > 0)
- {
- std::sprintf (tpl_final.get (), sidetpl_str.c_str(),
- this->sidebar_title.c_str(), listitem.c_str()) ;
- html.append ( tpl_final.get ());
- }
- // no items in the sidebar, render as empty string (even if it has a heading)
- // since heading becomes meaningless without items
- else
- html = "";
+ html = fmt::format (sidetpl_str,
+ fmt::arg ("title", this->sidebar_title),
+ fmt::arg ("items", listitems));
+
return html;
}
}