aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-08-03 01:57:39 +0200
committerdec05eba <dec05eba@protonmail.com>2019-08-03 01:57:42 +0200
commitd9fb89269fd30fa44d2b3728b9ae3c7b896a77d3 (patch)
tree853bf886fddc2c761f3b3b337775612475da4b10
parent117eb25e36ac3b1e1ba18cc9f1e177016c076f34 (diff)
Properly remove html tag in search result on manganelo
-rw-r--r--src/Manganelo.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/Manganelo.cpp b/src/Manganelo.cpp
index 85a3802..de39c77 100644
--- a/src/Manganelo.cpp
+++ b/src/Manganelo.cpp
@@ -49,22 +49,24 @@ namespace QuickMedia {
return result == 0 ? SearchResult::OK : SearchResult::ERR;
}
- static void remove_html_span(std::string &str) {
+ // Returns true if changed
+ static bool remove_html_span(std::string &str) {
size_t open_tag_start = str.find("<span");
if(open_tag_start == std::string::npos)
- return;
+ return false;
size_t open_tag_end = str.find('>', open_tag_start + 5);
if(open_tag_end == std::string::npos)
- return;
+ return false;
str.erase(open_tag_start, open_tag_end - open_tag_start + 1);
size_t close_tag = str.find("</span>");
if(close_tag == std::string::npos)
- return;
+ return true;
str.erase(close_tag, 7);
+ return true;
}
SuggestionResult Manganelo::update_search_suggestions(const std::string &text, std::vector<std::unique_ptr<BodyItem>> &result_items) {
@@ -98,7 +100,7 @@ namespace QuickMedia {
Json::Value name = child.get("name", "");
if(name.isString() && name.asCString()[0] != '\0') {
std::string name_str = name.asString();
- remove_html_span(name_str);
+ while(remove_html_span(name_str)) {}
auto item = std::make_unique<BodyItem>(name_str);
result_items.push_back(std::move(item));
}