2008-03-04 00:43:47 +00:00
|
|
|
//
|
|
|
|
// BlankZeroFormatter.m
|
|
|
|
// Cog
|
|
|
|
//
|
|
|
|
// Created by Vincent Spader on 3/3/08.
|
|
|
|
// Copyright 2008 __MyCompanyName__. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "BlankZeroFormatter.h"
|
|
|
|
|
|
|
|
@implementation BlankZeroFormatter
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (NSString *)stringForObjectValue:(id)object {
|
|
|
|
NSString *result = nil;
|
2008-03-04 00:43:47 +00:00
|
|
|
int value;
|
|
|
|
|
|
|
|
if(nil == object || NO == [object isKindOfClass:[NSNumber class]]) {
|
2013-09-30 01:58:24 +00:00
|
|
|
return [NSString string];
|
2008-03-04 00:43:47 +00:00
|
|
|
}
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2008-03-04 00:43:47 +00:00
|
|
|
value = [object intValue];
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
if(value)
|
2008-03-04 00:43:47 +00:00
|
|
|
result = [NSString stringWithFormat:@"%i", value];
|
2022-02-07 05:49:27 +00:00
|
|
|
else
|
|
|
|
result = [NSString string];
|
|
|
|
|
2008-03-04 00:43:47 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (BOOL)getObjectValue:(id *)object forString:(NSString *)string errorDescription:(NSString **)error {
|
2008-03-04 00:43:47 +00:00
|
|
|
if(NULL != object) {
|
|
|
|
*object = [NSNumber numberWithInt:[string intValue]];
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2008-03-04 00:43:47 +00:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (NSAttributedString *)attributedStringForObjectValue:(id)object withDefaultAttributes:(NSDictionary *)attributes {
|
|
|
|
NSAttributedString *result = nil;
|
|
|
|
|
2008-03-04 00:43:47 +00:00
|
|
|
result = [[NSAttributedString alloc] initWithString:[self stringForObjectValue:object] attributes:attributes];
|
2016-05-05 20:05:39 +00:00
|
|
|
return result;
|
2008-03-04 00:43:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|