Changeset 10988 for trunk/macosx/NSStringAdditions.m
- Timestamp:
- Jul 10, 2010, 2:31:05 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/macosx/NSStringAdditions.m
r10832 r10988 29 29 #import "utils.h" 30 30 31 @interface NSString (Private) 32 33 + (NSString *) stringForSpeed: (CGFloat) speed kb: (NSString *) kb mb: (NSString *) mb gb: (NSString *) gb; 34 35 @end 36 31 37 @implementation NSString (NSStringAdditions) 32 38 … … 81 87 + (NSString *) stringForSpeed: (CGFloat) speed 82 88 { 83 return [[self stringForSpeedAbbrev: speed] stringByAppendingString: NSLocalizedString(@"B/s", "Transfer speed (Bytes per second)")]; 89 return [self stringForSpeed: speed 90 kb: NSLocalizedString(@"KB/s", "Transfer speed (kilobytes per second)") 91 mb: NSLocalizedString(@"MB/s", "Transfer speed (megabytes per second)") 92 gb: NSLocalizedString(@"GB/s", "Transfer speed (gigabytes per second)")]; 84 93 } 85 94 86 95 + (NSString *) stringForSpeedAbbrev: (CGFloat) speed 87 96 { 88 if (speed <= 999.95) //0.0 K to 999.9 K 89 return [NSString localizedStringWithFormat: @"%.1f K", speed]; 90 91 speed /= 1024.0; 92 93 if (speed <= 99.995) //0.98 M to 99.99 M 94 return [NSString localizedStringWithFormat: @"%.2f M", speed]; 95 else if (speed <= 999.95) //100.0 M to 999.9 M 96 return [NSString localizedStringWithFormat: @"%.1f M", speed]; 97 else //insane speeds 98 return [NSString localizedStringWithFormat: @"%.2f G", (speed / 1024.0)]; 97 return [self stringForSpeed: speed kb: @"K" mb: @"M" gb: @"G"]; 99 98 } 100 99 … … 187 186 188 187 @end 188 189 @implementation NSString (Private) 190 191 + (NSString *) stringForSpeed: (CGFloat) speed kb: (NSString *) kb mb: (NSString *) mb gb: (NSString *) gb 192 { 193 if (speed <= 999.95) //0.0 KB/s to 999.9 KB/s 194 return [NSString localizedStringWithFormat: @"%.1f %@", speed, kb]; 195 196 speed /= 1024.0; 197 198 if (speed <= 99.995) //0.98 MB/s to 99.99 MB/s 199 return [NSString localizedStringWithFormat: @"%.2f %@", speed, mb]; 200 else if (speed <= 999.95) //100.0 MB/s to 999.9 MB/s 201 return [NSString localizedStringWithFormat: @"%.1f %@", speed, mb]; 202 else //insane speeds 203 return [NSString localizedStringWithFormat: @"%.2f %@", (speed / 1024.0), gb]; 204 } 205 206 @end
Note: See TracChangeset
for help on using the changeset viewer.