From 44243aadd238008cbf551e1d90c77423a54159d1 Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Sat, 23 Jul 2022 17:42:01 +0300 Subject: [PATCH] Fix removal of non alpha-numeric characters from strings. --- module/Misc/Player.cpp | 2 +- module/Misc/Vehicle.cpp | 2 +- module/Misc/Weapon.cpp | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/module/Misc/Player.cpp b/module/Misc/Player.cpp index 1ec10a37..9bb2955f 100644 --- a/module/Misc/Player.cpp +++ b/module/Misc/Player.cpp @@ -114,7 +114,7 @@ int32_t GetSkinID(StackStrF & name) // Clone the string into an editable version String str(name.mPtr, static_cast< size_t >(name.mLen)); // Strip non-alphanumeric characters from the name - str.erase(std::remove_if(str.begin(), str.end(), std::function(::isalnum)), str.end()); + str.erase(std::remove_if(str.begin(), str.end(), [](char c) -> bool { return std::isalnum(c) == 0; }), str.end()); // Convert the string to lowercase std::transform(str.begin(), str.end(), str.begin(), ::tolower); // See if we still have a valid name after the cleanup diff --git a/module/Misc/Vehicle.cpp b/module/Misc/Vehicle.cpp index ec61fa66..85b94743 100644 --- a/module/Misc/Vehicle.cpp +++ b/module/Misc/Vehicle.cpp @@ -123,7 +123,7 @@ int32_t GetAutomobileID(StackStrF & name) // Clone the string into an editable version String str(name.mPtr, static_cast< size_t >(name.mLen)); // Strip non-alphanumeric characters from the name - str.erase(std::remove_if(str.begin(), str.end(), std::function(::isalnum)), str.end()); + str.erase(std::remove_if(str.begin(), str.end(), [](char c) -> bool { return std::isalnum(c) == 0; }), str.end()); // Convert the string to lowercase std::transform(str.begin(), str.end(), str.begin(), ::tolower); // See if we still have a valid name after the cleanup diff --git a/module/Misc/Weapon.cpp b/module/Misc/Weapon.cpp index 6f89c84c..84b5c2f2 100644 --- a/module/Misc/Weapon.cpp +++ b/module/Misc/Weapon.cpp @@ -163,9 +163,10 @@ int32_t GetWeaponID(StackStrF & name) // Clone the string into an editable version String str(name.mPtr, static_cast< size_t >(name.mLen)); // Strip non-alphanumeric characters from the name - str.erase(std::remove_if(str.begin(), str.end(), std::function(::isalnum)), str.end()); + str.erase(std::remove_if(str.begin(), str.end(), [](char c) -> bool { return std::isalnum(c) == 0; }), str.end()); // Convert the string to lowercase std::transform(str.begin(), str.end(), str.begin(), ::tolower); + LogInf("%s", str.c_str()); // See if we still have a valid name after the cleanup if(str.length() < 1) { @@ -324,6 +325,7 @@ int32_t GetWeaponID(StackStrF & name) // [S]PAS-12 Shotgun // [S]tubby Shotgun // [S]uicide + // Pump action [S]hotgun case 's': // [Sc]rewdriver if (b == 'c') return SQMOD_WEAPON_SCREWDRIVER; @@ -337,7 +339,7 @@ int32_t GetWeaponID(StackStrF & name) else if (b == 't') return SQMOD_WEAPON_STUBBY; // [Su]icide else if (b == 'u') return SQMOD_WEAPON_SUICIDE; - // Pump action [Sh]otgun + // Pump action [Sh]otgun else if (b == 'h') return SQMOD_WEAPON_SHOTGUN; // Default to unknwon else return SQMOD_UNKNOWN;