2010-11-14 07:56:00 -08:00
|
|
|
//
|
|
|
|
// UniversalResultParser.m
|
|
|
|
// ZXingWidget
|
|
|
|
//
|
|
|
|
// Created by Romain Pechayre on 11/14/10.
|
|
|
|
// Copyright 2010 __MyCompanyName__. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "UniversalResultParser.h"
|
|
|
|
#import "SMSTOResultParser.h"
|
|
|
|
#import "URLResultParser.h"
|
|
|
|
#import "TelResultParser.h"
|
|
|
|
#import "URLTOResultParser.h"
|
|
|
|
#import "SMSResultParser.h"
|
|
|
|
#import "PlainEmailResultParser.h"
|
|
|
|
#import "MeCardParser.h"
|
|
|
|
#import "EmailDoCoMoResultParser.h"
|
|
|
|
#import "BookmarkDoCoMoResultParser.h"
|
|
|
|
#import "GeoResultParser.h"
|
|
|
|
#import "TextResultParser.h"
|
2011-07-13 11:10:33 -07:00
|
|
|
#import "CBarcodeFormat.h"
|
2011-07-14 14:59:34 -07:00
|
|
|
#import "ProductResultParser.h"
|
2011-07-19 15:54:19 -07:00
|
|
|
#import "BizcardResultParser.h"
|
2011-07-29 15:24:06 -07:00
|
|
|
#import "AddressBookAUResultParser.h"
|
|
|
|
#import "VCardResultParser.h"
|
2011-08-01 14:30:04 -07:00
|
|
|
#import "SMTPResultParser.h"
|
|
|
|
#import "ISBNResultParser.h"
|
|
|
|
#import "EmailAddressResultParser.h"
|
2010-11-14 07:56:00 -08:00
|
|
|
|
|
|
|
@implementation UniversalResultParser
|
2010-11-20 10:16:53 -08:00
|
|
|
static NSMutableArray *sTheResultParsers = nil;
|
|
|
|
//@synthesize parsers;
|
2010-11-14 07:56:00 -08:00
|
|
|
|
2010-11-20 10:16:53 -08:00
|
|
|
+(void) load {
|
|
|
|
[self initWithDefaultParsers];
|
2010-11-14 07:56:00 -08:00
|
|
|
}
|
|
|
|
|
2010-11-20 10:16:53 -08:00
|
|
|
+ (void)addParserClass:(Class)klass {
|
2011-07-19 15:54:19 -07:00
|
|
|
[sTheResultParsers addObject:klass];
|
2010-11-20 10:16:53 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (void) initWithDefaultParsers {
|
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
@synchronized(self) {
|
|
|
|
if (!sTheResultParsers) {
|
|
|
|
sTheResultParsers = [[NSMutableArray alloc] init];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
[pool release];
|
2011-07-15 13:32:27 -07:00
|
|
|
[self addParserClass:[BookmarkDoCoMoResultParser class]];
|
2010-11-14 07:56:00 -08:00
|
|
|
[self addParserClass:[MeCardParser class]];
|
|
|
|
[self addParserClass:[EmailDoCoMoResultParser class]];
|
2011-07-29 15:24:06 -07:00
|
|
|
[self addParserClass:[AddressBookAUResultParser class]];
|
|
|
|
[self addParserClass:[VCardResultParser class]];
|
2011-07-19 15:54:19 -07:00
|
|
|
[self addParserClass:[BizcardResultParser class]];
|
2011-08-01 14:30:04 -07:00
|
|
|
[self addParserClass:[EmailAddressResultParser class]];
|
2011-07-15 13:32:27 -07:00
|
|
|
[self addParserClass:[PlainEmailResultParser class]];
|
2011-08-01 14:30:04 -07:00
|
|
|
[self addParserClass:[SMTPResultParser class]];
|
2011-07-15 13:32:27 -07:00
|
|
|
[self addParserClass:[TelResultParser class]];
|
|
|
|
[self addParserClass:[SMSResultParser class]];
|
|
|
|
[self addParserClass:[SMSTOResultParser class]];
|
2010-11-14 07:56:00 -08:00
|
|
|
[self addParserClass:[GeoResultParser class]];
|
2011-07-15 13:32:27 -07:00
|
|
|
[self addParserClass:[URLTOResultParser class]];
|
|
|
|
[self addParserClass:[URLResultParser class]];
|
2011-08-01 14:30:04 -07:00
|
|
|
[self addParserClass:[ISBNResultParser class]];
|
2011-07-14 14:59:34 -07:00
|
|
|
[self addParserClass:[ProductResultParser class]];
|
2010-11-14 07:56:00 -08:00
|
|
|
[self addParserClass:[TextResultParser class]];
|
|
|
|
}
|
|
|
|
|
2011-07-13 11:10:33 -07:00
|
|
|
+ (ParsedResult *)parsedResultForString:(NSString *)s
|
|
|
|
format:(BarcodeFormat)format {
|
2010-11-14 07:56:00 -08:00
|
|
|
#ifdef DEBUG
|
|
|
|
NSLog(@"parsing result:\n<<<\n%@\n>>>\n", s);
|
|
|
|
#endif
|
2010-11-20 10:16:53 -08:00
|
|
|
for (Class c in sTheResultParsers) {
|
2010-11-14 07:56:00 -08:00
|
|
|
#ifdef DEBUG
|
|
|
|
NSLog(@"trying %@", NSStringFromClass(c));
|
|
|
|
#endif
|
2011-07-13 11:10:33 -07:00
|
|
|
ParsedResult *result = [c parsedResultForString:s format:format];
|
2010-11-14 07:56:00 -08:00
|
|
|
if (result != nil) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
NSLog(@"parsed as %@ %@", NSStringFromClass([result class]), result);
|
|
|
|
#endif
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2011-07-13 11:10:33 -07:00
|
|
|
+ (ParsedResult *)parsedResultForString:(NSString *)theString {
|
|
|
|
return [self parsedResultForString:theString format:BarcodeFormat_None];
|
|
|
|
}
|
2010-11-14 07:56:00 -08:00
|
|
|
|
|
|
|
@end
|