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
This commit is contained in:
parent
f81d977f46
commit
57e1498aec
28
main.cpp
28
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<std::string>();
|
||||
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<time_t>();
|
||||
strftime(tm_str, 100, "%FT%TZ", gmtime(&upload_timestamp));
|
||||
escape_xml(title);
|
||||
escape_xml(&title);
|
||||
printf(" <entry>\n <id>urn:pixiv:illust:%s</id>\n <title type=\"text\">%s</title>\n <updated>%s</updated>\n <link rel=\"alternate\" type=\"text/html\" href=\"https://www.pixiv.net/en/artworks/%s\"></link>\n </entry>\n", illust_id.c_str(), title.c_str(), tm_str, illust_id.c_str());
|
||||
}
|
||||
printf("</feed>\n");
|
||||
|
|
Loading…
Reference in New Issue