Author: jamessan
Date: 2009-08-19 22:51:08 +0000 (Wed, 19 Aug 2009)
New Revision: 1967
Modified:
trunk/scripts/debchange.pl
Log:
dch: Use the difference in length($unicode_string) vs. length($utf8_string) to
determine how many spaces should be padded when using format().
Modified: trunk/scripts/debchange.pl
===================================================================
--- trunk/scripts/debchange.pl 2009-08-19 22:10:20 UTC (rev 1966)
+++ trunk/scripts/debchange.pl 2009-08-19 22:51:08 UTC (rev 1967)
@@ -33,7 +33,8 @@
use strict;
use open ':utf8'; # changelogs are written with UTF-8 encoding
use filetest 'access'; # use access rather than stat for -w
-use Encode 'decode_utf8'; # for checking whether user names are valid
+# for checking whether user names are valid and making format() behave
+use Encode qw/decode_utf8 encode_utf8/;
use Getopt::Long;
use File::Copy;
use File::Basename;
@@ -1248,7 +1249,7 @@
};
if (! $opt_r) {
- # Add a multi-maintainer header...
+ # Add a multi-maintainer header...
if ($multimaint) {
# ...unless there already is one for this maintainer.
if (!defined $maintline) {
@@ -1453,15 +1454,14 @@
my $newentry=shift;
# Work around the fact that write() with formats
- # seems to assume that characters are 7-bit
+ # seems to assume that characters are single-byte
# See http://rt.perl.org/rt3/Public/Bug/Display.html?id=33832
# and Debian bugs #473769 and #541484
- # High-bit single characters need an extra space adding per
- # character, extended Unicode characters two
- my $count = () = $CHGLINE =~ /[^\x00-\x7F]/mg;
+ # This relies on $CHGLINE being a sequence of unicode characters. We can
+ # compare how many unicode characters we have to how many bytes we have
+ # when encoding to utf8 and therefore how many spaces we need to pad.
+ my $count = length(encode_utf8($CHGLINE)) - length($CHGLINE);
$CHGLINE .= " " x $count;
- $count = () = $CHGLINE =~ /[\x{0100}-\x{ffff}]/mg;
- $CHGLINE .= " " x $count;
print O "\n" if $opt_news && ! ($newentry || $linecount);
$linecount++;
--
To unsubscribe, send mail to [email protected].