summaryrefslogtreecommitdiffstats
path: root/Plugins/BuiltInFunctions/FileSizeFormatter.m
diff options
context:
space:
mode:
Diffstat (limited to 'Plugins/BuiltInFunctions/FileSizeFormatter.m')
-rw-r--r--Plugins/BuiltInFunctions/FileSizeFormatter.m47
1 files changed, 47 insertions, 0 deletions
diff --git a/Plugins/BuiltInFunctions/FileSizeFormatter.m b/Plugins/BuiltInFunctions/FileSizeFormatter.m
new file mode 100644
index 0000000..c6971e6
--- /dev/null
+++ b/Plugins/BuiltInFunctions/FileSizeFormatter.m
@@ -0,0 +1,47 @@
+//
+// FileSizeFormatter.m
+// Liaison
+//
+// Created by Brian Cully on Fri May 09 2003.
+// Copyright (c) 2003 Brian Cully. All rights reserved.
+//
+
+#import "FileSizeFormatter.h"
+
+@implementation FileSizeFormatter
+- (NSString *)stringForObjectValue: (id)anObject
+{
+ if ([anObject isKindOfClass: [NSNumber class]]) {
+ NSString *suffix;
+ int shownSize;
+ unsigned long size;
+
+ size = [anObject unsignedLongValue];
+ if (size > 1024 * 1024 * 1024) {
+ shownSize = size / 1024 / 1024 / 1024;
+ suffix = @" G";
+ } else if (size > 1024 * 1024) {
+ shownSize = size / 1024 / 1024;
+ suffix = @" M";
+ } else if (size > 1024) {
+ shownSize = size / 1024;
+ suffix = @" K";
+ } else {
+ shownSize = size;
+ suffix = @" B";
+ }
+
+ return [NSString stringWithFormat: @"%ld%@", shownSize, suffix];
+ }
+
+ return [super stringForObjectValue: anObject];
+}
+
+- (BOOL)getObjectValue: (id *)anObject
+ forString: (NSString *)string
+ errorDescription: (NSString **)error
+{
+ *anObject = string;
+ return YES;
+}
+@end