]> git.saurik.com Git - cydia.git/blob - UICaboodle/UCString.h
Added icon for Social section.
[cydia.git] / UICaboodle / UCString.h
1 #ifndef UICABOODLE_UCSTRING_H
2 #define UICABOODLE_UCSTRING_H
3
4 #import <Foundation/NSString.h>
5
6 @interface NSString (UIKit)
7 - (NSString *) stringByAddingPercentEscapes;
8 - (NSString *) stringByReplacingCharacter:(unsigned short)arg0 withCharacter:(unsigned short)arg1;
9 @end
10
11 @interface NSString (UICaboodle)
12 + (NSString *) stringWithDataSize:(double)size;
13 - (NSString *) stringByAddingPercentEscapesIncludingReserved;
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
30 - (NSString *) stringByAddingPercentEscapesIncludingReserved {
31 return [(id)CFURLCreateStringByAddingPercentEscapes(
32 kCFAllocatorDefault,
33 (CFStringRef) self,
34 NULL,
35 CFSTR(";/?:@&=+$,"),
36 kCFStringEncodingUTF8
37 ) autorelease];
38 }
39
40 @end
41
42 #endif/*UICABOODLE_UCSTRING_H*/