Make WordPress Core

Ticket #28724: miqro-28724.2.patch

File miqro-28724.2.patch, 4.6 KB (added by miqrogroove, 12 years ago)

Style tweak.

  • src/wp-includes/formatting.php

     
    9696                $static_characters = array_merge( array( '...', '``', '\'\'', ' (tm)' ), $cockney );
    9797                $static_replacements = array_merge( array( '…', $opening_quote, $closing_quote, ' ™' ), $cockneyreplace );
    9898
    99                 $spaces = wp_spaces_regexp();
    10099
    101 
    102100                // Pattern-based replacements of characters.
     101                // Sort the remaining patterns into several arrays for performance tuning.
     102                $dynamic_characters = array( 'apos' => array(), 'quote' => array(), 'dash' => array() );
     103                $dynamic_replacements = array( 'apos' => array(), 'quote' => array(), 'dash' => array() );
    103104                $dynamic = array();
     105                $spaces = wp_spaces_regexp();
    104106
    105107                // '99' and '99" are ambiguous among other patterns; assume it's an abbreviated year at the end of a quotation.
    106108                if ( "'" !== $apos || "'" !== $closing_single_quote ) {
     
    115117                        $dynamic[ '/\'(?=\d\d(?:\Z|(?![%\d]|[.,]\d)))/' ] = $apos;
    116118                }
    117119
    118                 // Quoted Numbers like "42" or '42.00'
    119                 if ( '"' !== $opening_quote && '"' !== $closing_quote ) {
    120                         $dynamic[ '/(?<=\A|' . $spaces . ')"(\d[.,\d]*)"/' ] = $opening_quote . '$1' . $closing_quote;
    121                 }
     120                // Quoted Numbers like '0.42'
    122121                if ( "'" !== $opening_single_quote && "'" !== $closing_single_quote ) {
    123122                        $dynamic[ '/(?<=\A|' . $spaces . ')\'(\d[.,\d]*)\'/' ] = $opening_single_quote . '$1' . $closing_single_quote;
    124123                }
     
    133132                        $dynamic[ '/(?<!' . $spaces . ')\'(?!\Z|[.,:;"\'(){}[\]\-]|&[lg]t;|' . $spaces . ')/' ] = $apos;
    134133                }
    135134
     135                // 9' (prime)
     136                if ( "'" !== $prime ) {
     137                        $dynamic[ '/(?<=\d)\'/' ] = $prime;
     138                }
     139
     140                // Single quotes followed by spaces or ending punctuation.
     141                if ( "'" !== $closing_single_quote ) {
     142                        $dynamic[ '/\'(?=\Z|[.,)}\-\]]|&gt;|' . $spaces . ')/' ] = $closing_single_quote;
     143                }
     144
     145                $dynamic_characters['apos'] = array_keys( $dynamic );
     146                $dynamic_replacements['apos'] = array_values( $dynamic );
     147                $dynamic = array();
     148               
     149                // Quoted Numbers like "42"
     150                if ( '"' !== $opening_quote && '"' !== $closing_quote ) {
     151                        $dynamic[ '/(?<=\A|' . $spaces . ')"(\d[.,\d]*)"/' ] = $opening_quote . '$1' . $closing_quote;
     152                }
     153
    136154                // 9" (double prime)
    137155                if ( '"' !== $double_prime ) {
    138156                        $dynamic[ '/(?<=\d)"/' ] = $double_prime;
    139157                }
    140158
    141                 // 9' (prime)
    142                 if ( "'" !== $prime ) {
    143                         $dynamic[ '/(?<=\d)\'/' ] = $prime;
    144                 }
    145 
    146159                // Double quote at start, or preceded by (, {, <, [, -, or spaces, and not followed by spaces.
    147160                if ( '"' !== $opening_quote ) {
    148161                        $dynamic[ '/(?<=\A|[([{\-]|&lt;|' . $spaces . ')"(?!' . $spaces . ')/' ] = $opening_quote;
     
    152165                if ( '"' !== $closing_quote ) {
    153166                        $dynamic[ '/"/' ] = $closing_quote;
    154167                }
    155 
    156                 // Single quotes followed by spaces or ending punctuation.
    157                 if ( "'" !== $closing_single_quote ) {
    158                         $dynamic[ '/\'(?=\Z|[.,)}\-\]]|&gt;|' . $spaces . ')/' ] = $closing_single_quote;
    159                 }
    160 
     168               
     169                $dynamic_characters['quote'] = array_keys( $dynamic );
     170                $dynamic_replacements['quote'] = array_values( $dynamic );
     171                $dynamic = array();
     172               
    161173                // Dashes and spaces
    162174                $dynamic[ '/---/' ] = $em_dash;
    163175                $dynamic[ '/(?<=' . $spaces . ')--(?=' . $spaces . ')/' ] = $em_dash;
     
    164176                $dynamic[ '/(?<!xn)--/' ] = $en_dash;
    165177                $dynamic[ '/(?<=' . $spaces . ')-(?=' . $spaces . ')/' ] = $en_dash;
    166178
    167                 $dynamic_characters = array_keys( $dynamic );
    168                 $dynamic_replacements = array_values( $dynamic );
     179                $dynamic_characters['dash'] = array_keys( $dynamic );
     180                $dynamic_replacements['dash'] = array_values( $dynamic );
    169181        }
    170182
    171183        // Must do this every time in case plugins use these filters in a context sensitive manner
     
    237249                        // This is neither a delimeter, nor is this content inside of no_texturize pairs.  Do texturize.
    238250
    239251                        $curl = str_replace( $static_characters, $static_replacements, $curl );
    240                         $curl = preg_replace( $dynamic_characters, $dynamic_replacements, $curl );
    241252
     253                        if ( false !== strpos( $curl, "'" ) ) {
     254                                $curl = preg_replace( $dynamic_characters['apos'], $dynamic_replacements['apos'], $curl );
     255                        }
     256                        if ( false !== strpos( $curl, '"' ) ) {
     257                                $curl = preg_replace( $dynamic_characters['quote'], $dynamic_replacements['quote'], $curl );
     258                        }
     259                        if ( false !== strpos( $curl, '-' ) ) {
     260                                $curl = preg_replace( $dynamic_characters['dash'], $dynamic_replacements['dash'], $curl );
     261                        }
     262
    242263                        // 9x9 (times), but never 0x9999
    243264                        if ( 1 === preg_match( '/(?<=\d)x-?\d/', $curl ) ) {
    244265                                // Searching for a digit is 10 times more expensive than for the x, so we avoid doing this one!