//
//  OADecimalNumberExpressionFormatter.m
//  drachma
//
//  Created by Niko Matsakis on 11/25/06.
//  Copyright 2006 __MyCompanyName__. All rights reserved.
//

#import "OADecimalNumberExpressionFormatter.h"
#import "OAExpressionEvaluator.h"

@implementation OADecimalNumberExpressionFormatter

- (BOOL)getObjectValue:(id *)anObject forString:(NSString *)string errorDescription:(NSString **)error;
{
    // First evaluate the expression:
    @try {
        NSAssert2([[string class] isSubclassOfClass:[NSString class]], 
                  @"So-called string %@ is in fact a %@", string, [string class]);
        *anObject = evaluateExpressionUsingNSDecimalNumber(string);
        return YES;
    } @catch (NSException *exc) {
        if (error) 
            *error = [exc reason];
        return NO;
    }
    
    *error = @"Weird Exception Thrown...?";
    return NO;
}

- (NSString *)stringForObjectValue:(id)anObject
{
    // XXX
    return [anObject description];
}

- (NSString *)editingStringForObjectValue:(id)anObject
{
    return [anObject description];
}

//- (NSAttributedString *)attributedStringForObjectValue:(id)anObject withDefaultAttributes:(NSDictionary *)attributes
//{
//  TODO
//}

//- (BOOL)isPartialStringValid:(NSString *)partialString 
//            newEditingString:(NSString **)newString 
//            errorDescription:(NSString **)error
//{
//    BOOL result = YES;
//    @try {
//        evaluateExpressionUsingNSDecimalNumber(partialString);
//    } @catch (NSException *exc) {
//        result = NO;
//        *newString = @"22";
//    }
//    return result;
//}

//- (BOOL)isPartialStringValid:(NSString **)partialStringPtr 
//       proposedSelectedRange:(NSRangePointer)proposedSelRangePtr 
//              originalString:(NSString *)origString 
//       originalSelectedRange:(NSRange)origSelRange 
//            errorDescription:(NSString **)error
//{
//    BOOL result = YES;
//    @try {
//        evaluateExpressionUsingNSDecimalNumber(*partialStringPtr);
//    } @catch (NSException *exc) {
//        result = NO;
//    }
//    return result;
//}

@end
