mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Add Bizcard result parser to zxing widget.
git-svn-id: https://zxing.googlecode.com/svn/trunk@1861 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
fdb0c30497
commit
13fcdc4ffa
|
@ -0,0 +1,30 @@
|
||||||
|
//
|
||||||
|
// BizcardResultParser.h
|
||||||
|
// ZXing
|
||||||
|
//
|
||||||
|
// Created by George Nachman on 7/15/2011.
|
||||||
|
/*
|
||||||
|
* Copyright 2011 ZXing authors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#import "ResultParser.h"
|
||||||
|
|
||||||
|
@interface BizcardResultParser : ResultParser {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
102
iphone/ZXingWidget/Classes/resultParsers/BizcardResultParser.m
Normal file
102
iphone/ZXingWidget/Classes/resultParsers/BizcardResultParser.m
Normal file
|
@ -0,0 +1,102 @@
|
||||||
|
//
|
||||||
|
// BizcardResultParser.m
|
||||||
|
// ZXing
|
||||||
|
//
|
||||||
|
// Ported to Objective-C by George Nachman on 7/14/2011.
|
||||||
|
/*
|
||||||
|
* Copyright 2011 ZXing authors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#import "BizcardResultParser.h"
|
||||||
|
#import "BusinessCardParsedResult.h"
|
||||||
|
#import "CBarcodeFormat.h"
|
||||||
|
#import "DoCoMoResultParser.h"
|
||||||
|
|
||||||
|
@implementation BizcardResultParser
|
||||||
|
|
||||||
|
+ (void)load {
|
||||||
|
[ResultParser registerResultParserClass:self];
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (NSArray*)arrayWithFirstName:(NSString*)firstName
|
||||||
|
lastName:(NSString*)lastName {
|
||||||
|
if (firstName && !lastName) {
|
||||||
|
return [NSArray arrayWithObject:firstName];
|
||||||
|
} else if (!firstName && lastName) {
|
||||||
|
return [NSArray arrayWithObject:lastName];
|
||||||
|
} else if (lastName && firstName) {
|
||||||
|
return [NSArray arrayWithObject:[NSString stringWithFormat:@"%@ %@",
|
||||||
|
firstName, lastName, nil]];
|
||||||
|
} else {
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Implements the "BIZCARD" address book entry format, though this has been
|
||||||
|
// largely reverse-engineered from examples observed in the wild -- still
|
||||||
|
// looking for a definitive reference.
|
||||||
|
//
|
||||||
|
// @author Sean Owen
|
||||||
|
//
|
||||||
|
+ (ParsedResult *)parsedResultForString:(NSString *)rawText
|
||||||
|
format:(BarcodeFormat)format {
|
||||||
|
if (rawText == nil || ![rawText hasPrefix:@"BIZCARD:"]) {
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
NSString *firstName =
|
||||||
|
[[rawText fieldWithPrefix:@"N:"] stringWithTrimmedWhitespace];
|
||||||
|
NSString *lastName =
|
||||||
|
[[rawText fieldWithPrefix:@"X:"] stringWithTrimmedWhitespace];
|
||||||
|
NSString *title =
|
||||||
|
[[rawText fieldWithPrefix:@"T:"] stringWithTrimmedWhitespace];
|
||||||
|
NSString *org =
|
||||||
|
[[rawText fieldWithPrefix:@"C:"] stringWithTrimmedWhitespace];
|
||||||
|
NSArray *addresses =
|
||||||
|
[[rawText fieldsWithPrefix:@"A:"] stringArrayWithTrimmedWhitespace];
|
||||||
|
NSString *phoneNumber1 =
|
||||||
|
[[rawText fieldWithPrefix:@"B:"] stringWithTrimmedWhitespace];
|
||||||
|
NSString *phoneNumber2 =
|
||||||
|
[[rawText fieldWithPrefix:@"M:"] stringWithTrimmedWhitespace];
|
||||||
|
NSString *phoneNumber3 =
|
||||||
|
[[rawText fieldWithPrefix:@"F:"] stringWithTrimmedWhitespace];
|
||||||
|
NSString *email =
|
||||||
|
[[rawText fieldWithPrefix:@"E:"] stringWithTrimmedWhitespace];
|
||||||
|
|
||||||
|
BusinessCardParsedResult *result = [[BusinessCardParsedResult alloc] init];
|
||||||
|
|
||||||
|
result.names = [BizcardResultParser arrayWithFirstName:firstName lastName:lastName];
|
||||||
|
NSMutableArray *phoneNumbers = [NSMutableArray arrayWithCapacity:3];
|
||||||
|
if (phoneNumber1) {
|
||||||
|
[phoneNumbers addObject:phoneNumber1];
|
||||||
|
}
|
||||||
|
if (phoneNumber1) {
|
||||||
|
[phoneNumbers addObject:phoneNumber2];
|
||||||
|
}
|
||||||
|
if (phoneNumber1) {
|
||||||
|
[phoneNumbers addObject:phoneNumber3];
|
||||||
|
}
|
||||||
|
if ([phoneNumbers count]) {
|
||||||
|
result.phoneNumbers = phoneNumbers;
|
||||||
|
}
|
||||||
|
result.emails = email ? [NSArray arrayWithObject:email] : nil;
|
||||||
|
result.addresses = addresses;
|
||||||
|
result.organization = org;
|
||||||
|
result.jobTitle = title;
|
||||||
|
|
||||||
|
return [result autorelease];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
|
@ -20,7 +20,7 @@
|
||||||
#import "TextResultParser.h"
|
#import "TextResultParser.h"
|
||||||
#import "CBarcodeFormat.h"
|
#import "CBarcodeFormat.h"
|
||||||
#import "ProductResultParser.h"
|
#import "ProductResultParser.h"
|
||||||
#import "AddressBookAUResultParser.h"
|
#import "BizcardResultParser.h"
|
||||||
|
|
||||||
@implementation UniversalResultParser
|
@implementation UniversalResultParser
|
||||||
static NSMutableArray *sTheResultParsers = nil;
|
static NSMutableArray *sTheResultParsers = nil;
|
||||||
|
@ -45,7 +45,7 @@ static NSMutableArray *sTheResultParsers = nil;
|
||||||
[self addParserClass:[BookmarkDoCoMoResultParser class]];
|
[self addParserClass:[BookmarkDoCoMoResultParser class]];
|
||||||
[self addParserClass:[MeCardParser class]];
|
[self addParserClass:[MeCardParser class]];
|
||||||
[self addParserClass:[EmailDoCoMoResultParser class]];
|
[self addParserClass:[EmailDoCoMoResultParser class]];
|
||||||
[self addParserClass:[AddressBookAUResultParser class]];
|
[self addParserClass:[BizcardResultParser class]];
|
||||||
[self addParserClass:[PlainEmailResultParser class]];
|
[self addParserClass:[PlainEmailResultParser class]];
|
||||||
[self addParserClass:[TelResultParser class]];
|
[self addParserClass:[TelResultParser class]];
|
||||||
[self addParserClass:[SMSResultParser class]];
|
[self addParserClass:[SMSResultParser class]];
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
objects = {
|
objects = {
|
||||||
|
|
||||||
/* Begin PBXBuildFile section */
|
/* Begin PBXBuildFile section */
|
||||||
|
1D0CBDF913D0DD5D003D0F8D /* BizcardResultParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D0CBDF713D0DD5D003D0F8D /* BizcardResultParser.h */; };
|
||||||
|
1D0CBDFA13D0DD5D003D0F8D /* BizcardResultParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D0CBDF813D0DD5D003D0F8D /* BizcardResultParser.m */; };
|
||||||
1DFA090C13CE1A3900599044 /* CBarcodeFormat.h in Headers */ = {isa = PBXBuildFile; fileRef = 1DFA090A13CE1A3900599044 /* CBarcodeFormat.h */; };
|
1DFA090C13CE1A3900599044 /* CBarcodeFormat.h in Headers */ = {isa = PBXBuildFile; fileRef = 1DFA090A13CE1A3900599044 /* CBarcodeFormat.h */; };
|
||||||
1DFA090D13CE1A3900599044 /* CBarcodeFormat.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1DFA090B13CE1A3900599044 /* CBarcodeFormat.mm */; };
|
1DFA090D13CE1A3900599044 /* CBarcodeFormat.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1DFA090B13CE1A3900599044 /* CBarcodeFormat.mm */; };
|
||||||
1DFA092413CE251600599044 /* ProductParsedResult.h in Headers */ = {isa = PBXBuildFile; fileRef = 1DFA092213CE251600599044 /* ProductParsedResult.h */; };
|
1DFA092413CE251600599044 /* ProductParsedResult.h in Headers */ = {isa = PBXBuildFile; fileRef = 1DFA092213CE251600599044 /* ProductParsedResult.h */; };
|
||||||
|
@ -244,6 +246,8 @@
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
|
1D0CBDF713D0DD5D003D0F8D /* BizcardResultParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BizcardResultParser.h; path = Classes/resultParsers/BizcardResultParser.h; sourceTree = "<group>"; };
|
||||||
|
1D0CBDF813D0DD5D003D0F8D /* BizcardResultParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = BizcardResultParser.m; path = Classes/resultParsers/BizcardResultParser.m; sourceTree = "<group>"; };
|
||||||
1DFA090A13CE1A3900599044 /* CBarcodeFormat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CBarcodeFormat.h; path = Classes/CBarcodeFormat.h; sourceTree = "<group>"; };
|
1DFA090A13CE1A3900599044 /* CBarcodeFormat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CBarcodeFormat.h; path = Classes/CBarcodeFormat.h; sourceTree = "<group>"; };
|
||||||
1DFA090B13CE1A3900599044 /* CBarcodeFormat.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = CBarcodeFormat.mm; path = Classes/CBarcodeFormat.mm; sourceTree = "<group>"; };
|
1DFA090B13CE1A3900599044 /* CBarcodeFormat.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = CBarcodeFormat.mm; path = Classes/CBarcodeFormat.mm; sourceTree = "<group>"; };
|
||||||
1DFA092213CE251600599044 /* ProductParsedResult.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ProductParsedResult.h; path = Classes/parsedResults/ProductParsedResult.h; sourceTree = "<group>"; };
|
1DFA092213CE251600599044 /* ProductParsedResult.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ProductParsedResult.h; path = Classes/parsedResults/ProductParsedResult.h; sourceTree = "<group>"; };
|
||||||
|
@ -806,6 +810,8 @@
|
||||||
1FB4319E12901C76002D63E8 /* UniversalResultParser.m */,
|
1FB4319E12901C76002D63E8 /* UniversalResultParser.m */,
|
||||||
1DFA099E13CE5C0300599044 /* AddressBookAUResultParser.h */,
|
1DFA099E13CE5C0300599044 /* AddressBookAUResultParser.h */,
|
||||||
1DFA099F13CE5C0300599044 /* AddressBookAUResultParser.m */,
|
1DFA099F13CE5C0300599044 /* AddressBookAUResultParser.m */,
|
||||||
|
1D0CBDF713D0DD5D003D0F8D /* BizcardResultParser.h */,
|
||||||
|
1D0CBDF813D0DD5D003D0F8D /* BizcardResultParser.m */,
|
||||||
1F027FFB11A7BF06006B06DE /* BookmarkDoCoMoResultParser.h */,
|
1F027FFB11A7BF06006B06DE /* BookmarkDoCoMoResultParser.h */,
|
||||||
1F027FFC11A7BF06006B06DE /* BookmarkDoCoMoResultParser.m */,
|
1F027FFC11A7BF06006B06DE /* BookmarkDoCoMoResultParser.m */,
|
||||||
1F027FFD11A7BF06006B06DE /* DoCoMoResultParser.h */,
|
1F027FFD11A7BF06006B06DE /* DoCoMoResultParser.h */,
|
||||||
|
@ -1014,6 +1020,7 @@
|
||||||
1DFA092413CE251600599044 /* ProductParsedResult.h in Headers */,
|
1DFA092413CE251600599044 /* ProductParsedResult.h in Headers */,
|
||||||
1DFA092A13CE252300599044 /* ProductResultParser.h in Headers */,
|
1DFA092A13CE252300599044 /* ProductResultParser.h in Headers */,
|
||||||
1DFA09A013CE5C0300599044 /* AddressBookAUResultParser.h in Headers */,
|
1DFA09A013CE5C0300599044 /* AddressBookAUResultParser.h in Headers */,
|
||||||
|
1D0CBDF913D0DD5D003D0F8D /* BizcardResultParser.h in Headers */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
|
@ -1181,6 +1188,7 @@
|
||||||
1DFA092513CE251600599044 /* ProductParsedResult.m in Sources */,
|
1DFA092513CE251600599044 /* ProductParsedResult.m in Sources */,
|
||||||
1DFA092B13CE252300599044 /* ProductResultParser.mm in Sources */,
|
1DFA092B13CE252300599044 /* ProductResultParser.mm in Sources */,
|
||||||
1DFA09A113CE5C0300599044 /* AddressBookAUResultParser.m in Sources */,
|
1DFA09A113CE5C0300599044 /* AddressBookAUResultParser.m in Sources */,
|
||||||
|
1D0CBDFA13D0DD5D003D0F8D /* BizcardResultParser.m in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue