remove duplicate helper

This commit is contained in:
a 2024-12-06 23:19:58 +02:00
parent 648faa9f79
commit 49a9cfa375
6 changed files with 12 additions and 19 deletions

View File

@ -354,7 +354,7 @@ const std::map<std::string, Stat_config>& Settings::getStats() const
std::map<std::string, Stat_config>::const_iterator Settings::setStatDefiniton(const std::string &name, const struct Stat_config &stat_config)
{
auto ins_it = stats.insert_or_assign(common_helpers::ascii_to_lowercase(name), stat_config);
auto ins_it = stats.insert_or_assign(common_helpers::to_lower(name), stat_config);
return ins_it.first;
}

View File

@ -69,7 +69,7 @@ Steam_User_Stats::Steam_User_Stats(Settings *settings, class Networking *network
try {
trig.name = name;
trig.value_operation = static_cast<std::string const&>(it["progress"]["value"]["operation"]);
std::string stat_name = common_helpers::ascii_to_lowercase(static_cast<std::string const&>(it["progress"]["value"]["operand1"]));
std::string stat_name = common_helpers::to_lower(static_cast<std::string const&>(it["progress"]["value"]["operand1"]));
trig.min_value = static_cast<std::string const&>(it["progress"]["min_val"]);
trig.max_value = static_cast<std::string const&>(it["progress"]["max_val"]);
achievement_stat_trigger[stat_name].push_back(trig);

View File

@ -81,7 +81,7 @@ std::vector<Steam_Leaderboard_Entry> Steam_User_Stats::load_leaderboard_entries(
std::vector<Steam_Leaderboard_Entry> out{};
std::string leaderboard_name(common_helpers::ascii_to_lowercase(name));
std::string leaderboard_name(common_helpers::to_lower(name));
unsigned read_bytes = local_storage->file_size(Local_Storage::leaderboard_storage_folder, leaderboard_name);
if ((read_bytes == 0) ||
(read_bytes < (ELEMENT_SIZE * MAIN_HEADER_ELEMENTS_COUNT)) ||
@ -138,7 +138,7 @@ void Steam_User_Stats::save_my_leaderboard_entry(const Steam_Leaderboard &leader
output.push_back(detail);
}
std::string leaderboard_name(common_helpers::ascii_to_lowercase(leaderboard.name));
std::string leaderboard_name(common_helpers::to_lower(leaderboard.name));
unsigned int buffer_size = static_cast<unsigned int>(output.size() * sizeof(output[0])); // in bytes
local_storage->store_data(Local_Storage::leaderboard_storage_folder, leaderboard_name, (char* )&output[0], buffer_size);
}
@ -186,6 +186,7 @@ unsigned int Steam_User_Stats::cache_leaderboard_ifneeded(const std::string &nam
// create a new entry in-memory and try reading the entries from disk
struct Steam_Leaderboard new_board{};
// don't make this lower/upper case, appid 1372280 later calls GetLeaderboardName() and hangs if the name wasn't the same as the original
new_board.name = name;
new_board.sort_method = eLeaderboardSortMethod;
new_board.display_type = eLeaderboardDisplayType;

View File

@ -28,7 +28,7 @@ bool Steam_User_Stats::clear_stats_internal()
bool notify_server = false;
for (const auto &stat : settings->getStats()) {
std::string stat_name(common_helpers::ascii_to_lowercase(stat.first));
std::string stat_name(common_helpers::to_lower(stat.first));
switch (stat.second.type)
{
@ -79,7 +79,7 @@ Steam_User_Stats::InternalSetResult<int32> Steam_User_Stats::set_stat_internal(
Steam_User_Stats::InternalSetResult<int32> result{};
if (!pchName) return result;
std::string stat_name(common_helpers::ascii_to_lowercase(pchName));
std::string stat_name(common_helpers::to_lower(pchName));
const auto &stats_config = settings->getStats();
auto stats_data = stats_config.find(stat_name);
@ -152,7 +152,7 @@ Steam_User_Stats::InternalSetResult<std::pair<GameServerStats_Messages::StatInfo
Steam_User_Stats::InternalSetResult<std::pair<GameServerStats_Messages::StatInfo::Stat_Type, float>> result{};
if (!pchName) return result;
std::string stat_name(common_helpers::ascii_to_lowercase(pchName));
std::string stat_name(common_helpers::to_lower(pchName));
const auto &stats_config = settings->getStats();
auto stats_data = stats_config.find(stat_name);
@ -226,7 +226,7 @@ Steam_User_Stats::InternalSetResult<std::pair<GameServerStats_Messages::StatInfo
Steam_User_Stats::InternalSetResult<std::pair<GameServerStats_Messages::StatInfo::Stat_Type, float>> result{};
if (!pchName) return result;
std::string stat_name(common_helpers::ascii_to_lowercase(pchName));
std::string stat_name(common_helpers::to_lower(pchName));
const auto &stats_config = settings->getStats();
auto stats_data = stats_config.find(stat_name);
@ -305,7 +305,7 @@ bool Steam_User_Stats::GetStat( const char *pchName, int32 *pData )
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (!pchName) return false;
std::string stat_name = common_helpers::ascii_to_lowercase(pchName);
std::string stat_name = common_helpers::to_lower(pchName);
const auto &stats_config = settings->getStats();
auto stats_data = stats_config.find(stat_name);
@ -344,7 +344,7 @@ bool Steam_User_Stats::GetStat( const char *pchName, float *pData )
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (!pchName) return false;
std::string stat_name = common_helpers::ascii_to_lowercase(pchName);
std::string stat_name = common_helpers::to_lower(pchName);
const auto &stats_config = settings->getStats();
auto stats_data = stats_config.find(stat_name);
@ -531,7 +531,7 @@ bool Steam_User_Stats::ResetAllStats( bool bAchievementsToo )
clear_stats_internal(); // this will save stats to disk if necessary
if (!settings->disable_sharing_stats_with_gameserver) {
for (const auto &stat : settings->getStats()) {
std::string stat_name(common_helpers::ascii_to_lowercase(stat.first));
std::string stat_name(common_helpers::to_lower(stat.first));
auto &new_stat = (*pending_server_updates.mutable_user_stats())[stat_name];
new_stat.set_stat_type(stat.second.type);

View File

@ -225,12 +225,6 @@ bool common_helpers::str_cmp_insensitive(std::wstring_view str1, std::wstring_vi
});
}
std::string common_helpers::ascii_to_lowercase(std::string data) {
std::transform(data.begin(), data.end(), data.begin(),
[](char c){ return std::tolower(c); });
return data;
}
void common_helpers::thisThreadYieldFor(std::chrono::microseconds u)
{
const auto start = std::chrono::high_resolution_clock::now();

View File

@ -71,8 +71,6 @@ std::string uint8_vector_to_hex_string(const std::vector<uint8_t> &v);
bool str_cmp_insensitive(std::string_view str1, std::string_view str2);
bool str_cmp_insensitive(std::wstring_view str1, std::wstring_view str2);
std::string ascii_to_lowercase(std::string data);
void thisThreadYieldFor(std::chrono::microseconds u);
void consume_bom(std::ifstream &input);