diff --git a/composer.json b/composer.json index c13fd59..d6cdeef 100644 --- a/composer.json +++ b/composer.json @@ -18,6 +18,7 @@ "php-mock/php-mock-phpunit": "^2.1" }, "autoload": { + "files": ["src/string_functions.php"], "psr-4": { "TheIconic\\NameParser\\": ["src/", "tests/"] } diff --git a/src/Mapper/InitialMapper.php b/src/Mapper/InitialMapper.php index 3a75dc4..48bcddf 100644 --- a/src/Mapper/InitialMapper.php +++ b/src/Mapper/InitialMapper.php @@ -4,6 +4,8 @@ use TheIconic\NameParser\Part\AbstractPart; use TheIconic\NameParser\Part\Initial; +use function TheIconic\NameParser\characters; +use function TheIconic\NameParser\strlen; /** * single letter, possibly followed by a period @@ -46,7 +48,7 @@ public function map(array $parts): array $length = strlen($stripped); if (1 < $length && $length <= $this->combinedMax) { - array_splice($parts, $k, 1, str_split($stripped)); + array_splice($parts, $k, 1, characters($stripped)); $last = count($parts) - 1; $part = $parts[$k]; } diff --git a/src/Mapper/LastnameMapper.php b/src/Mapper/LastnameMapper.php index 43cfdc7..67fbae9 100644 --- a/src/Mapper/LastnameMapper.php +++ b/src/Mapper/LastnameMapper.php @@ -2,13 +2,13 @@ namespace TheIconic\NameParser\Mapper; -use TheIconic\NameParser\LanguageInterface; use TheIconic\NameParser\Part\AbstractPart; use TheIconic\NameParser\Part\Lastname; use TheIconic\NameParser\Part\LastnamePrefix; use TheIconic\NameParser\Part\Nickname; use TheIconic\NameParser\Part\Salutation; use TheIconic\NameParser\Part\Suffix; +use function TheIconic\NameParser\strlen; class LastnameMapper extends AbstractMapper { diff --git a/src/Part/AbstractPart.php b/src/Part/AbstractPart.php index 51e6372..cb9a5a2 100644 --- a/src/Part/AbstractPart.php +++ b/src/Part/AbstractPart.php @@ -2,6 +2,8 @@ namespace TheIconic\NameParser\Part; +use function TheIconic\NameParser\tcword; + abstract class AbstractPart { /** @@ -81,10 +83,6 @@ protected function camelcase($word): string */ protected function camelcaseReplace($matches): string { - if (function_exists('mb_convert_case')) { - return mb_convert_case($matches[0], MB_CASE_TITLE, 'UTF-8'); - } - - return ucfirst(strtolower($matches[0])); + return tcword($matches[0]); } } diff --git a/src/string_functions.php b/src/string_functions.php new file mode 100644 index 0000000..7f869ab --- /dev/null +++ b/src/string_functions.php @@ -0,0 +1,9 @@ +