[Rt-commit] [svn] r1068 - Text-Quoted
jesse at pallas.eruditorum.org
jesse at pallas.eruditorum.org
Mon Jun 14 15:37:46 EDT 2004
Author: jesse
Date: Mon Jun 14 15:37:46 2004
New Revision: 1068
Modified:
Text-Quoted/Makefile.PL
Text-Quoted/Quoted.pm
Log:
Updated dependencies, tidied source
Modified: Text-Quoted/Makefile.PL
==============================================================================
--- Text-Quoted/Makefile.PL (original)
+++ Text-Quoted/Makefile.PL Mon Jun 14 15:37:46 2004
@@ -5,7 +5,8 @@
'NAME' => 'Text::Quoted',
'VERSION_FROM' => 'Quoted.pm', # finds $VERSION
'PREREQ_PM' => {
- Text::Autoformat => 0
+ Text::Autoformat => 0,
+ Text::Tabs => 0
}, # e.g., Module::Name => 1.1
ABSTRACT_FROM => 'Quoted.pm', # retrieve abstract from module
AUTHOR => 'Jesse Vincent <jesse at bestpractical.com>'
Modified: Text-Quoted/Quoted.pm
==============================================================================
--- Text-Quoted/Quoted.pm (original)
+++ Text-Quoted/Quoted.pm Mon Jun 14 15:37:46 2004
@@ -6,10 +6,10 @@
require Exporter;
-our @ISA = qw(Exporter);
+our @ISA = qw(Exporter);
our @EXPORT = qw(extract);
-use Text::Autoformat (); # Provides the Hang package, heh, heh.
+use Text::Autoformat(); # Provides the Hang package, heh, heh.
=head1 NAME
@@ -59,14 +59,14 @@
=cut
sub extract {
- my $text = shift;
+ my $text = shift;
my @paras = classify($text);
my @needed;
for my $p (@paras) {
push @needed, { map { $_ => $p->{$_} } qw(raw empty text quoter) };
}
-
- return organize("", at needed);
+
+ return organize( "", @needed );
}
=head1 CREDITS
@@ -90,30 +90,35 @@
sub organize {
my $top_level = shift;
- my @todo = @_;
+ my @todo = @_;
my @ret;
+
# Recursively form a data structure which reflects the quoting
# structure of the list.
while (@todo) {
my $line = shift @todo;
- if (defn($line->{quoter}) eq defn($top_level)) {
+ if ( defn( $line->{quoter} ) eq defn($top_level) ) {
+
# Just append lines at "my" level.
- push @ret, $line
- if exists $line->{quoter} or exists $line->{empty};
- } elsif (defn($line->{quoter}) =~ /^\Q$top_level\E.+/) {
+ push @ret, $line
+ if exists $line->{quoter}
+ or exists $line->{empty};
+ }
+ elsif ( defn( $line->{quoter} ) =~ /^\Q$top_level\E.+/ ) {
+
# Find all the lines at a quoting level "below" me.
- my $newquoter = find_below($top_level, $line, @todo);
+ my $newquoter = find_below( $top_level, $line, @todo );
my @next = $line;
- push @next, shift @todo
- while defined $todo[0]->{quoter}
- and $todo[0]->{quoter} =~ /^\Q$newquoter/;
+ push @next, shift @todo while defined $todo[0]->{quoter}
+ and $todo[0]->{quoter} =~ /^\Q$newquoter/;
+
# Find the
# And pass them on to organize()!
#print "Trying to organise the following lines over $newquoter:\n";
#print $_->{raw}."\n" for @next;
#print "!-!-!-\n";
- push @ret, organize($newquoter, @next);
- }# else { die "bugger! I had $top_level, but now I have $line->{raw}\n"; }
+ push @ret, organize( $newquoter, @next );
+ } # else { die "bugger! I had $top_level, but now I have $line->{raw}\n"; }
}
return \@ret;
}
@@ -130,22 +135,25 @@
# works out which is the next level below us.
sub find_below {
- my ($top_level, @stuff) = @_;
+ my ( $top_level, @stuff ) = @_;
+
#print "## Looking for the next level of quoting after $top_level\n";
#print "## We have:\n";
#print "## $_->{raw}\n" for @stuff;
- my @prefices = sort { length $a <=> length $b }
- map { $_->{quoter} } @stuff;
+ my @prefices = sort { length $a <=> length $b } map { $_->{quoter} } @stuff;
+
# Find the prefices, shortest first.
# return $prefices[0] if $prefices[0] eq $prefices[-1];
-
- for (@prefices) {
+
+ for (@prefices) {
+
# And return the first one which is "below" where we are right
# now but is a proper subset of the next line.
next unless $_;
- if ($_ =~ /^\Q$top_level\E.+/ and $stuff[0]->{quoter} =~ /\Q$_\E/) {
+ if ( $_ =~ /^\Q$top_level\E.+/ and $stuff[0]->{quoter} =~ /\Q$_\E/ ) {
+
#print "## We decided on $_\n";
return $_;
}
@@ -157,115 +165,106 @@
# BITS OF A TEXT LINE
-my $quotechar = qq{[!#%=|:]};
+my $quotechar = qq{[!#%=|:]};
my $quotechunk = qq{(?:$quotechar(?!\\w)|\\w*>+)};
-my $quoter = qq{(?:(?i)(?:$quotechunk(?:[ \\t]*$quotechunk)*))};
+my $quoter = qq{(?:(?i)(?:$quotechunk(?:[ \\t]*$quotechunk)*))};
my $separator = q/(?:[-_]{2,}|[=#*]{3,}|[+~]{4,})/;
sub defn($) { return $_[0] if defined $_[0]; return ""; }
-sub classify
-{
+sub classify {
my $text = shift;
- # DETABIFY
- my @rawlines = split /\n/, $text;
- use Text::Tabs;
- @rawlines = expand(@rawlines);
-
- # PARSE EACH LINE
-
- my $pre = 0;
- my @lines;
- foreach (@rawlines)
- {
- push @lines, { raw => $_ };
- s/\A([ \t]*)($quoter?)([ \t]*)//;
- $lines[-1]{presig} = $lines[-1]{prespace} = defn $1;
- $lines[-1]{presig} .= $lines[-1]{quoter} = defn $2;
- $lines[-1]{presig} .= $lines[-1]{quotespace} = defn $3;
- $lines[-1]{hang} = defn(Hang->new($_));
-
- s/([ \t]*)(.*?)(\s*)$//;
- $lines[-1]{hangspace} = defn $1;
- $lines[-1]{text} = defn $2;
- $lines[-1]{empty} = $lines[-1]{hang}->empty() && $2 !~ /\S/;
- $lines[-1]{separator} = $lines[-1]{text} =~ /^$separator$/;
- }
-
- # SUBDIVIDE DOCUMENT INTO COHERENT SUBSECTIONS
-
- my @chunks;
- push @chunks, [shift @lines];
- foreach my $line (@lines)
- {
- if ($line->{separator} ||
- $line->{quoter} ne $chunks[-1][-1]->{quoter} ||
- $line->{empty} ||
- @chunks && $chunks[-1][-1]->{empty})
- {
- push @chunks, [$line];
- }
- else
- {
- push @{$chunks[-1]}, $line;
- }
- }
-
- # REDIVIDE INTO PARAGRAPHS
-
- my @paras;
- foreach my $chunk ( @chunks )
- {
- my $first = 1;
- my $firstfrom;
- foreach my $line ( @{$chunk} )
- {
- if ($first ||
- $line->{quoter} ne $paras[-1]->{quoter} ||
- $paras[-1]->{separator}
- )
- {
- push @paras, $line;
- $first = 0;
- $firstfrom = length($line->{raw}) - length($line->{text});
- }
- else
- {
- my $extraspace = length($line->{raw}) - length($line->{text}) - $firstfrom;
- $paras[-1]->{text} .= "\n" . q{ }x$extraspace . $line->{text};
- $paras[-1]->{raw} .= "\n" . $line->{raw};
- }
- }
- }
-
- my $remainder = "";
-
- # ALIGN QUOTERS
- # DETERMINE HANGING MARKER TYPE (BULLET, ALPHA, ROMAN, ETC.)
-
- my %sigs;
- my $lastquoted = 0;
- my $lastprespace = 0;
- for my $i ( 0..$#paras )
- {
- my $para = $paras[$i];
- if ($para->{quoter})
- {
- if ($lastquoted) { $para->{prespace} = $lastprespace }
- else { $lastquoted = 1; $lastprespace = $para->{prespace} }
- }
- else
- {
- $lastquoted = 0;
- }
- }
- # Reapply hangs
+ # DETABIFY
+ my @rawlines = split /\n/, $text;
+ use Text::Tabs;
+ @rawlines = expand(@rawlines);
+
+ # PARSE EACH LINE
+
+ my $pre = 0;
+ my @lines;
+ foreach (@rawlines) {
+ push @lines, { raw => $_ };
+ s/\A([ \t]*)($quoter?)([ \t]*)//;
+ $lines[-1]{presig} = $lines[-1]{prespace} = defn $1;
+ $lines[-1]{presig} .= $lines[-1]{quoter} = defn $2;
+ $lines[-1]{presig} .= $lines[-1]{quotespace} = defn $3;
+ $lines[-1]{hang} = defn( Hang->new($_) );
+
+ s/([ \t]*)(.*?)(\s*)$//;
+ $lines[-1]{hangspace} = defn $1;
+ $lines[-1]{text} = defn $2;
+ $lines[-1]{empty} = $lines[-1]{hang}->empty() && $2 !~ /\S/;
+ $lines[-1]{separator} = $lines[-1]{text} =~ /^$separator$/;
+ }
+
+ # SUBDIVIDE DOCUMENT INTO COHERENT SUBSECTIONS
+
+ my @chunks;
+ push @chunks, [ shift @lines ];
+ foreach my $line (@lines) {
+ if ( $line->{separator}
+ || $line->{quoter} ne $chunks[-1][-1]->{quoter}
+ || $line->{empty}
+ || @chunks && $chunks[-1][-1]->{empty} )
+ {
+ push @chunks, [$line];
+ }
+ else {
+ push @{ $chunks[-1] }, $line;
+ }
+ }
+
+ # REDIVIDE INTO PARAGRAPHS
+
+ my @paras;
+ foreach my $chunk (@chunks) {
+ my $first = 1;
+ my $firstfrom;
+ foreach my $line ( @{$chunk} ) {
+ if ( $first
+ || $line->{quoter} ne $paras[-1]->{quoter}
+ || $paras[-1]->{separator} )
+ {
+ push @paras, $line;
+ $first = 0;
+ $firstfrom = length( $line->{raw} ) - length( $line->{text} );
+ }
+ else {
+ my $extraspace =
+ length( $line->{raw} ) - length( $line->{text} ) - $firstfrom;
+ $paras[-1]->{text} .= "\n" . q{ } x $extraspace . $line->{text};
+ $paras[-1]->{raw} .= "\n" . $line->{raw};
+ }
+ }
+ }
+
+ my $remainder = "";
+
+ # ALIGN QUOTERS
+ # DETERMINE HANGING MARKER TYPE (BULLET, ALPHA, ROMAN, ETC.)
+
+ my %sigs;
+ my $lastquoted = 0;
+ my $lastprespace = 0;
+ for my $i ( 0 .. $#paras ) {
+ my $para = $paras[$i];
+ if ( $para->{quoter} ) {
+ if ($lastquoted) { $para->{prespace} = $lastprespace }
+ else { $lastquoted = 1; $lastprespace = $para->{prespace} }
+ }
+ else {
+ $lastquoted = 0;
+ }
+ }
+
+ # Reapply hangs
for (@paras) {
next unless my $hang = $_->{hang};
next unless $hang->stringify;
- $_->{text} = $hang->stringify . " ".$_->{text};
+ $_->{text} = $hang->stringify . " " . $_->{text};
}
return @paras;
}
More information about the Rt-commit
mailing list