mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-02-07 14:58:22 +00:00
Codechange: use fmt::format_to instead of seprintf to create the search URL
This commit is contained in:
parent
6a8b4f3e10
commit
b221fa3c5a
@ -350,27 +350,27 @@ class NetworkContentListWindow : public Window, ContentCallback {
|
|||||||
/** Search external websites for content */
|
/** Search external websites for content */
|
||||||
void OpenExternalSearch()
|
void OpenExternalSearch()
|
||||||
{
|
{
|
||||||
char url[1024];
|
std::string url;
|
||||||
const char *last = lastof(url);
|
url.reserve(1024);
|
||||||
|
|
||||||
char *pos = strecpy(url, "https://grfsearch.openttd.org/?", last);
|
url += "https://grfsearch.openttd.org/?";
|
||||||
|
|
||||||
if (this->auto_select) {
|
if (this->auto_select) {
|
||||||
pos = strecpy(pos, "do=searchgrfid&q=", last);
|
url += "do=searchgrfid&q=";
|
||||||
|
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (const ContentInfo *ci : this->content) {
|
for (const ContentInfo *ci : this->content) {
|
||||||
if (ci->state != ContentInfo::DOES_NOT_EXIST) continue;
|
if (ci->state != ContentInfo::DOES_NOT_EXIST) continue;
|
||||||
|
|
||||||
if (!first) pos = strecpy(pos, ",", last);
|
if (!first) url.push_back(',');
|
||||||
first = false;
|
first = false;
|
||||||
|
|
||||||
pos += seprintf(pos, last, "%08X", ci->unique_id);
|
char buf[33];
|
||||||
pos = strecpy(pos, ":", last);
|
md5sumToString(buf, lastof(buf), ci->md5sum);
|
||||||
pos = md5sumToString(pos, last, ci->md5sum);
|
fmt::format_to(std::back_inserter(url), "{:08X}:{}", ci->unique_id, buf);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pos = strecpy(pos, "do=searchtext&q=", last);
|
url += "do=searchtext&q=";
|
||||||
|
|
||||||
/* Escape search term */
|
/* Escape search term */
|
||||||
for (const char *search = this->filter_editbox.text.buf; *search != '\0'; search++) {
|
for (const char *search = this->filter_editbox.text.buf; *search != '\0'; search++) {
|
||||||
@ -379,15 +379,14 @@ class NetworkContentListWindow : public Window, ContentCallback {
|
|||||||
|
|
||||||
/* Escape special chars, such as &%,= */
|
/* Escape special chars, such as &%,= */
|
||||||
if (*search < 0x30) {
|
if (*search < 0x30) {
|
||||||
pos += seprintf(pos, last, "%%%02X", *search);
|
fmt::format_to(std::back_inserter(url), "%{:02X}", *search);
|
||||||
} else if (pos < last) {
|
} else {
|
||||||
*pos = *search;
|
url.push_back(*search);
|
||||||
*++pos = '\0';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OpenBrowser(url);
|
OpenBrowser(url.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user