- Added --use-unicode-gcstring to control use of Unicode::GCString for
evaluating character widths of encoded data. By default, for encoded files
perltidy will now look for Unicode::GCString and, if found, will use it
- to evaluate character display widths. This improves displayed
- vertical alignment. This flag is mainly intended for testing. Perltidy
- installation does not require Unicode::GCString, so users wanting
- to use this feature need to install it separately.
+ to evaluate character display widths. This can improve displayed
+ vertical alignment for files with wide characters. This flag is mainly intended
+ for testing, but can also prevent the use of this module in the event that some
+ unforseen issue arises. Perltidy installation does not require
+ Unicode::GCString, so users wanting to use this feature need to install it
+ separately.
- Added --character-encoding=guess or -guess to have perltidy guess
if a file is encoded as -utf8 or some older single-byte encoding. This
# we must not treat it as encoded data.
my $is_encoded_data = $encoding_in ? 'utf8' : "";
- my $use_unicode_gcstring;
+ # Define the function to determine the display width of character strings
+ my $length_function = sub { return length( $_[0] ) };
if ($is_encoded_data) {
# Delete any Byte Order Mark (BOM), which can cause trouble
eval { require Unicode::GCString };
$loaded_unicode_gcstring = !$@;
}
- $use_unicode_gcstring = $loaded_unicode_gcstring;
+ if ($loaded_unicode_gcstring) {
+ $length_function = sub {
+ return Unicode::GCString->new( $_[0] )->columns;
+ };
+ }
}
# MD5 sum of input file is evaluated before any prefilter
}
elsif ( $rOpts->{'format'} eq 'tidy' ) {
$formatter = Perl::Tidy::Formatter->new(
- logger_object => $logger_object,
- diagnostics_object => $diagnostics_object,
- sink_object => $sink_object,
- use_unicode_gcstring => $use_unicode_gcstring,
+ logger_object => $logger_object,
+ diagnostics_object => $diagnostics_object,
+ sink_object => $sink_object,
+ length_function => $length_function,
);
}
else {
# we are given an object with a write_line() method to take lines
my %defaults = (
- sink_object => undef,
- diagnostics_object => undef,
- logger_object => undef,
- use_unicode_gcstring => undef,
+ sink_object => undef,
+ diagnostics_object => undef,
+ logger_object => undef,
+ length_function => sub { return length( $_[0] ) },
);
my %args = ( %defaults, @args );
- my $use_unicode_gcstring = $args{use_unicode_gcstring};
+ my $length_function = $args{length_function};
$logger_object = $args{logger_object};
$diagnostics_object = $args{diagnostics_object};
rK_phantom_semicolons =>
undef, # for undoing phantom semicolons if iterating
rpaired_to_inner_container => {},
- rbreak_container => {}, # prevent one-line blocks
- rshort_nested => {}, # blocks not forced open
- rvalid_self_keys => [], # for checking
+ rbreak_container => {}, # prevent one-line blocks
+ rshort_nested => {}, # blocks not forced open
+ rvalid_self_keys => [], # for checking
valign_batch_count => 0,
- use_unicode_gcstring => $use_unicode_gcstring,
+ length_function => $length_function,
};
my @valid_keys = keys %{$formatter_self};
$formatter_self->{rvalid_self_keys} = \@valid_keys;
my $Klimit_old = $self->{Klimit};
my $rlines = $self->{rlines};
my $rpaired_to_inner_container = $self->{rpaired_to_inner_container};
- my $use_unicode_gcstring = $self->{use_unicode_gcstring};
-
- # Define a function for evaluating the display width of text
- my $length_function = sub { return length( $_[0] ) };
- if ($use_unicode_gcstring) {
- $length_function = sub {
- return Unicode::GCString->new( $_[0] )->columns;
- };
- }
+ my $length_function = $self->{length_function};
my $rLL_new = []; # This is the new array
my $KK = 0;