Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Abstract string functions to support both mbstring and native
- Loading branch information
Showing
7 changed files
with
79 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
if (!function_exists('TheIconic\NameParser\strlen')) { | ||
if (extension_loaded('mbstring')) { | ||
require __DIR__ . '/string_functions_mbstring.php'; | ||
} else { | ||
require __DIR__ . '/string_functions_native.php'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace TheIconic\NameParser; | ||
|
||
if (!function_exists('TheIconic\NameParser\strlen')) { | ||
function strlen(string $string): int | ||
{ | ||
return \mb_strlen($string, 'UTF-8'); | ||
} | ||
} | ||
|
||
if (!function_exists('TheIconic\NameParser\tcword')) { | ||
function tcword(string $string): string | ||
{ | ||
return \mb_convert_case($string, MB_CASE_TITLE, 'UTF-8'); | ||
} | ||
} | ||
|
||
if (!function_exists('TheIconic\NameParser\characters')) { | ||
function characters(string $string): array | ||
{ | ||
return $charactersAsArray = \preg_split('//u', $string, null, PREG_SPLIT_NO_EMPTY); | ||
} | ||
} | ||
|
||
if (!function_exists('TheIconic\NameParser\substr')) { | ||
function substr(string $string, int $start, int $length = null): string | ||
{ | ||
return \mb_substr($string, $start, $length, 'UTF-8'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace TheIconic\NameParser; | ||
|
||
if (!function_exists('TheIconic\NameParser\strlen')) { | ||
function strlen(string $string): int | ||
{ | ||
return \strlen($string); | ||
} | ||
} | ||
|
||
if (!function_exists('TheIconic\NameParser\tcword')) { | ||
function tcword(string $string): string | ||
{ | ||
return \ucfirst(\strtolower($string)); | ||
} | ||
} | ||
|
||
if (!function_exists('TheIconic\NameParser\characters')) { | ||
function characters(string $string): array | ||
{ | ||
return \str_split($string, $split_length = 1); | ||
} | ||
} | ||
|
||
if (!function_exists('TheIconic\NameParser\substr')) { | ||
function substr(string $string, int $start, int $length = null): string | ||
{ | ||
return \substr($string, $start, $length); | ||
} | ||
} |