]>
Commit | Line | Data |
---|---|---|
7fb3cc0f JF |
1 | #ifndef UICABOODLE_UCSTRING_H |
2 | #define UICABOODLE_UCSTRING_H | |
3 | ||
4 | #import <Foundation/NSString.h> | |
5 | ||
62fc7146 JF |
6 | @interface NSString (UIKit) |
7 | - (NSString *) stringByAddingPercentEscapes; | |
8 | - (NSString *) stringByReplacingCharacter:(unsigned short)arg0 withCharacter:(unsigned short)arg1; | |
9 | @end | |
10 | ||
7fb3cc0f JF |
11 | @interface NSString (UICaboodle) |
12 | + (NSString *) stringWithDataSize:(double)size; | |
62fc7146 | 13 | - (NSString *) stringByAddingPercentEscapesIncludingReserved; |
7fb3cc0f JF |
14 | @end |
15 | ||
16 | @implementation NSString (UICaboodle) | |
17 | ||
18 | + (NSString *) stringWithDataSize:(double)size { | |
19 | unsigned power = 0; | |
20 | while (size > 1024) { | |
21 | size /= 1024; | |
22 | ++power; | |
23 | } | |
24 | ||
25 | static const char *powers_[] = {"B", "KiB", "MiB", "GiB"}; | |
26 | ||
27 | return [NSString stringWithFormat:@"%.1f%s", size, powers_[power]]; | |
28 | } | |
29 | ||
62fc7146 JF |
30 | - (NSString *) stringByAddingPercentEscapesIncludingReserved { |
31 | return [(id)CFURLCreateStringByAddingPercentEscapes( | |
f99f86e2 | 32 | kCFAllocatorDefault, |
62fc7146 JF |
33 | (CFStringRef) self, |
34 | NULL, | |
35 | CFSTR(";/?:@&=+$,"), | |
36 | kCFStringEncodingUTF8 | |
37 | ) autorelease]; | |
38 | } | |
39 | ||
7fb3cc0f JF |
40 | @end |
41 | ||
42 | #endif/*UICABOODLE_UCSTRING_H*/ |