From 63aff0f18c0b4a88cef5ff2feec591ba5631f858 Mon Sep 17 00:00:00 2001 From: Anton Gorbylev Date: Tue, 16 Oct 2018 09:46:44 +0200 Subject: [PATCH 1/2] =?UTF-8?q?=D0=9F=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=B8=D0=BC=D1=91=D0=BD=20=D0=B2=20=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D1=85=D0=BD=D0=B5=D0=BC=20=D1=80=D0=B5=D0=B3=D0=B8=D1=81?= =?UTF-8?q?=D1=82=D1=80=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Petrovich.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Petrovich.php b/Petrovich.php index 5c8ac35..dbec65f 100644 --- a/Petrovich.php +++ b/Petrovich.php @@ -15,7 +15,7 @@ class Petrovich { const GENDER_MALE = 1; // Мужской const GENDER_FEMALE = 2; // Женский - private $gender = Petrovich::GENDER_ANDROGYNOUS; //Пол male/мужской female/женский + private $gender = Petrovich::GENDER_ANDROGYNOUS; //Пол male/мужской female/женский /** * Конструтор класса Петрович @@ -48,8 +48,8 @@ public function detectGender($middlename) { if(empty($middlename)) throw new Exception('Middlename cannot be empty.'); - - switch ( mb_substr( mb_strtolower($middlename) , -4)) + + switch ( mb_substr( mb_strtolower($middlename) , -4)) { case 'оглы': return Petrovich::GENDER_MALE; break; case 'кызы': return Petrovich::GENDER_FEMALE; break; @@ -157,8 +157,8 @@ private function findInRules($name,$case,$type) { if ( ! $this->checkGender($rule->gender) ) continue; foreach($rule->test as $last_char) { - $last_name_char = mb_substr($name,mb_strlen($name)-mb_strlen($last_char),mb_strlen($last_char)); - if($last_char == $last_name_char) { + $last_name_char = mb_strtolower(mb_substr($name,mb_strlen($name)-mb_strlen($last_char),mb_strlen($last_char))); + if(mb_strtolower($last_char) == $last_name_char) { if($rule->mods[$case] == '.') return $name; return $this->applyRule($rule->mods,$name,$case); @@ -203,7 +203,12 @@ private function checkException($name,$case,$type) { * @return string */ private function applyRule($mods,$name,$case) { + $isUpperCase = ($name != mb_strtolower($name)); $result = mb_substr($name,0,mb_strlen($name) - mb_substr_count($mods[$case],'-')); + if($isUpperCase) + { + $mods[$case] = mb_strtoupper($mods[$case]); + } $result .= str_replace('-','',$mods[$case]); return $result; } From f4485c73140563c9a6864b736d13a86e5d2e3466 Mon Sep 17 00:00:00 2001 From: Anton Gorbylev Date: Tue, 16 Oct 2018 12:36:27 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=D0=9F=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=B8=D0=BC=D1=91=D0=BD=20=D0=B2=20=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D1=85=D0=BD=D0=B5=D0=BC=20=D1=80=D0=B5=D0=B3=D0=B8=D1=81?= =?UTF-8?q?=D1=82=D1=80=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Petrovich.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Petrovich.php b/Petrovich.php index dbec65f..87bcf83 100644 --- a/Petrovich.php +++ b/Petrovich.php @@ -203,7 +203,8 @@ private function checkException($name,$case,$type) { * @return string */ private function applyRule($mods,$name,$case) { - $isUpperCase = ($name != mb_strtolower($name)); + $nameWithoutFirstLetter = mb_substr($name, 1); + $isUpperCase = ($nameWithoutFirstLetter != mb_strtolower($nameWithoutFirstLetter)); $result = mb_substr($name,0,mb_strlen($name) - mb_substr_count($mods[$case],'-')); if($isUpperCase) {