Changeset 3886 for trunk/macosx/NSStringAdditions.m
- Timestamp:
- Nov 19, 2007, 6:13:41 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/macosx/NSStringAdditions.m
r3358 r3886 40 40 + (NSString *) stringForFileSize: (uint64_t) size 41 41 { 42 if (size < 1024)43 return [NSString stringWithFormat: NSLocalizedString(@"%lld bytes", "File size"), size]; 42 [self stringForLargeFileSizeGigs: size / 1073741824 bytes: size % 1073741824]; 43 } 44 44 45 + (NSString *) stringForLargeFileSizeGigs: (uint64_t) gigs bytes: (uint64_t) bytes 46 { 45 47 float convertedSize; 46 48 NSString * unit; 47 if ( size < 1048576)49 if (gigs == 0) 48 50 { 49 convertedSize = size / 1024.0;50 unit = NSLocalizedString(@"KB", "File size");51 }52 else if (size < 1073741824)53 {54 convertedSize = size / 1048576.0;55 unit = NSLocalizedString(@"MB", "File size");56 }57 else if (size < 1099511627776.0)58 {59 convertedSize = size / 1073741824.0;60 unit = NSLocalizedString(@"GB", "File size");51 if (bytes < 1024) 52 return [NSString stringWithFormat: NSLocalizedString(@"%lld bytes", "File size"), bytes]; 53 else if (bytes < 1048576) 54 { 55 convertedSize = bytes / 1024.0; 56 unit = NSLocalizedString(@"KB", "File size"); 57 } 58 else 59 { 60 convertedSize = bytes / 1048576.0; 61 unit = NSLocalizedString(@"MB", "File size"); 62 } 61 63 } 62 64 else 63 65 { 64 convertedSize = size / 1099511627776.0; 65 unit = NSLocalizedString(@"TB", "File size"); 66 if (gigs < 1024) 67 { 68 convertedSize = (float)gigs + bytes / 1073741824.0; 69 unit = NSLocalizedString(@"GB", "File size"); 70 } 71 else 72 { 73 convertedSize = gigs / 1024.0; 74 unit = NSLocalizedString(@"TB", "File size"); 75 } 66 76 } 67 77
Note: See TracChangeset
for help on using the changeset viewer.