Merge pull request #350 from diamante0018/better-strip

[Utils] Refactor strip function
This commit is contained in:
Maurice Heumann 2022-03-26 09:40:01 +01:00 committed by GitHub
commit 44b372f967
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 9 additions and 12 deletions

View File

@ -87,7 +87,7 @@ namespace colors
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;
}
@ -99,7 +99,7 @@ namespace colors
const auto result = reinterpret_cast<size_t(*)(int, int, char*, int, size_t, size_t)>(0x140213E60)(
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;
}

View File

@ -48,11 +48,10 @@ namespace dedicated_info
}
}
std::string cleaned_hostname;
cleaned_hostname.resize(static_cast<int>(strlen(sv_hostname->current.string) + 1));
std::string cleaned_hostname = sv_hostname->current.string;
utils::string::strip(sv_hostname->current.string, 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(),
mapname->current.string, client_count,

View File

@ -55,7 +55,7 @@ namespace discord
// get server host name
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
auto clients = reinterpret_cast<int*>(0x1414CC290);

View File

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