r97807 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97806‎ | r97807 | r97808 >
Date:11:06, 22 September 2011
Author:reedy
Status:ok (Comments)
Tags:
Comment:
Fix mixed tabs and spaces from r97793

Couple of minor style tweaks also
Modified paths:
  • /trunk/phase3/languages/Language.php (modified) (history)

Diff [purge]

Index: trunk/phase3/languages/Language.php
@@ -2612,12 +2612,11 @@
26132613 */
26142614 function commafy( $_ ) {
26152615 $digitGroupingPattern = $this->digitGroupingPattern();
2616 -
 2616+
26172617 if ( !$digitGroupingPattern || $digitGroupingPattern === "###,###,###" ) {
26182618 //default grouping is at thousands, use the same for ###,###,### pattern too.
26192619 return strrev( (string)preg_replace( '/(\d{3})(?=\d)(?!\d*\.)/', '$1,', strrev( $_ ) ) );
2620 - }
2621 - else {
 2620+ } else {
26222621 // Ref: http://cldr.unicode.org/translation/number-patterns
26232622 $numberpart = array();
26242623 $decimalpart = array();
@@ -2625,28 +2624,27 @@
26262625 preg_match( "/\d+/", $_, $numberpart );
26272626 preg_match( "/\.\d*/", $_, $decimalpart );
26282627 $groupedNumber = ( count( $decimalpart ) > 0 ) ? $decimalpart[0]:"";
2629 - if ( $groupedNumber === $_){
2630 - //the string does not have any number part. Eg: .12345
2631 - return $groupedNumber;
 2628+ if ( $groupedNumber === $_ ){
 2629+ //the string does not have any number part. Eg: .12345
 2630+ return $groupedNumber;
26322631 }
26332632 $start = $end = strlen( $numberpart[0] );
2634 - while ( $start > 0 )
2635 - {
2636 - $match = $matches[0][$numMatches -1] ;
2637 - $matchLen = strlen( $match );
2638 - $start = $end - $matchLen;
2639 - if ( $start < 0 ) {
2640 - $start = 0;
2641 - }
2642 - $groupedNumber = substr( $_ , $start, $end -$start ) . $groupedNumber ;
2643 - $end = $start;
2644 - if ( $numMatches > 1 ) {
2645 - // use the last pattern for the rest of the number
2646 - $numMatches--;
2647 - }
2648 - if ( $start > 0 ) {
2649 - $groupedNumber = "," . $groupedNumber;
2650 - }
 2633+ while ( $start > 0 ) {
 2634+ $match = $matches[0][$numMatches -1] ;
 2635+ $matchLen = strlen( $match );
 2636+ $start = $end - $matchLen;
 2637+ if ( $start < 0 ) {
 2638+ $start = 0;
 2639+ }
 2640+ $groupedNumber = substr( $_ , $start, $end -$start ) . $groupedNumber ;
 2641+ $end = $start;
 2642+ if ( $numMatches > 1 ) {
 2643+ // use the last pattern for the rest of the number
 2644+ $numMatches--;
 2645+ }
 2646+ if ( $start > 0 ) {
 2647+ $groupedNumber = "," . $groupedNumber;
 2648+ }
26512649 }
26522650 return $groupedNumber;
26532651 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r97809stylize.php - minor whitespace fixes.santhosh11:52, 22 September 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r97793Add support for Number grouping(commafy) based on CLDR number grouping patter...santhosh05:01, 22 September 2011

Comments

#Comment by Nikerabbit (talk | contribs)   11:31, 22 September 2011

Thanks, I was going to do this too. One space could still be added between ){.

#Comment by Santhosh.thottingal (talk | contribs)   11:53, 22 September 2011

Whitespaces corrected in r97809

Status & tagging log