Eradicate all usages of strtoupper()

strtoupper() is an evil function whose behaviour depends on the system locale. mb_strtoupper() has more consistent behaviour.
This commit is contained in:
Dylan K. Taylor 2020-06-13 19:47:00 +01:00
parent a219b727f2
commit 097c260dbb
7 changed files with 15 additions and 15 deletions

View File

@ -50,6 +50,7 @@ use function is_object;
use function is_resource; use function is_resource;
use function is_string; use function is_string;
use function json_encode; use function json_encode;
use function mb_strtoupper;
use function min; use function min;
use function mkdir; use function mkdir;
use function preg_match; use function preg_match;
@ -58,7 +59,6 @@ use function round;
use function spl_object_hash; use function spl_object_hash;
use function sprintf; use function sprintf;
use function strlen; use function strlen;
use function strtoupper;
use function substr; use function substr;
use const JSON_PRETTY_PRINT; use const JSON_PRETTY_PRINT;
use const JSON_UNESCAPED_SLASHES; use const JSON_UNESCAPED_SLASHES;
@ -127,7 +127,7 @@ class MemoryManager{
if($m <= 0){ if($m <= 0){
$defaultMemory = 0; $defaultMemory = 0;
}else{ }else{
switch(strtoupper($matches[2])){ switch(mb_strtoupper($matches[2])){
case "K": case "K":
$defaultMemory = $m / 1024; $defaultMemory = $m / 1024;
break; break;

View File

@ -31,7 +31,7 @@ use pocketmine\event\player\PlayerExhaustEvent;
use pocketmine\utils\Color; use pocketmine\utils\Color;
use function constant; use function constant;
use function defined; use function defined;
use function strtoupper; use function mb_strtoupper;
class Effect{ class Effect{
public const SPEED = 1; public const SPEED = 1;
@ -102,7 +102,7 @@ class Effect{
} }
public static function getEffectByName(string $name) : ?Effect{ public static function getEffectByName(string $name) : ?Effect{
$const = self::class . "::" . strtoupper($name); $const = self::class . "::" . mb_strtoupper($name);
if(defined($const)){ if(defined($const)){
return self::getEffect(constant($const)); return self::getEffect(constant($const));
} }

View File

@ -25,7 +25,7 @@ namespace pocketmine\event;
use function constant; use function constant;
use function defined; use function defined;
use function strtoupper; use function mb_strtoupper;
/** /**
* List of event priorities * List of event priorities
@ -79,7 +79,7 @@ abstract class EventPriority{
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
*/ */
public static function fromString(string $name) : int{ public static function fromString(string $name) : int{
$name = strtoupper($name); $name = mb_strtoupper($name);
$const = self::class . "::" . $name; $const = self::class . "::" . $name;
if($name !== "ALL" and defined($const)){ if($name !== "ALL" and defined($const)){
return constant($const); return constant($const);

View File

@ -34,8 +34,8 @@ use function gettype;
use function is_numeric; use function is_numeric;
use function is_object; use function is_object;
use function is_string; use function is_string;
use function mb_strtoupper;
use function str_replace; use function str_replace;
use function strtoupper;
use function trim; use function trim;
/** /**
@ -375,8 +375,8 @@ class ItemFactory{
if(is_numeric($b[0])){ if(is_numeric($b[0])){
$item = self::get((int) $b[0], $meta); $item = self::get((int) $b[0], $meta);
}elseif(defined(ItemIds::class . "::" . strtoupper($b[0]))){ }elseif(defined(ItemIds::class . "::" . mb_strtoupper($b[0]))){
$item = self::get(constant(ItemIds::class . "::" . strtoupper($b[0])), $meta); $item = self::get(constant(ItemIds::class . "::" . mb_strtoupper($b[0])), $meta);
}else{ }else{
throw new \InvalidArgumentException("Unable to resolve \"" . $str . "\" to a valid item"); throw new \InvalidArgumentException("Unable to resolve \"" . $str . "\" to a valid item");
} }

View File

@ -26,7 +26,7 @@ namespace pocketmine\item\enchantment;
use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\entity\EntityDamageEvent;
use function constant; use function constant;
use function defined; use function defined;
use function strtoupper; use function mb_strtoupper;
/** /**
* Manages enchantment type data. * Manages enchantment type data.
@ -161,7 +161,7 @@ class Enchantment{
} }
public static function getEnchantmentByName(string $name) : ?Enchantment{ public static function getEnchantmentByName(string $name) : ?Enchantment{
$const = Enchantment::class . "::" . strtoupper($name); $const = Enchantment::class . "::" . mb_strtoupper($name);
if(defined($const)){ if(defined($const)){
return self::getEnchantment(constant($const)); return self::getEnchantment(constant($const));
} }

View File

@ -29,12 +29,12 @@ use function array_values;
use function constant; use function constant;
use function defined; use function defined;
use function is_array; use function is_array;
use function mb_strtoupper;
use function phpversion; use function phpversion;
use function preg_match; use function preg_match;
use function str_replace; use function str_replace;
use function stripos; use function stripos;
use function strlen; use function strlen;
use function strtoupper;
use function substr; use function substr;
use function version_compare; use function version_compare;
use function yaml_parse; use function yaml_parse;
@ -147,7 +147,7 @@ class PluginDescription{
$this->prefix = (string) ($plugin["prefix"] ?? $this->prefix); $this->prefix = (string) ($plugin["prefix"] ?? $this->prefix);
if(isset($plugin["load"])){ if(isset($plugin["load"])){
$order = strtoupper($plugin["load"]); $order = mb_strtoupper($plugin["load"]);
if(!defined(PluginLoadOrder::class . "::" . $order)){ if(!defined(PluginLoadOrder::class . "::" . $order)){
throw new PluginException("Invalid PluginDescription load"); throw new PluginException("Invalid PluginDescription load");
}else{ }else{

View File

@ -59,12 +59,12 @@ use function is_dir;
use function is_string; use function is_string;
use function is_subclass_of; use function is_subclass_of;
use function iterator_to_array; use function iterator_to_array;
use function mb_strtoupper;
use function mkdir; use function mkdir;
use function shuffle; use function shuffle;
use function stripos; use function stripos;
use function strpos; use function strpos;
use function strtolower; use function strtolower;
use function strtoupper;
use const DIRECTORY_SEPARATOR; use const DIRECTORY_SEPARATOR;
/** /**
@ -379,7 +379,7 @@ class PluginManager{
if($version !== $serverString){ if($version !== $serverString){
$pluginApi = array_pad(explode("-", $version, 2), 2, ""); //0 = version, 1 = suffix (optional) $pluginApi = array_pad(explode("-", $version, 2), 2, ""); //0 = version, 1 = suffix (optional)
if(strtoupper($pluginApi[1]) !== strtoupper($serverApi[1])){ //Different release phase (alpha vs. beta) or phase build (alpha.1 vs alpha.2) if(mb_strtoupper($pluginApi[1]) !== mb_strtoupper($serverApi[1])){ //Different release phase (alpha vs. beta) or phase build (alpha.1 vs alpha.2)
continue; continue;
} }