From 57e1498aec019f025b7208923d467f3e76e40c01 Mon Sep 17 00:00:00 2001 From: blank X Date: Thu, 2 Dec 2021 22:19:25 +0700 Subject: [PATCH] escape_xml now takes in a std::string* It previously took in a std::string, which means the string is copied and the string isn't modified in-place nor does the caller get the escaped string, making the call essentially useless --- main.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/main.cpp b/main.cpp index 65b07f4..8c08407 100644 --- a/main.cpp +++ b/main.cpp @@ -26,33 +26,33 @@ size_t write_memory_cb(char* contents, size_t size, size_t nmemb, std::string* s // behold: the why // oh and this is stolen from https://stackoverflow.com/a/3418285 -void escape_xml(std::string str) { - if (str.empty()) { +void escape_xml(std::string* str) { + if (str->empty()) { return; } size_t start = 0; - while ((start = str.find("&", start)) != std::string::npos) { - str.replace(start, 1, "&"); + while ((start = str->find("&", start)) != std::string::npos) { + str->replace(start, 1, "&"); start += 5; } start = 0; - while ((start = str.find("<", start)) != std::string::npos) { - str.replace(start, 1, "<"); + while ((start = str->find("<", start)) != std::string::npos) { + str->replace(start, 1, "<"); start += 4; } start = 0; - while ((start = str.find(">", start)) != std::string::npos) { - str.replace(start, 1, ">"); + while ((start = str->find(">", start)) != std::string::npos) { + str->replace(start, 1, ">"); start += 4; } start = 0; - while ((start = str.find("\"", start)) != std::string::npos) { - str.replace(start, 1, """); + while ((start = str->find("\"", start)) != std::string::npos) { + str->replace(start, 1, """); start += 6; } start = 0; - while ((start = str.find("'", start)) != std::string::npos) { - str.replace(start, 1, "'"); + while ((start = str->find("'", start)) != std::string::npos) { + str->replace(start, 1, "'"); start += 6; } } @@ -113,7 +113,7 @@ int main(int argc, char* argv[]) { last_updated_timestamp = time(NULL); } std::string ogp_title = j["body"]["meta"]["ogp"]["title"].get(); - escape_xml(ogp_title); + escape_xml(&ogp_title); char tm_str[100] = ""; strftime(tm_str, 100, "%FT%TZ", gmtime(&last_updated_timestamp)); // wonder if pixiv is a urn namespace @@ -126,7 +126,7 @@ int main(int argc, char* argv[]) { // istg if 0 isn't 1970 time_t upload_timestamp = illust["upload_timestamp"].get(); strftime(tm_str, 100, "%FT%TZ", gmtime(&upload_timestamp)); - escape_xml(title); + escape_xml(&title); printf(" \n urn:pixiv:illust:%s\n %s\n %s\n \n \n", illust_id.c_str(), title.c_str(), tm_str, illust_id.c_str()); } printf("\n");