Update of mhonarc/MHonArc/lib
Modified Files:
mhamain.pl mhtxtplain.pl
Log Message:
Bug #12314: Applied a fix that will work with versions of Perl with
the Encode module installed (i.e Perl >=5.8). The fix converts
the input to perl's internal utf-8 so line breaking is done on characters
vs bytes. The data is translated back after operation.
To avoid unnecessary translations, translation is not done on
us-ascii or iso-8859 sets, common 7/8-bit charsets. Of course,
conversion could be avoided for other 8-bit sets, but charset check
may cause more overhead then translation, so only common ones are
checked for.
======================================================================
FILE: mhonarc/MHonArc/lib/mhamain.pl
<http://www.mhonarc.org/cgi-bin/viewcvs.cgi/*checkout*/mhonarc/MHonArc/lib/mhamain.pl?rev=2.83>
<http://www.mhonarc.org/cgi-bin/viewcvs.cgi/mhonarc/MHonArc/lib/mhamain.pl.diff?r1=2.82&r2=2.83&diff_format=h>
--- mhamain.pl 9 Jun 2005 01:12:59 -0000 2.82
+++ mhamain.pl 20 Jun 2005 04:25:18 -0000 2.83
@@ -30,5 +30,5 @@
require 5;
-$VERSION = '2.6.12';
+$VERSION = '2.6.12+';
$VINFO =<<EndOfInfo;
MHonArc v$VERSION (Perl $] $^O)
======================================================================
FILE: mhonarc/MHonArc/lib/mhtxtplain.pl
<http://www.mhonarc.org/cgi-bin/viewcvs.cgi/*checkout*/mhonarc/MHonArc/lib/mhtxtplain.pl?rev=2.47>
<http://www.mhonarc.org/cgi-bin/viewcvs.cgi/mhonarc/MHonArc/lib/mhtxtplain.pl.diff?r1=2.46&r2=2.47&diff_format=h>
--- mhtxtplain.pl 27 May 2005 06:28:33 -0000 2.46
+++ mhtxtplain.pl 20 Jun 2005 04:25:18 -0000 2.47
@@ -318,5 +318,5 @@
## Check if max-width set
if (($maxwidth > 0) && ($quote_style != Q_FLOWED)) {
- $$data =~ s/^(.*)$/&break_line($1, $maxwidth)/gem;
+ break_lines($data, $charset, $maxwidth);
}
@@ -438,8 +438,5 @@
if ($maxwidth > 0) {
# Fixed lines should be clipped to specified max.
- $line =~ s/\n\Z//;
- $line = break_line(
- $line, $maxwidth+
- (length($line)-html_length($line))) . "\n";
+ $line = break_lines($line, $charset, $maxwidth, 1);
}
if ($nonfixed) {
@@ -633,5 +630,40 @@
##---------------------------------------------------------------------------##
-sub break_line {
+sub break_lines {
+ my $data_in = shift;
+ my $charset = shift;
+ my $maxwidth = shift;
+ my $is_html = shift; # hack for flowed processing
+ return unless $maxwidth > 0;
+
+ my $data = ref($data_in) ? $data_in : \$data_in;
+ my $do_encode = 0;
+ eval {
+ require Encode;
+ # Only translate to Perl's utf-8 if not an 8-bit charset.
+ # No harm if done for 8-bit, but try to avoid unnecesary
+ # overhead. Translation done so line breaking is done
+ # on characters, not octets.
+ if ($charset !~ /us-ascii/i &&
+ $charset !~ /8859/i &&
+ !Encode::is_utf8($$data)) {
+ $$data = Encode::decode($charset, $$data);
+ $do_encode = 1;
+ }
+ };
+ $$data =~ s{
+ ^(.*)$
+ }{
+ _break_line($1, ($is_html ? $maxwidth+(length($1)-html_length($1))
+ : $maxwidth))
+ }gemx;
+ if ($do_encode) {
+ # Translate back to current encoding.
+ $$data = Encode::encode($charset, $$data);
+ }
+ $$data;
+}
+
+sub _break_line {
my($str) = shift;
my($width) = shift;
---------------------------------------------------------------------
To sign-off this list, send email to majordomo(_at_)mhonarc(_dot_)org with the
message text UNSUBSCRIBE MHONARC-COMMITS