wp/wp-includes/Text/Diff.php
changeset 18 be944660c56a
parent 7 cf61fcea0001
child 19 3d72ae0968f4
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
    73     /**
    73     /**
    74      * returns the number of new (added) lines in a given diff.
    74      * returns the number of new (added) lines in a given diff.
    75      *
    75      *
    76      * @since Text_Diff 1.1.0
    76      * @since Text_Diff 1.1.0
    77      *
    77      *
    78      * @return integer The number of new lines
    78      * @return int The number of new lines
    79      */
    79      */
    80     function countAddedLines()
    80     function countAddedLines()
    81     {
    81     {
    82         $count = 0;
    82         $count = 0;
    83         foreach ($this->_edits as $edit) {
    83         foreach ($this->_edits as $edit) {
    92     /**
    92     /**
    93      * Returns the number of deleted (removed) lines in a given diff.
    93      * Returns the number of deleted (removed) lines in a given diff.
    94      *
    94      *
    95      * @since Text_Diff 1.1.0
    95      * @since Text_Diff 1.1.0
    96      *
    96      *
    97      * @return integer The number of deleted lines
    97      * @return int The number of deleted lines
    98      */
    98      */
    99     function countDeletedLines()
    99     function countDeletedLines()
   100     {
   100     {
   101         $count = 0;
   101         $count = 0;
   102         foreach ($this->_edits as $edit) {
   102         foreach ($this->_edits as $edit) {
   137     }
   137     }
   138 
   138 
   139     /**
   139     /**
   140      * Checks for an empty diff.
   140      * Checks for an empty diff.
   141      *
   141      *
   142      * @return boolean  True if two sequences were identical.
   142      * @return bool True if two sequences were identical.
   143      */
   143      */
   144     function isEmpty()
   144     function isEmpty()
   145     {
   145     {
   146         foreach ($this->_edits as $edit) {
   146         foreach ($this->_edits as $edit) {
   147             if (!is_a($edit, 'Text_Diff_Op_copy')) {
   147             if (!is_a($edit, 'Text_Diff_Op_copy')) {
   154     /**
   154     /**
   155      * Computes the length of the Longest Common Subsequence (LCS).
   155      * Computes the length of the Longest Common Subsequence (LCS).
   156      *
   156      *
   157      * This is mostly for diagnostic purposes.
   157      * This is mostly for diagnostic purposes.
   158      *
   158      *
   159      * @return integer  The length of the LCS.
   159      * @return int The length of the LCS.
   160      */
   160      */
   161     function lcs()
   161     function lcs()
   162     {
   162     {
   163         $lcs = 0;
   163         $lcs = 0;
   164         foreach ($this->_edits as $edit) {
   164         foreach ($this->_edits as $edit) {
   208     /**
   208     /**
   209      * Removes trailing newlines from a line of text. This is meant to be used
   209      * Removes trailing newlines from a line of text. This is meant to be used
   210      * with array_walk().
   210      * with array_walk().
   211      *
   211      *
   212      * @param string $line  The line to trim.
   212      * @param string $line  The line to trim.
   213      * @param integer $key  The index of the line in the array. Not used.
   213      * @param int    $key   The index of the line in the array. Not used.
   214      */
   214      */
   215     static function trimNewlines(&$line, $key)
   215     static function trimNewlines(&$line, $key)
   216     {
   216     {
   217         $line = str_replace(array("\n", "\r"), '', $line);
   217         $line = str_replace(array("\n", "\r"), '', $line);
   218     }
   218     }
   219 
   219 
   220     /**
   220     /**
   221      * Determines the location of the system temporary directory.
   221      * Determines the location of the system temporary directory.
   222      *
       
   223      * @static
       
   224      *
   222      *
   225      * @access protected
   223      * @access protected
   226      *
   224      *
   227      * @return string  A directory name which can be used for temp files.
   225      * @return string  A directory name which can be used for temp files.
   228      *                 Returns false if one could not be found.
   226      *                 Returns false if one could not be found.
   229      */
   227      */
   230     function _getTempDir()
   228     static function _getTempDir()
   231     {
   229     {
   232         $tmp_locations = array('/tmp', '/var/tmp', 'c:\WUTemp', 'c:\temp',
   230         $tmp_locations = array('/tmp', '/var/tmp', 'c:\WUTemp', 'c:\temp',
   233                                'c:\windows\temp', 'c:\winnt\temp');
   231                                'c:\windows\temp', 'c:\winnt\temp');
   234 
   232 
   235         /* Try PHP's upload_tmp_dir directive. */
   233         /* Try PHP's upload_tmp_dir directive. */
   276             trigger_error("Reversed final doesn't match", E_USER_ERROR);
   274             trigger_error("Reversed final doesn't match", E_USER_ERROR);
   277         }
   275         }
   278 
   276 
   279         $prevtype = null;
   277         $prevtype = null;
   280         foreach ($this->_edits as $edit) {
   278         foreach ($this->_edits as $edit) {
   281             if ($prevtype == get_class($edit)) {
   279             if ($edit instanceof $prevtype) {
   282                 trigger_error("Edit sequence is non-optimal", E_USER_ERROR);
   280                 trigger_error("Edit sequence is non-optimal", E_USER_ERROR);
   283             }
   281             }
   284             $prevtype = get_class($edit);
   282             $prevtype = get_class($edit);
   285         }
   283         }
   286 
   284