Changeset 11417


Ignore:
Timestamp:
Nov 14, 2010, 8:26:58 PM (11 years ago)
Author:
livings124
Message:

add a string function to format an NSUInteger as a formatted string

Location:
trunk/macosx
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.m

    r11416 r11417  
    17861786- (void) setBottomCountText: (BOOL) filtering
    17871787{
    1788     NSNumberFormatter * numberFormatter = [[[NSNumberFormatter alloc] init] autorelease];
    1789     [numberFormatter setNumberStyle: NSNumberFormatterDecimalStyle];
    1790     [numberFormatter setMaximumFractionDigits: 0];
    1791    
    17921788    NSString * totalTorrentsString;
    17931789    NSUInteger totalCount = [fTorrents count];
    17941790    if (totalCount != 1)
    17951791        totalTorrentsString = [NSString stringWithFormat: NSLocalizedString(@"%@ transfers", "Status bar transfer count"),
    1796                                 [numberFormatter stringFromNumber: [NSNumber numberWithUnsignedInteger: totalCount]]];
     1792                                [NSString formattedUInteger: totalCount]];
    17971793    else
    17981794        totalTorrentsString = NSLocalizedString(@"1 transfer", "Status bar transfer count");
     
    18051801       
    18061802        totalTorrentsString = [NSString stringWithFormat: NSLocalizedString(@"%@ of %@", "Status bar transfer count"),
    1807                                 [numberFormatter stringFromNumber: [NSNumber numberWithUnsignedInteger: count]],
    1808                                 totalTorrentsString];
     1803                                [NSString formattedUInteger: count], totalTorrentsString];
    18091804    }
    18101805   
  • trunk/macosx/FilterButton.m

    r11416 r11417  
    2424
    2525#import "FilterButton.h"
     26#import "NSStringAdditions.h"
    2627
    2728@implementation FilterButton
     
    4344    fCount = count;
    4445   
    45     NSNumberFormatter * numberFormatter = [[[NSNumberFormatter alloc] init] autorelease];
    46     [numberFormatter setNumberStyle: NSNumberFormatterDecimalStyle];
    47     [numberFormatter setMaximumFractionDigits: 0];
    48    
    4946    [self setToolTip: fCount == 1 ? NSLocalizedString(@"1 transfer", "Filter Button -> tool tip")
    5047        : [NSString stringWithFormat: NSLocalizedString(@"%@ transfers", "Filter Bar Button -> tool tip"),
    51             [numberFormatter stringFromNumber: [NSNumber numberWithUnsignedInteger: fCount]]]];
     48            [NSString formattedUInteger: fCount]]];
    5249}
    5350
  • trunk/macosx/NSStringAdditions.h

    r11284 r11417  
    3030- (NSString *) stringByAppendingEllipsis;
    3131
     32+ (NSString *) formattedUInteger: (NSUInteger) value;
     33
    3234+ (NSString *) stringForFileSize: (uint64_t) size;
    3335
  • trunk/macosx/NSStringAdditions.m

    r11351 r11417  
    4747}
    4848
     49+ (NSString *) formattedUInteger: (NSUInteger) value
     50{
     51    NSNumberFormatter * numberFormatter = [[[NSNumberFormatter alloc] init] autorelease];
     52    [numberFormatter setNumberStyle: NSNumberFormatterDecimalStyle];
     53    [numberFormatter setMaximumFractionDigits: 0];
     54   
     55    return [numberFormatter stringFromNumber: [NSNumber numberWithUnsignedInteger: value]];
     56}
     57
    4958+ (NSString *) stringForFileSize: (uint64_t) size
    5059{
  • trunk/macosx/PrefsController.m

    r11416 r11417  
    504504    if (exists)
    505505    {
    506         NSNumberFormatter * numberFormatter = [[[NSNumberFormatter alloc] init] autorelease];
    507         [numberFormatter setNumberStyle: NSNumberFormatterDecimalStyle];
    508         [numberFormatter setMaximumFractionDigits: 0];
    509         NSString * countString = [numberFormatter stringFromNumber: [NSNumber numberWithInt: tr_blocklistGetRuleCount(fHandle)]];
    510        
     506        NSString * countString = [NSString formattedUInteger: tr_blocklistGetRuleCount(fHandle)];
    511507        [fBlocklistMessageField setStringValue: [NSString stringWithFormat: NSLocalizedString(@"%@ IP address rules in list",
    512508            "Prefs -> blocklist -> message"), countString]];
Note: See TracChangeset for help on using the changeset viewer.