@@ -2877,7 +2877,6 @@ function count_array_diff(
2877
2877
2878
2878
function generate_array_diff (array $ ar1 , array $ ar2 , bool $ is_reg , array $ w ): array
2879
2879
{
2880
- global $ colorize ;
2881
2880
$ idx1 = 0 ;
2882
2881
$ cnt1 = @count ($ ar1 );
2883
2882
$ idx2 = 0 ;
@@ -2886,25 +2885,6 @@ function generate_array_diff(array $ar1, array $ar2, bool $is_reg, array $w): ar
2886
2885
$ old1 = [];
2887
2886
$ old2 = [];
2888
2887
2889
- $ format_expected_line = function (int $ line_number , string $ contents ) use ($ colorize ): string {
2890
- $ output = sprintf ("%03d- " , $ line_number ) . $ contents ;
2891
- if ($ colorize ) {
2892
- // Reuse the colors used for `-` in other diff tools.
2893
- // Here, red should be interpreted as "removed", and not "bad".
2894
- return "\e[1;31m {$ output }\e[0m " ;
2895
- }
2896
- return $ output ;
2897
- };
2898
- $ format_actual_line = function (int $ line_number , string $ contents ) use ($ colorize ): string {
2899
- $ output = sprintf ("%03d+ " , $ line_number ) . $ contents ;
2900
- if ($ colorize ) {
2901
- // Reuse the colors used for `+` in other diff tools.
2902
- // Here, green should be interpreted as "added", and not "good".
2903
- return "\e[1;32m {$ output }\e[0m " ;
2904
- }
2905
- return $ output ;
2906
- };
2907
-
2908
2888
while ($ idx1 < $ cnt1 && $ idx2 < $ cnt2 ) {
2909
2889
if (comp_line ($ ar1 [$ idx1 ], $ ar2 [$ idx2 ], $ is_reg )) {
2910
2890
$ idx1 ++;
@@ -2915,12 +2895,12 @@ function generate_array_diff(array $ar1, array $ar2, bool $is_reg, array $w): ar
2915
2895
$ c2 = @count_array_diff ($ ar1 , $ ar2 , $ is_reg , $ w , $ idx1 , $ idx2 + 1 , $ cnt1 , $ cnt2 , 10 );
2916
2896
2917
2897
if ($ c1 > $ c2 ) {
2918
- $ old1 [$ idx1 ] = $ format_expected_line ( $ idx1 + 1 , $ w [$ idx1 ++]) ;
2898
+ $ old1 [$ idx1 ] = sprintf ( " %03d- " , $ idx1 + 1 ) . $ w [$ idx1 ++];
2919
2899
} elseif ($ c2 > 0 ) {
2920
- $ old2 [$ idx2 ] = $ format_actual_line ( $ idx2 + 1 , $ ar2 [$ idx2 ++]) ;
2900
+ $ old2 [$ idx2 ] = sprintf ( " %03d+ " , $ idx2 + 1 ) . $ ar2 [$ idx2 ++];
2921
2901
} else {
2922
- $ old1 [$ idx1 ] = $ format_expected_line ( $ idx1 + 1 , $ w [$ idx1 ++]) ;
2923
- $ old2 [$ idx2 ] = $ format_actual_line ( $ idx2 + 1 , $ ar2 [$ idx2 ++]) ;
2902
+ $ old1 [$ idx1 ] = sprintf ( " %03d- " , $ idx1 + 1 ) . $ w [$ idx1 ++];
2903
+ $ old2 [$ idx2 ] = sprintf ( " %03d+ " , $ idx2 + 1 ) . $ ar2 [$ idx2 ++];
2924
2904
}
2925
2905
}
2926
2906
}
@@ -2953,11 +2933,11 @@ function generate_array_diff(array $ar1, array $ar2, bool $is_reg, array $w): ar
2953
2933
}
2954
2934
2955
2935
while ($ idx1 < $ cnt1 ) {
2956
- $ diff [] = $ format_expected_line ( $ idx1 + 1 , $ w [$ idx1 ++]) ;
2936
+ $ diff [] = sprintf ( " %03d- " , $ idx1 + 1 ) . $ w [$ idx1 ++];
2957
2937
}
2958
2938
2959
2939
while ($ idx2 < $ cnt2 ) {
2960
- $ diff [] = $ format_actual_line ( $ idx2 + 1 , $ ar2 [$ idx2 ++]) ;
2940
+ $ diff [] = sprintf ( " %03d+ " , $ idx2 + 1 ) . $ ar2 [$ idx2 ++];
2961
2941
}
2962
2942
2963
2943
return $ diff ;
0 commit comments