summaryrefslogtreecommitdiffstats
path: root/Plugins/BuiltInFunctions/FileSizeFormatter.m
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2008-04-14 21:45:08 -0400
committerBrian Cully <github.20.shmit@spamgourmet.com>2008-04-14 21:45:08 -0400
commit17349a5e426dc7acf1216a3767a22f69974cbca0 (patch)
tree20029d02f07ab6257cccec36d34fb312f796e1d1 /Plugins/BuiltInFunctions/FileSizeFormatter.m
downloadliaison-17349a5e426dc7acf1216a3767a22f69974cbca0.tar.gz
liaison-17349a5e426dc7acf1216a3767a22f69974cbca0.zip
Initial commit.
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