1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 00:37:15 +01:00

Fix removal of non alpha-numeric characters from strings.

This commit is contained in:
Sandu Liviu Catalin 2022-07-23 17:42:01 +03:00
parent aa3952fd45
commit 44243aadd2
3 changed files with 6 additions and 4 deletions

View File

@ -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<int(int)>(::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

View File

@ -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<int(int)>(::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

View File

@ -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<int(int)>(::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;