blob: c6971e69136d8e42ac7bf30cc274408b920c5df5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
//
// FileSizeFormatter.m
// Liaison
//
// Created by Brian Cully on Fri May 09 2003.
// Copyright (c) 2003 Brian Cully. All rights reserved.
//
#import "FileSizeFormatter.h"
@implementation FileSizeFormatter
- (NSString *)stringForObjectValue: (id)anObject
{
if ([anObject isKindOfClass: [NSNumber class]]) {
NSString *suffix;
int shownSize;
unsigned long size;
size = [anObject unsignedLongValue];
if (size > 1024 * 1024 * 1024) {
shownSize = size / 1024 / 1024 / 1024;
suffix = @" G";
} else if (size > 1024 * 1024) {
shownSize = size / 1024 / 1024;
suffix = @" M";
} else if (size > 1024) {
shownSize = size / 1024;
suffix = @" K";
} else {
shownSize = size;
suffix = @" B";
}
return [NSString stringWithFormat: @"%ld%@", shownSize, suffix];
}
return [super stringForObjectValue: anObject];
}
- (BOOL)getObjectValue: (id *)anObject
forString: (NSString *)string
errorDescription: (NSString **)error
{
*anObject = string;
return YES;
}
@end
|