diff --git a/src/Util/Common.php b/src/Util/Common.php index 204f44de14..dc890f46a9 100644 --- a/src/Util/Common.php +++ b/src/Util/Common.php @@ -346,49 +346,27 @@ public static function isCamelCaps( if ($strict === false) { // Can either start with a lowercase letter, or multiple uppercase // in a row, representing an acronym. - $legalFirstChar .= '([A-Z]{2,}|[a-z])'; + $legalFirstChar .= '([[:upper:]]{2,}|[[:lower:]])'; } else { - $legalFirstChar .= '[a-z]'; + $legalFirstChar .= '[[:lower:]]'; } } else { - $legalFirstChar = '[A-Z]'; + $legalFirstChar = '[[:upper:]]'; } - if (preg_match("/^$legalFirstChar/", $string) === 0) { + if (preg_match("/^$legalFirstChar/u", $string) === 0) { return false; } // Check that the name only contains legal characters. - $legalChars = 'a-zA-Z0-9'; - if (preg_match("|[^$legalChars]|", substr($string, 1)) > 0) { + if (preg_match('/^[[:alnum:]]*$/u', substr($string, 1)) === 0) { return false; } - if ($strict === true) { - // Check that there are not two capital letters next to each other. - $length = strlen($string); - $lastCharWasCaps = $classFormat; - - for ($i = 1; $i < $length; $i++) { - $ascii = ord($string[$i]); - if ($ascii >= 48 && $ascii <= 57) { - // The character is a number, so it cant be a capital. - $isCaps = false; - } else { - if (strtoupper($string[$i]) === $string[$i]) { - $isCaps = true; - } else { - $isCaps = false; - } - } - - if ($isCaps === true && $lastCharWasCaps === true) { - return false; - } - - $lastCharWasCaps = $isCaps; - } - }//end if + // Check that there are not two capital letters next to each other. + if ($strict === true && preg_match('/[[:upper:]]{2}/u', $string) === 1) { + return false; + } return true; diff --git a/tests/Core/IsCamelCapsTest.php b/tests/Core/IsCamelCapsTest.php index b60d524b03..04a30723be 100644 --- a/tests/Core/IsCamelCapsTest.php +++ b/tests/Core/IsCamelCapsTest.php @@ -25,6 +25,8 @@ public function testValidNotClassFormatPublic() { $this->assertTrue(Common::isCamelCaps('thisIsCamelCaps', false, true, true)); $this->assertTrue(Common::isCamelCaps('thisISCamelCaps', false, true, false)); + $this->assertTrue(Common::isCamelCaps('élément', false, true, false)); + $this->assertTrue(Common::isCamelCaps('unÉlément', false, true, false)); }//end testValidNotClassFormatPublic() @@ -39,6 +41,8 @@ public function testInvalidNotClassFormatPublic() $this->assertFalse(Common::isCamelCaps('_thisIsCamelCaps', false, true, true)); $this->assertFalse(Common::isCamelCaps('thisISCamelCaps', false, true, true)); $this->assertFalse(Common::isCamelCaps('ThisIsCamelCaps', false, true, true)); + $this->assertFalse(Common::isCamelCaps('Élément', false, true, true)); + $this->assertFalse(Common::isCamelCaps('UnÉlément', false, true, true)); $this->assertFalse(Common::isCamelCaps('3thisIsCamelCaps', false, true, true)); $this->assertFalse(Common::isCamelCaps('*thisIsCamelCaps', false, true, true)); @@ -61,6 +65,8 @@ public function testValidNotClassFormatPrivate() { $this->assertTrue(Common::isCamelCaps('_thisIsCamelCaps', false, false, true)); $this->assertTrue(Common::isCamelCaps('_thisISCamelCaps', false, false, false)); + $this->assertTrue(Common::isCamelCaps('_élément', false, false, false)); + $this->assertTrue(Common::isCamelCaps('_unÉlément', false, false, false)); $this->assertTrue(Common::isCamelCaps('_i18N', false, false, true)); $this->assertTrue(Common::isCamelCaps('_i18n', false, false, true)); @@ -79,6 +85,7 @@ public function testInvalidNotClassFormatPrivate() $this->assertFalse(Common::isCamelCaps('_ThisIsCamelCaps', false, false, true)); $this->assertFalse(Common::isCamelCaps('__thisIsCamelCaps', false, false, true)); $this->assertFalse(Common::isCamelCaps('__thisISCamelCaps', false, false, false)); + $this->assertFalse(Common::isCamelCaps('_unÉLément', false, false, true)); $this->assertFalse(Common::isCamelCaps('3thisIsCamelCaps', false, false, true)); $this->assertFalse(Common::isCamelCaps('*thisIsCamelCaps', false, false, true)); @@ -98,6 +105,7 @@ public function testValidClassFormatPublic() $this->assertTrue(Common::isCamelCaps('ThisIsCamelCaps', true, true, true)); $this->assertTrue(Common::isCamelCaps('ThisISCamelCaps', true, true, false)); $this->assertTrue(Common::isCamelCaps('This3IsCamelCaps', true, true, false)); + $this->assertTrue(Common::isCamelCaps('Élément', true, true, true)); }//end testValidClassFormatPublic() @@ -112,6 +120,7 @@ public function testInvalidClassFormat() $this->assertFalse(Common::isCamelCaps('thisIsCamelCaps', true)); $this->assertFalse(Common::isCamelCaps('This-IsCamelCaps', true)); $this->assertFalse(Common::isCamelCaps('This_Is_Camel_Caps', true)); + $this->assertFalse(Common::isCamelCaps('UnÉLément', true)); }//end testInvalidClassFormat() @@ -128,6 +137,7 @@ public function testInvalidClassFormatPrivate() { $this->assertFalse(Common::isCamelCaps('_ThisIsCamelCaps', true, true)); $this->assertFalse(Common::isCamelCaps('_ThisIsCamelCaps', true, false)); + $this->assertFalse(Common::isCamelCaps('_UnÉlément', true, false)); }//end testInvalidClassFormatPrivate()