[Utils] Refactor strip function

This commit is contained in:
FutureRave 2022-03-22 15:13:50 +00:00
parent 84f405b1a0
commit 92bd54aed7
No known key found for this signature in database
GPG Key ID: E883E2BC9657D955
5 changed files with 10 additions and 13 deletions

View File

@ -87,7 +87,7 @@ namespace colors
char* i_clean_str_stub(char* string) char* i_clean_str_stub(char* string)
{ {
utils::string::strip(string, string, static_cast<int>(strlen(string)) + 1); utils::string::strip(string, string, std::strlen(string) + 1);
return string; return string;
} }
@ -99,7 +99,7 @@ namespace colors
const auto result = reinterpret_cast<size_t(*)(int, int, char*, int, size_t, size_t)>(0x140213E60)( const auto result = reinterpret_cast<size_t(*)(int, int, char*, int, size_t, size_t)>(0x140213E60)(
local_client_num, index, buf, size, unk, unk2); local_client_num, index, buf, size, unk, unk2);
utils::string::strip(buf, buf, size); utils::string::strip(buf, buf, static_cast<size_t>(size));
return result; return result;
} }

View File

@ -48,11 +48,10 @@ namespace dedicated_info
} }
} }
std::string cleaned_hostname; std::string cleaned_hostname(sv_hostname->current.string);
cleaned_hostname.resize(static_cast<int>(strlen(sv_hostname->current.string) + 1));
utils::string::strip(sv_hostname->current.string, cleaned_hostname.data(), utils::string::strip(cleaned_hostname.data(), cleaned_hostname.data(),
static_cast<int>(strlen(sv_hostname->current.string)) + 1); cleaned_hostname.size() + 1);
console::set_title(utils::string::va("%s on %s [%d/%d] (%d)", cleaned_hostname.data(), console::set_title(utils::string::va("%s on %s [%d/%d] (%d)", cleaned_hostname.data(),
mapname->current.string, client_count, mapname->current.string, client_count,

View File

@ -55,7 +55,7 @@ namespace discord
// get server host name // get server host name
auto* const host_name = reinterpret_cast<char*>(0x141646CC4); auto* const host_name = reinterpret_cast<char*>(0x141646CC4);
utils::string::strip(host_name, host_name, static_cast<int>(strlen(host_name)) + 1); utils::string::strip(host_name, host_name, std::strlen(host_name) + 1);
// get number of clients in game // get number of clients in game
auto clients = reinterpret_cast<int*>(0x1414CC290); auto clients = reinterpret_cast<int*>(0x1414CC290);

View File

@ -105,12 +105,12 @@ namespace utils::string
return {}; return {};
} }
void strip(const char* in, char* out, int max) void strip(const char* in, char* out, size_t max)
{ {
if (!in || !out) return; if (!in || !out) return;
max--; max--;
auto current = 0; auto current = 0u;
while (*in != 0 && current < max) while (*in != 0 && current < max)
{ {
const auto color_index = (*(in + 1) - 48) >= 0xC ? 7 : (*(in + 1) - 48); const auto color_index = (*(in + 1) - 48) >= 0xC ? 7 : (*(in + 1) - 48);
@ -128,11 +128,10 @@ namespace utils::string
++in; ++in;
} }
*out = '\0'; *out = '\0';
} }
#pragma warning(push)
#pragma warning(disable: 4100)
std::string convert(const std::wstring& wstr) std::string convert(const std::wstring& wstr)
{ {
std::string result; std::string result;
@ -158,7 +157,6 @@ namespace utils::string
return result; return result;
} }
#pragma warning(pop)
std::string replace(std::string str, const std::string& from, const std::string& to) std::string replace(std::string str, const std::string& from, const std::string& to)
{ {

View File

@ -91,7 +91,7 @@ namespace utils::string
std::string get_clipboard_data(); std::string get_clipboard_data();
void strip(const char* in, char* out, int max); void strip(const char* in, char* out, size_t max);
std::string convert(const std::wstring& wstr); std::string convert(const std::wstring& wstr);
std::wstring convert(const std::string& str); std::wstring convert(const std::string& str);