33namespace PHLAK \Twine \Traits ;
44
55use PHLAK \Twine \Config ;
6+ use PHLAK \Twine \Support ;
67use RuntimeException ;
78
89trait Caseable
@@ -95,8 +96,8 @@ public function lowercase(string $mode = Config\Lowercase::ALL) : self
9596 public function camelCase () : self
9697 {
9798 $ words = array_map (function ($ word ) {
98- return $ word-> uppercaseFirst ( );
99- }, $ this ->words ( ));
99+ return mb_strtoupper ( mb_substr ( $ word, 0 , 1 , $ this -> encoding ), $ this -> encoding ) . mb_substr ( $ word , 1 , null , $ this -> encoding );
100+ }, Support \Str:: words ( $ this ->string ));
100101
101102 $ word = implode ('' , $ words );
102103
@@ -113,8 +114,8 @@ public function camelCase() : self
113114 public function studlyCase () : self
114115 {
115116 $ words = array_map (function ($ word ) {
116- return $ word-> uppercaseFirst ( );
117- }, $ this ->words ( ));
117+ return mb_strtoupper ( mb_substr ( $ word, 0 , 1 , $ this -> encoding ), $ this -> encoding ) . mb_substr ( $ word , 1 , null , $ this -> encoding );
118+ }, Support \Str:: words ( $ this ->string ));
118119
119120 return new static (implode ('' , $ words ));
120121 }
@@ -137,8 +138,8 @@ public function pascalCase() : self
137138 public function snakeCase () : self
138139 {
139140 $ words = array_map (function ($ word ) {
140- return $ word-> lowercase ( );
141- }, $ this ->words ( ));
141+ return mb_strtolower ( $ word, $ this -> encoding );
142+ }, Support \Str:: words ( $ this ->string ));
142143
143144 return new static (implode ('_ ' , $ words ));
144145 }
@@ -151,8 +152,8 @@ public function snakeCase() : self
151152 public function kebabCase () : self
152153 {
153154 $ words = array_map (function ($ word ) {
154- return $ word-> lowercase ( );
155- }, $ this ->words ( ));
155+ return mb_strtolower ( $ word, $ this -> encoding );
156+ }, Support \Str:: words ( $ this ->string ));
156157
157158 return new static (implode ('- ' , $ words ));
158159 }
0 commit comments