mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Replace strcasestr with StrContainsIgnoreCase.
parent
14bab7d76b
commit
9229956f04
|
@ -2205,7 +2205,7 @@ DEF_CONSOLE_CMD(ConContent)
|
|||
if (StrEqualsIgnoreCase(argv[1], "state")) {
|
||||
IConsolePrint(CC_WHITE, "id, type, state, name");
|
||||
for (ConstContentIterator iter = _network_content_client.Begin(); iter != _network_content_client.End(); iter++) {
|
||||
if (argc > 2 && strcasestr((*iter)->name.c_str(), argv[2]) == nullptr) continue;
|
||||
if (argc > 2 && !StrContainsIgnoreCase((*iter)->name, argv[2])) continue;
|
||||
OutputContentState(*iter);
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -337,7 +337,7 @@ static bool TryLoadFontFromFile(const std::string &font_name, LOGFONT &logfont)
|
|||
_wsplitpath(fontPath, nullptr, nullptr, fname, nullptr);
|
||||
|
||||
wcsncpy_s(logfont.lfFaceName, lengthof(logfont.lfFaceName), fname, _TRUNCATE);
|
||||
logfont.lfWeight = strcasestr(font_name.c_str(), " bold") != nullptr || strcasestr(font_name.c_str(), "-bold") != nullptr ? FW_BOLD : FW_NORMAL; // Poor man's way to allow selecting bold fonts.
|
||||
logfont.lfWeight = StrContainsIgnoreCase(font_name, " bold") || StrContainsIgnoreCase(font_name, "-bold") ? FW_BOLD : FW_NORMAL; // Poor man's way to allow selecting bold fonts.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -345,7 +345,7 @@ static bool TryLoadFontFromFile(const std::string &font_name, LOGFONT &logfont)
|
|||
return logfont.lfFaceName[0] != 0;
|
||||
}
|
||||
|
||||
static void LoadWin32Font(FontSize fs, const LOGFONT &logfont, uint size, const char *font_name)
|
||||
static void LoadWin32Font(FontSize fs, const LOGFONT &logfont, uint size, std::string_view font_name)
|
||||
{
|
||||
HFONT font = CreateFontIndirect(&logfont);
|
||||
if (font == nullptr) {
|
||||
|
@ -369,7 +369,6 @@ void LoadWin32Font(FontSize fs)
|
|||
std::string font = GetFontCacheFontName(fs);
|
||||
if (font.empty()) return;
|
||||
|
||||
const char *font_name = font.c_str();
|
||||
LOGFONT logfont;
|
||||
MemSetT(&logfont, 0);
|
||||
logfont.lfPitchAndFamily = fs == FS_MONO ? FIXED_PITCH : VARIABLE_PITCH;
|
||||
|
@ -379,7 +378,7 @@ void LoadWin32Font(FontSize fs)
|
|||
|
||||
if (settings->os_handle != nullptr) {
|
||||
logfont = *(const LOGFONT *)settings->os_handle;
|
||||
} else if (strchr(font_name, '.') != nullptr) {
|
||||
} else if (font.find('.') != std::string::npos) {
|
||||
/* Might be a font file name, try load it. */
|
||||
if (!TryLoadFontFromFile(font, logfont)) {
|
||||
ShowInfo("Unable to load file '{}' for {} font, using default windows font selection instead", font, FontSizeToName(fs));
|
||||
|
@ -387,9 +386,9 @@ void LoadWin32Font(FontSize fs)
|
|||
}
|
||||
|
||||
if (logfont.lfFaceName[0] == 0) {
|
||||
logfont.lfWeight = strcasestr(font_name, " bold") != nullptr ? FW_BOLD : FW_NORMAL; // Poor man's way to allow selecting bold fonts.
|
||||
convert_to_fs(font_name, logfont.lfFaceName);
|
||||
logfont.lfWeight = StrContainsIgnoreCase(font, " bold") ? FW_BOLD : FW_NORMAL; // Poor man's way to allow selecting bold fonts.
|
||||
convert_to_fs(font, logfont.lfFaceName);
|
||||
}
|
||||
|
||||
LoadWin32Font(fs, logfont, GetFontCacheFontSize(fs), font_name);
|
||||
LoadWin32Font(fs, logfont, GetFontCacheFontSize(fs), font);
|
||||
}
|
||||
|
|
|
@ -470,22 +470,6 @@ size_t Utf8Decode(char32_t *c, const char *s)
|
|||
return 1;
|
||||
}
|
||||
|
||||
#ifdef DEFINE_STRCASESTR
|
||||
char *strcasestr(const char *haystack, const char *needle)
|
||||
{
|
||||
size_t hay_len = strlen(haystack);
|
||||
size_t needle_len = strlen(needle);
|
||||
while (hay_len >= needle_len) {
|
||||
if (strncasecmp(haystack, needle, needle_len) == 0) return const_cast<char *>(haystack);
|
||||
|
||||
haystack++;
|
||||
hay_len--;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
#endif /* DEFINE_STRCASESTR */
|
||||
|
||||
/**
|
||||
* Test if a unicode character is considered garbage to be skipped.
|
||||
* @param c Character to test.
|
||||
|
|
|
@ -243,12 +243,4 @@ inline bool IsWhitespace(char32_t c)
|
|||
#include <sys/param.h>
|
||||
#endif
|
||||
|
||||
/* strcasestr is available for _GNU_SOURCE, BSD and some Apple */
|
||||
#if defined(_GNU_SOURCE) || (defined(__BSD_VISIBLE) && __BSD_VISIBLE) || (defined(__APPLE__) && (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE))) || defined(_NETBSD_SOURCE)
|
||||
# undef DEFINE_STRCASESTR
|
||||
#else
|
||||
# define DEFINE_STRCASESTR
|
||||
char *strcasestr(const char *haystack, const char *needle);
|
||||
#endif /* strcasestr is available */
|
||||
|
||||
#endif /* STRING_FUNC_H */
|
||||
|
|
Loading…
Reference in New Issue