From acf37643b34e6932dcba944ff9ff2614774f7599 Mon Sep 17 00:00:00 2001 From: glebaster Date: Sun, 14 Mar 2021 21:47:57 +0300 Subject: [PATCH 1/2] issue1 + issue https://github.com/rmasters/filter/issues/2 --- composer.json | 3 ++- src/Filter/Filter.php | 30 ++++++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index eff5f00..59e5d25 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,8 @@ "require": { "php": ">=5.4.0", "illuminate/support": "4.*", - "illuminate/container": "4.*" + "illuminate/container": "4.*", + "ext-mbstring": "*" }, "require-dev": { "phpunit/phpunit": "3.7.*", diff --git a/src/Filter/Filter.php b/src/Filter/Filter.php index a1297ec..7c43714 100644 --- a/src/Filter/Filter.php +++ b/src/Filter/Filter.php @@ -181,19 +181,41 @@ public function registerDefaultFilters() }); $this->registerFilter('upper', function($value, array $args) { - return strtoupper($value); + return mb_strtoupper($value); }); $this->registerFilter('lower', function($value, array $args) { - return strtolower($value); + return mb_strtolower($value); }); $this->registerFilter('capfirst', function($value, array $args) { - return ucfirst($value); + return $this->mb_ucfirst($value); }); $this->registerFilter('lowerfirst', function($value, array $args) { - return lcfirst($value); + return $this->mb_lcfirst($value); }); } + + /** + * @param $string + * @return string + */ + protected function mb_ucfirst($string) + { + $firstChar = mb_substr($string, 0, 1); + $then = mb_substr($string, 1, null); + return mb_strtoupper($firstChar) . $then; + } + + /** + * @param $string + * @return string + */ + protected function mb_lcfirst($string) + { + $firstChar = mb_substr($string, 0, 1); + $then = mb_substr($string, 1, null); + return mb_strtolower($firstChar) . $then; + } } \ No newline at end of file From 67a79c3550e98cd8ae9e794ab29d1891d82e6b01 Mon Sep 17 00:00:00 2001 From: glebaster Date: Fri, 19 Mar 2021 17:31:13 +0300 Subject: [PATCH 2/2] issue1 + correction to issue https://github.com/rmasters/filter/issues/2 --- src/Filter/Filter.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Filter/Filter.php b/src/Filter/Filter.php index 7c43714..fd72a18 100644 --- a/src/Filter/Filter.php +++ b/src/Filter/Filter.php @@ -199,23 +199,24 @@ public function registerDefaultFilters() /** * @param $string + * @param string $encoding * @return string */ - protected function mb_ucfirst($string) + protected function mb_ucfirst($string, $encoding = 'UTF-8') { - $firstChar = mb_substr($string, 0, 1); - $then = mb_substr($string, 1, null); - return mb_strtoupper($firstChar) . $then; + $firstChar = mb_substr($string, 0, 1, $encoding); + $then = mb_substr($string, 1, null, $encoding); + return mb_strtoupper($firstChar, $encoding) . $then; } /** * @param $string * @return string */ - protected function mb_lcfirst($string) + protected function mb_lcfirst($string, $encoding = 'UTF-8') { - $firstChar = mb_substr($string, 0, 1); - $then = mb_substr($string, 1, null); - return mb_strtolower($firstChar) . $then; + $firstChar = mb_substr($string, 0, 1, $encoding); + $then = mb_substr($string, 1, null, $encoding); + return mb_strtolower($firstChar, $encoding) . $then; } } \ No newline at end of file