diff --git a/src/StaticStringy.php b/src/StaticStringy.php index ebbeb89..08afea8 100644 --- a/src/StaticStringy.php +++ b/src/StaticStringy.php @@ -747,6 +747,18 @@ class StaticStringy return Stringy::create($str, $encoding)->isLowerCase(); } + /** + * Returns whether the given string has any lower case characters in it. + * + * @param string $str String to check + * @param string $encoding The character encoding + * @return bool Whether or not $str contains a lower case character. + */ + public static function hasLowerCase($str, $encoding = null) + { + return Stringy::create($str, $encoding)->hasLowerCase(); + } + /** * Returns true if the string is serialized, false otherwise. * @@ -772,6 +784,18 @@ class StaticStringy return Stringy::create($str, $encoding)->isUpperCase(); } + /** + * Returns whether the given string has any upper case characters in it. + * + * @param string $str String to check + * @param string $encoding The character encoding + * @return bool Whether or not $str contains an upper case character. + */ + public static function hasUpperCase($str, $encoding = null) + { + return Stringy::create($str, $encoding)->hasUpperCase(); + } + /** * Returns true if the string contains only hexadecimal chars, false * otherwise. diff --git a/src/Stringy.php b/src/Stringy.php index 68fa30b..d715658 100644 --- a/src/Stringy.php +++ b/src/Stringy.php @@ -1333,6 +1333,17 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess return $this->matchesPattern('^[[:lower:]]*$'); } + /** + * Returns true if the string contains a lower case char, false + * otherwise. + * + * @return bool Whether or not the string contains a lower case character. + */ + public function hasLowerCase() + { + return $this->matchesPattern('.*[[:lower:]]'); + } + /** * Returns true if the string contains only lower case chars, false * otherwise. @@ -1344,6 +1355,17 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess return $this->matchesPattern('^[[:upper:]]*$'); } + /** + * Returns true if the string contains an upper case char, false + * otherwise. + * + * @return bool Whether or not the string contains an upper case character. + */ + public function hasUpperCase() + { + return $this->matchesPattern('.*[[:upper:]]'); + } + /** * Returns true if the string is serialized, false otherwise. * diff --git a/tests/CommonTest.php b/tests/CommonTest.php index d6a7009..2076a71 100644 --- a/tests/CommonTest.php +++ b/tests/CommonTest.php @@ -884,6 +884,24 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase ); } + public function hasLowerCaseProvider() + { + return array( + array(false, ''), + array(true, 'foobar'), + array(false, 'FOO BAR'), + array(true, 'fOO BAR'), + array(true, 'foO BAR'), + array(true, 'FOO BAr'), + array(true, 'Foobar'), + array(false, 'FÒÔBÀŘ', 'UTF-8'), + array(true, 'fòôbàř', 'UTF-8'), + array(true, 'fòôbàř2', 'UTF-8'), + array(true, 'Fòô bàř', 'UTF-8'), + array(true, 'fòôbÀŘ', 'UTF-8'), + ); + } + public function isSerializedProvider() { return array( @@ -911,6 +929,24 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase ); } + public function hasUpperCaseProvider() + { + return array( + array(false, ''), + array(true, 'FOOBAR'), + array(false, 'foo bar'), + array(true, 'Foo bar'), + array(true, 'FOo bar'), + array(true, 'foo baR'), + array(true, 'fOOBAR'), + array(false, 'fòôbàř', 'UTF-8'), + array(true, 'FÒÔBÀŘ', 'UTF-8'), + array(true, 'FÒÔBÀŘ2', 'UTF-8'), + array(true, 'fÒÔ BÀŘ', 'UTF-8'), + array(true, 'FÒÔBàř', 'UTF-8'), + ); + } + public function isHexadecimalProvider() { return array( diff --git a/tests/StaticStringyTest.php b/tests/StaticStringyTest.php index 49c58e7..d6e3063 100644 --- a/tests/StaticStringyTest.php +++ b/tests/StaticStringyTest.php @@ -565,6 +565,16 @@ class StaticStringyTestCase extends CommonTest $this->assertEquals($expected, $result); } + /** + * @dataProvider hasLowerCaseProvider() + */ + public function testHasLowerCase($expected, $str, $encoding = null) + { + $result = S::hasLowerCase($str, $encoding); + $this->assertInternalType('boolean', $result); + $this->assertEquals($expected, $result); + } + /** * @dataProvider isSerializedProvider() */ @@ -585,6 +595,16 @@ class StaticStringyTestCase extends CommonTest $this->assertEquals($expected, $result); } + /** + * @dataProvider hasUpperCaseProvider() + */ + public function testHasUpperCase($expected, $str, $encoding = null) + { + $result = S::hasUpperCase($str, $encoding); + $this->assertInternalType('boolean', $result); + $this->assertEquals($expected, $result); + } + /** * @dataProvider isHexadecimalProvider() */ diff --git a/tests/StringyTest.php b/tests/StringyTest.php index 0a60a7b..95a7696 100644 --- a/tests/StringyTest.php +++ b/tests/StringyTest.php @@ -813,6 +813,18 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + /** + * @dataProvider hasLowerCaseProvider() + */ + public function testHasLowerCase($expected, $str, $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->hasLowerCase(); + $this->assertInternalType('boolean', $result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + /** * @dataProvider isSerializedProvider() */ @@ -837,6 +849,18 @@ class StringyTestCase extends CommonTest $this->assertEquals($str, $stringy); } + /** + * @dataProvider hasUpperCaseProvider() + */ + public function testHasUpperCase($expected, $str, $encoding = null) + { + $stringy = S::create($str, $encoding); + $result = $stringy->hasUpperCase(); + $this->assertInternalType('boolean', $result); + $this->assertEquals($expected, $result); + $this->assertEquals($str, $stringy); + } + /** * @dataProvider isHexadecimalProvider() */