summaryrefslogtreecommitdiff
path: root/UICaboodle/UCString.h
diff options
context:
space:
mode:
Diffstat (limited to 'UICaboodle/UCString.h')
-rw-r--r--UICaboodle/UCString.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/UICaboodle/UCString.h b/UICaboodle/UCString.h
new file mode 100644
index 0000000..77ee6a1
--- /dev/null
+++ b/UICaboodle/UCString.h
@@ -0,0 +1,26 @@
+#ifndef UICABOODLE_UCSTRING_H
+#define UICABOODLE_UCSTRING_H
+
+#import <Foundation/NSString.h>
+
+@interface NSString (UICaboodle)
++ (NSString *) stringWithDataSize:(double)size;
+@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]];
+}
+
+@end
+
+#endif/*UICABOODLE_UCSTRING_H*/