File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ function print_usage_and_exit(string $msg = '') {
77}
88
99function convert_codestyle () {
10+ error_reporting (E_ALL );
1011 global $ argv ;
1112 if (count ($ argv ) !== 2 ) {
1213 print_usage_and_exit ();
@@ -26,6 +27,23 @@ function convert_codestyle() {
2627 return '_ ' . strtolower ($ msg [0 ]) . $ msg [1 ];
2728 }, $ args [2 ]);
2829 }, $ contents );
30+
31+ preg_match_all ('@\bfunction\s+(_?[a-z]+(_[a-z]+)+)\s*\(@ ' , $ new_contents , $ matches );
32+ $ function_names = $ matches [1 ];
33+ $ function_names_set = array_flip ($ function_names );
34+ $ new_contents = preg_replace_callback ('@\b_?[a-z]+(_[a-z]+)+\b@ ' , function (array $ args ) use ($ function_names_set ) : string {
35+ $ name = $ args [0 ];
36+ if (!isset ($ function_names_set [$ name ])) {
37+ return $ name ;
38+ }
39+ $ name = ltrim ($ name , '_ ' );
40+ $ name = preg_replace_callback ('@_[a-z]@ ' , function (array $ args ) {
41+ $ msg = $ args [0 ];
42+ assert (strlen ($ msg ) === 2 );
43+ return strtoupper ($ msg [1 ]);
44+ }, $ name );
45+ return $ name ;
46+ }, $ new_contents );
2947 echo $ new_contents ;
3048}
3149
You can’t perform that action at this time.
0 commit comments