blob: d776728adab9477b16769cd999bb4b0a93f4691a (
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
|
#ifndef UICABOODLE_UCSTRING_H
#define UICABOODLE_UCSTRING_H
#import <Foundation/NSString.h>
@interface NSString (UIKit)
- (NSString *) stringByAddingPercentEscapes;
- (NSString *) stringByReplacingCharacter:(unsigned short)arg0 withCharacter:(unsigned short)arg1;
@end
@interface NSString (UICaboodle)
+ (NSString *) stringWithDataSize:(double)size;
- (NSString *) stringByAddingPercentEscapesIncludingReserved;
@end
@implementation NSString (UICaboodle)
+ (NSString *) stringWithDataSize:(double)size {
unsigned power = 0;
while (size > 1024) {
size /= 1024;
++power;
}
static const char *powers_[] = {"B", "KiB", "MiB", "GiB"};
return [NSString stringWithFormat:@"%.1f%s", size, powers_[power]];
}
- (NSString *) stringByAddingPercentEscapesIncludingReserved {
return [(id)CFURLCreateStringByAddingPercentEscapes(
kCFAllocatorDefault,
(CFStringRef) self,
NULL,
CFSTR(";/?:@&=+$,"),
kCFStringEncodingUTF8
) autorelease];
}
@end
#endif/*UICABOODLE_UCSTRING_H*/
|