User: sits
Date: 08/06/19 19:34:00
Modified: lib/Codestriker/Http HtmlEntityLineFilter.pm
NonHighlightedLxrLineFilter.pm
HighlightedLxrLineFilter.pm DeltaRenderer.pm
TabToNbspLineFilter.pm LxrLineFilter.pm
HighlightLineFilter.pm LineBreakLineFilter.pm
LineFilter.pm
Log:
More refactorings to make the highlighting code clearer.
Index: HtmlEntityLineFilter.pm
===================================================================
RCS file:
/cvsroot/codestriker/codestriker/lib/Codestriker/Http/HtmlEntityLineFilter.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- HtmlEntityLineFilter.pm 16 Jun 2008 11:32:05 -0000 1.2
+++ HtmlEntityLineFilter.pm 20 Jun 2008 02:34:00 -0000 1.3
@@ -24,11 +24,9 @@
}
# Escape all HTML entities so that they are displayed correctly.
-sub filter {
- my ($self, $delta) = @_;
-
- $delta->{diff_old_lines} =
HTML::Entities::encode($delta->{diff_old_lines});
- $delta->{diff_new_lines} =
HTML::Entities::encode($delta->{diff_new_lines});
+sub _filter {
+ my ($self, $text) = @_;
+ return HTML::Entities::encode($text);
}
1;
Index: NonHighlightedLxrLineFilter.pm
===================================================================
RCS file:
/cvsroot/codestriker/codestriker/lib/Codestriker/Http/NonHighlightedLxrLineFilter.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- NonHighlightedLxrLineFilter.pm 19 Jun 2008 11:20:22 -0000 1.1
+++ NonHighlightedLxrLineFilter.pm 20 Jun 2008 02:34:00 -0000 1.2
@@ -18,64 +18,25 @@
# Parse the line and produce the appropriate hyperlinks to LXR.
# Currently, this is very Java/C/C++ centric, but it will do for now.
-sub filter {
+sub _filter {
my ($self, $text) = @_;
-
- # If the line is a comment, don't do any processing. Note this code
- # isn't bullet-proof, but its good enough most of the time.
- $_ = $text;
- return $text if (/^(\s| )*\/\// ||
- /^(\s| ){0,10}\*/ ||
- /^(\s| ){0,10}\/\*/ ||
- /^(\s| )*\*\/(\s| )*$/);
-
- # Handle package Java statements.
- if ($text =~ /^(package(\s| )+)([\w\.]+)(.*)$/) {
- return $1 . $self->lxr_ident($3) . $4;
- }
-
- # Handle Java import statements.
- if ($text =~ /^(import(\s| )+)([\w\.]+)\.(\w+)((\s| )*)(.*)$/)
{
- return $1 . $self->lxr_ident($3) . "." . $self->lxr_ident($4) .
"$5$7";
- }
-
- # Break the string into potential identifiers, and look them up to see
- # if they can be hyperlinked to an LXR lookup.
- my $idhash = $self->{idhash};
- my @data_tokens = split /([_A-Za-z][\w]+)/, $text;
- my $newdata = "";
- my $in_comment = 0;
- my $eol_comment = 0;
- for (my $i = 0; $i <= $#data_tokens; $i++) {
- my $token = $data_tokens[$i];
- if ($token =~ /^[_A-Za-z]/) {
- if ($eol_comment || $in_comment) {
- # Currently in a comment, don't LXRify.
- $newdata .= $token;
- } elsif ($token eq "nbsp" || $token eq "quot" || $token eq
"amp" ||
- $token eq "lt" || $token eq "gt") {
- # TODO: is this still needed?
- # HACK - ignore potential HTML entities. This
needs to be
- # done in a smarter fashion later.
- $newdata .= $token;
- } else {
- $newdata .= $self->lxr_ident($token);
- }
- } else {
- $newdata .= $token;
- $token =~ s/(\s| )//g;
-
- # Check if we are entering or exiting a comment.
- if ($token =~ /\/\//) {
- $eol_comment = 1;
- } elsif ($token =~ /\*+\//) {
- $in_comment = 0;
- } elsif ($token =~ /\/\*/) {
- $in_comment = 1;
- }
+
+ my $newdata = "";
+ my @lines = split /\n/, $text;
+ foreach my $line (@lines) {
+ if ($line =~ /^(package(\s| )+)([\w\.]+)(.*)$/) {
+ # Handle package Java statements.
+ $newdata .= $1 . $self->lxr_ident($3) . $4 . "\n";
+ }
+ elsif ($line =~
/^(import(\s| )+)([\w\.]+)\.(\w+)((\s| )*)(.*)$/) {
+ # Handle Java import statements.
+ $newdata .= $1 . $self->lxr_ident($3) . "." .
$self->lxr_ident($4) . "$5$7\n";
+ }
+ else {
+ $newdata .= $self->_handle_identifiers($line) . "\n";
}
}
-
+
return $newdata;
}
Index: HighlightedLxrLineFilter.pm
===================================================================
RCS file:
/cvsroot/codestriker/codestriker/lib/Codestriker/Http/HighlightedLxrLineFilter.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- HighlightedLxrLineFilter.pm 19 Jun 2008 11:20:22 -0000 1.1
+++ HighlightedLxrLineFilter.pm 20 Jun 2008 02:34:00 -0000 1.2
@@ -17,9 +17,11 @@
("Codestriker::Http::LxrLineFilter");
# Replace all variables with the appropriate link to LXR.
-sub filter {
+sub _filter {
my ($self, $text) = @_;
- $text =~ s#(<span class="kw[cd]">)(.*?)(</span>)#$1 .
$self->lxr_ident($2) . $3#geo;
+ $text =~ s#(<span class="hl kwd">)(.*?)(</span>)#$1 .
$self->lxr_ident($2) . $3#geo;
+ $text =~ s#(<span class="kwd">)(.*?)(</span>)#$1 . $self->lxr_ident($2)
. $3#geo;
+ $text =~ s#(>\s*)([^<]+?)<#$1 . $self->_handle_identifiers($2) .
'<'#gemo;
return $text;
}
Index: DeltaRenderer.pm
===================================================================
RCS file:
/cvsroot/codestriker/codestriker/lib/Codestriker/Http/DeltaRenderer.pm,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- DeltaRenderer.pm 19 Jun 2008 11:20:22 -0000 1.12
+++ DeltaRenderer.pm 20 Jun 2008 02:34:00 -0000 1.13
@@ -14,6 +14,7 @@
use Codestriker::Http::HtmlEntityLineFilter;
use Codestriker::Http::TabToNbspLineFilter;
use Codestriker::Http::LineBreakLineFilter;
+use Codestriker::Http::HighlightLineFilter;
use Codestriker::Http::HighlightedLxrLineFilter;
use Codestriker::Http::NonHighlightedLxrLineFilter;
@@ -62,14 +63,14 @@
push @{$self->{line_filters}},
Codestriker::Http::HighlightLineFilter->new($Codestriker::highlighter,
$tabwidth);
push @{$self->{line_filters}},
Codestriker::Http::LineBreakLineFilter->new();
if (defined $lxr_config) {
- push @{$self->{line_filters}},
Codestriker::Http::HighlighedLxrLineFilter->new($lxr_config);
+ push @{$self->{line_filters}},
Codestriker::Http::HighlightedLxrLineFilter->new($lxr_config);
}
} else {
push @{$self->{line_filters}},
Codestriker::Http::HtmlEntityLineFilter->new();
push @{$self->{line_filters}},
Codestriker::Http::TabToNbspLineFilter->new($tabwidth);
push @{$self->{line_filters}},
Codestriker::Http::LineBreakLineFilter->new();
if (defined $lxr_config) {
- push @{$self->{line_filters}},
Codestriker::Http::NonHighlighedLxrLineFilter->new($lxr_config);
+ push @{$self->{line_filters}},
Codestriker::Http::NonHighlightedLxrLineFilter->new($lxr_config);
}
}
@@ -143,6 +144,8 @@
# Split the delta into the left and right side so that text filtering
# can be applied.
my @diff_lines = split /\n/, $delta->{text};
+ $delta->{diff_old_lines} = "";
+ $delta->{diff_new_lines} = "";
for (my $i = 0; $i <= $#diff_lines; $i++) {
my $data = $diff_lines[$i];
Index: TabToNbspLineFilter.pm
===================================================================
RCS file:
/cvsroot/codestriker/codestriker/lib/Codestriker/Http/TabToNbspLineFilter.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TabToNbspLineFilter.pm 16 Jun 2008 11:32:05 -0000 1.2
+++ TabToNbspLineFilter.pm 20 Jun 2008 02:34:00 -0000 1.3
@@ -14,7 +14,7 @@
use Codestriker::Http::LineFilter;
[EMAIL PROTECTED]::Http::HtmlEntityLineFilter::ISA =
[EMAIL PROTECTED]::Http::TabToNbspLineFilter::ISA =
("Codestriker::Http::LineFilter");
# Take the desired tabwidth as a parameter.
@@ -38,12 +38,4 @@
return $text;
}
-# Convert tabs to the appropriate number of entities.
-sub filter {
- my ($self, $delta) = @_;
-
- $delta->{diff_old_lines} = $self->_filter($delta->{diff_old_lines});
- $delta->{diff_new_lines} = $self->_filter($delta->{diff_new_lines});
-}
-
1;
Index: LxrLineFilter.pm
===================================================================
RCS file:
/cvsroot/codestriker/codestriker/lib/Codestriker/Http/LxrLineFilter.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- LxrLineFilter.pm 19 Jun 2008 11:20:22 -0000 1.3
+++ LxrLineFilter.pm 20 Jun 2008 02:34:00 -0000 1.4
@@ -91,6 +91,34 @@
}
}
+# Break up the string into potential identifies, and see if lxr can process
+# them.
+sub _handle_identifiers {
+ my ($self, $text) = @_;
+
+ # Break the string into potential identifiers, and look them up to see
+ # if they can be hyperlinked to an LXR lookup.
+ my @data_tokens = split /([_A-z]\w+)/, $text;
+ my $newdata = "";
+ foreach my $token (@data_tokens) {
+ if ($token =~ /^[_A-z]/) {
+ if ($token eq "nbsp" || $token eq "quot" || $token eq "amp" ||
+ $token eq "lt" || $token eq "gt") {
+ # TODO: is this still needed?
+ # HACK - ignore potential HTML entities. This
needs to be
+ # done in a smarter fashion later.
+ $newdata .= $token;
+ } else {
+ $newdata .= $self->lxr_ident($token);
+ }
+ } else {
+ $newdata .= $token;
+ }
+ }
+
+ return $newdata;
+}
+
# Ensure the prepared statements and database connection to LXR is closed.
sub DESTROY {
my ($self) = @_;
Index: HighlightLineFilter.pm
===================================================================
RCS file:
/cvsroot/codestriker/codestriker/lib/Codestriker/Http/HighlightLineFilter.pm,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- HighlightLineFilter.pm 18 Jun 2008 06:44:34 -0000 1.4
+++ HighlightLineFilter.pm 20 Jun 2008 02:34:00 -0000 1.5
@@ -33,7 +33,7 @@
# Convert tabs to the appropriate number of entities.
sub _filter {
my ($self, $text, $extension) = @_;
-
+
# Create a temporary file which will contain the delta text to
highlight.
my ($input_text_fh, $input_filename) = tempfile(SUFFIX => $extension);
print $input_text_fh $text;
Index: LineBreakLineFilter.pm
===================================================================
RCS file:
/cvsroot/codestriker/codestriker/lib/Codestriker/Http/LineBreakLineFilter.pm,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- LineBreakLineFilter.pm 19 Jun 2008 03:33:50 -0000 1.4
+++ LineBreakLineFilter.pm 20 Jun 2008 02:34:00 -0000 1.5
@@ -36,12 +36,4 @@
return $text;
}
-# Convert the spaces appropriately for line-breaking.
-sub filter {
- my ($self, $delta) = @_;
-
- $delta->{diff_old_lines} = $self->_filter($delta->{diff_old_lines});
- $delta->{diff_new_lines} = $self->_filter($delta->{diff_new_lines});
-}
-
1;
Index: LineFilter.pm
===================================================================
RCS file:
/cvsroot/codestriker/codestriker/lib/Codestriker/Http/LineFilter.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- LineFilter.pm 16 Jun 2008 11:32:05 -0000 1.2
+++ LineFilter.pm 20 Jun 2008 02:34:00 -0000 1.3
@@ -21,7 +21,8 @@
sub filter {
my ($self, $delta) = @_;
- # Default is a no-op.
+ $delta->{diff_old_lines} = $self->_filter($delta->{diff_old_lines});
+ $delta->{diff_new_lines} = $self->_filter($delta->{diff_new_lines});
}
1;
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Codestriker-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/codestriker-commits