]> git.saurik.com Git - cydia.git/blob - UICaboodle/UCString.h
Continuing the optimization work.
[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 (UICaboodle)
7 + (NSString *) stringWithDataSize:(double)size;
8 @end
9
10 @implementation NSString (UICaboodle)
11
12 + (NSString *) stringWithDataSize:(double)size {
13 unsigned power = 0;
14 while (size > 1024) {
15 size /= 1024;
16 ++power;
17 }
18
19 static const char *powers_[] = {"B", "KiB", "MiB", "GiB"};
20
21 return [NSString stringWithFormat:@"%.1f%s", size, powers_[power]];
22 }
23
24 @end
25
26 #endif/*UICABOODLE_UCSTRING_H*/