Text_Diff example


            return $prefix . $this->_deleted($orig) . $this->_added($final);
        }

        $text1 = implode("\n", $orig);
        $text2 = implode("\n", $final);

        /* Non-printing newline marker. */
        $nl = "\0";

        if ($this->_split_characters) {
            $diff = new Text_Diff('native',
                                  array(preg_split('//', $text1),
                                        preg_split('//', $text2)));
        } else {
            /* We want to split on word boundaries, but we need to preserve * whitespace as well. Therefore we split on words, but include * all blocks of whitespace in the wordlist. */
            $diff = new Text_Diff('native',
                                  array($this->_splitOnWords($text1$nl),
                                        $this->_splitOnWords($text2$nl)));
        }

        
$args     = wp_parse_args( $args$defaults );

        if ( ! class_exists( 'WP_Text_Diff_Renderer_Table', false ) ) {
            require ABSPATH . WPINC . '/wp-diff.php';
        }

        $left_string  = normalize_whitespace( $left_string );
        $right_string = normalize_whitespace( $right_string );

        $left_lines  = explode( "\n", $left_string );
        $right_lines = explode( "\n", $right_string );
        $text_diff   = new Text_Diff( $left_lines$right_lines );
        $renderer    = new WP_Text_Diff_Renderer_Table( $args );
        $diff        = $renderer->render( $text_diff );

        if ( ! $diff ) {
            return '';
        }

        $is_split_view       = ! empty( $args['show_split_view'] );
        $is_split_view_class = $is_split_view ? ' is-split-view' : '';

        $r = "<table class='diff$is_split_view_class'>\n";

        

        list($orig_matches$final_matches$orig_rows$final_rows) = $this->interleave_changed_lines( $orig$final );

        // These will hold the word changes as determined by an inline diff.         $orig_diffs  = array();
        $final_diffs = array();

        // Compute word diffs for each matched pair using the inline diff.         foreach ( $orig_matches as $o => $f ) {
            if ( is_numeric( $o ) && is_numeric( $f ) ) {
                $text_diff = new Text_Diff( 'auto', array( array( $orig[ $o ] ), array( $final[ $f ] ) ) );
                $renderer  = new $this->inline_diff_renderer();
                $diff      = $renderer->render( $text_diff );

                // If they're too different, don't include any <ins> or <del>'s.                 if ( preg_match_all( '!(<ins>.*?</ins>|<del>.*?</del>)!', $diff$diff_matches ) ) {
                    // Length of all text between <ins> or <del>.                     $stripped_matches = strlen( strip_tags( implode( ' ', $diff_matches[0] ) ) );
                    /* * Since we count length of text between <ins> or <del> (instead of picking just one), * we double the length of chars not in those tags. */
                    

    function __construct($from_lines$to_lines,
                             $mapped_from_lines$mapped_to_lines)
    {
        assert(count($from_lines) == count($mapped_from_lines));
        assert(count($to_lines) == count($mapped_to_lines));

        parent::Text_Diff($mapped_from_lines$mapped_to_lines);

        $xi = $yi = 0;
        for ($i = 0; $i < count($this->_edits)$i++) {
            $orig = &$this->_edits[$i]->orig;
            if (is_array($orig)) {
                $orig = array_slice($from_lines$xicount($orig));
                $xi += count($orig);
            }

            $final = &$this->_edits[$i]->final;
            if (is_array($final)) {
                
Home | Imprint | This part of the site doesn't use cookies.