1: <?php
2:
3: 4: 5: 6: 7: 8:
9:
10: use Chromabits\Nucleus\Data\ArrayList;
11: use Chromabits\Nucleus\Support\Std;
12:
13: if (!function_exists('mb_lcfirst')) {
14: 15: 16: 17: 18: 19: 20: 21:
22: function mb_lcfirst($str, $encoding = null)
23: {
24: $encoding = Std::coalesce($encoding, mb_internal_encoding());
25:
26: $first = mb_strtolower(
27: mb_substr($str, 0, 1, $encoding),
28: $encoding
29: );
30:
31: return $first . mb_substr($str, 1, null, $encoding);
32: }
33: }
34:
35: if (!function_exists('mb_ucfirst')) {
36: 37: 38: 39: 40: 41: 42: 43:
44: function mb_ucfirst($str, $encoding = null)
45: {
46: $encoding = Std::coalesce($encoding, mb_internal_encoding());
47:
48: $first = mb_strtoupper(
49: mb_substr($str, 0, 1, $encoding),
50: $encoding
51: );
52:
53: return $first . mb_substr($str, 1, null, $encoding);
54: }
55: }
56:
57: if (!function_exists('mb_ctype_lower')) {
58: 59: 60: 61: 62: 63: 64: 65:
66: function mb_ctype_lower($text, $encoding = null)
67: {
68: $encoding = Std::coalesce($encoding, mb_internal_encoding());
69: $characters = preg_split('//u', $text, -1, PREG_SPLIT_NO_EMPTY);
70:
71: foreach ($characters as $char) {
72: if (mb_strtolower($char, $encoding) != $char) {
73: return false;
74: }
75: }
76:
77: return true;
78: }
79: }
80:
81: if (!function_exists('mb_ucwords')) {
82: 83: 84: 85: 86: 87: 88: 89: 90:
91: function mb_ucwords($str, $delimiters = " \t\r\n\f\v", $encoding = null)
92: {
93: $encoding = Std::coalesce($encoding, mb_internal_encoding());
94:
95: $delimitersArray = mb_str_split($delimiters, 1, $encoding);
96: $upper = true;
97: $result = '';
98:
99: for ($ii = 0; $ii < mb_strlen($str, $encoding); $ii++) {
100: $char = mb_substr($str, $ii, 1, $encoding);
101:
102: if ($upper) {
103: $char = mb_convert_case($char, MB_CASE_UPPER, $encoding);
104: $upper = false;
105: } elseif (ArrayList::of($delimitersArray)->includes($char)) {
106: $upper = true;
107: }
108:
109: $result .= $char;
110: }
111:
112: return $result;
113: }
114: }
115:
116: if (!function_exists('mb_str_split')) {
117: 118: 119: 120: 121: 122: 123: 124:
125: function mb_str_split($string, $splitLength = 1, $encoding = null)
126: {
127: if ($splitLength == 0) {
128: throw new Exception(
129: 'The length of each segment must be greater than zero'
130: );
131: }
132:
133: $result = [];
134: $len = mb_strlen($string, $encoding);
135:
136: for ($ii = 0; $ii < $len; $ii += $splitLength) {
137: $result[] = mb_substr($string, $ii, $splitLength, $encoding);
138: }
139:
140: if (empty($result)) {
141: return [''];
142: }
143:
144: return $result;
145: }
146: }
147: