App-Guiio

 view release on metacpan or  search on metacpan

lib/App/Guiio/Undo.pm  view on Meta::CPAN


my @diff_lines = get_diff_lines(\@seq1, \@seq2) ;

for my $diff_line (@diff_lines)
	{
	print DumpTree $diff_line ;
	
	my (
		$number_of_errors
		, $number_of_match
		, $synchronized_a
		, $synchronized_b
		, $error_string
		) = CompareStrings($diff_line->{REFERENCE}, $diff_line->{NEW}) ;
		
	my $undefined_line = '' ;
	
	$undefined_line = '** reference line did not exist! **' unless defined $diff_line->{REFERENCE} ;
	$undefined_line = '** new line did not exist! **' unless defined $diff_line->{NEW} ;

	print <<ERRORS ;
line = $diff_line->{LINE}
number_of_match  = $number_of_match
number_of_errors = $number_of_errors
$undefined_line
$synchronized_a
$synchronized_b
$error_string

ERRORS
	}
}

sub get_diff_lines
{
my ($seq1, $seq2) = @_ ;

lib/App/Guiio/Undo.pm  view on Meta::CPAN

=head2 CompareStrings

Returns the following list:

=over 2

=item 1	number_of_errors

=item 2 number_of_match

=item 3	synchronized_a

=item 4	synchronized_b

=item 5	error_string

=back

=cut


my ($a_string, $b_string) = @_ ;
my ($a, $b) ;

lib/App/Guiio/Undo.pm  view on Meta::CPAN

		if(defined $match_indexes[$_])
			{
			if($match_indexes[$_] == $previous + 1)
				{
				# match
				$b .= $b[$match_indexes[$_]] ;
				$last_match_in_B = $match_indexes[$_] ;
				}
			else
				{
				# match but extra letters in B, synchronize A
				$a .= ' ' x ($match_indexes[$_] - ($previous + 1)) ;
				$b .= join '', @b[$previous + 1 .. $match_indexes[$_]] ;
				
				$last_match_in_B = $match_indexes[$_] ;
				}
			}
		#else
			# letter in A doesn't match in B
		}
	else
		{
		if(defined $match_indexes[$_])
			{
			# match
			# synchronize B
			my $number_of_skipped_characters_in_B = ($match_indexes[$_] - 1) - ($last_match_in_B) ;
			$b .= ' ' x (length($a) - (length($b) + $number_of_skipped_characters_in_B)) ;
			
			$b .= join '', @b[$last_match_in_B + 1 .. $match_indexes[$_]] ;
			$last_match_in_B = $match_indexes[$_] ;
			
			# synchronize A if needed
			$a .= ' ' x (length($b) - (length($a) + 1)) ; # +1 as current character will be appended to $a
			}
		#else
			# letter in A doesn't match in B
		}
		
	$a .= $a[$_] ;
	$previous = $match_indexes[$_] ;
	}



( run in 0.557 second using v1.01-cache-2.11-cpan-05444aca049 )