diff --git a/iphone/ZXingWidget/Classes/parsedResults/ProductParsedResult.h b/iphone/ZXingWidget/Classes/parsedResults/ProductParsedResult.h new file mode 100644 index 000000000..6b0a77cff --- /dev/null +++ b/iphone/ZXingWidget/Classes/parsedResults/ProductParsedResult.h @@ -0,0 +1,36 @@ +// +// ProductParsedResult.h +// ZXing +// +// Created by George Nachman on 7/8/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 +#import "ParsedResult.h" + +@interface ProductParsedResult : ParsedResult { + NSString *productID; + NSString *normalizedProductID; +} + +@property (nonatomic, copy) NSString *productID; +@property (nonatomic, copy) NSString *normalizedProductID; + +- (id)initWithProductID:(NSString*)newProductID + normalizedProductID:(NSString*)newNormalizedProductID; + +@end diff --git a/iphone/ZXingWidget/Classes/parsedResults/ProductParsedResult.m b/iphone/ZXingWidget/Classes/parsedResults/ProductParsedResult.m new file mode 100644 index 000000000..477706d26 --- /dev/null +++ b/iphone/ZXingWidget/Classes/parsedResults/ProductParsedResult.m @@ -0,0 +1,43 @@ +// +// ProductParsedResult.4 +// ZXing +// +// Created by George Nachman on 7/8/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 +#import "ProductParsedResult.h" + +@implementation ProductParsedResult + +@synthesize productID; +@synthesize normalizedProductID; + +- (id)initWithProductID:(NSString*)newProductID + normalizedProductID:(NSString*)newNormalizedProductID { + if ((self = [super init]) != nil) { + self.productID = newProductID; + self.normalizedProductID = newNormalizedProductID; + } + return self; +} + +- (NSString *)stringForDisplay { + return self.productID; +} + +@end diff --git a/iphone/ZXingWidget/Classes/resultParsers/ProductResultParser.h b/iphone/ZXingWidget/Classes/resultParsers/ProductResultParser.h new file mode 100644 index 000000000..b8d67cd8d --- /dev/null +++ b/iphone/ZXingWidget/Classes/resultParsers/ProductResultParser.h @@ -0,0 +1,30 @@ +// +// ProductResultParser.h +// ZXing +// +// Created by George Nachman on 7/7/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 +#import "ResultParser.h" + +@interface ProductResultParser : ResultParser { + +} + +@end + diff --git a/iphone/ZXingWidget/Classes/resultParsers/ProductResultParser.mm b/iphone/ZXingWidget/Classes/resultParsers/ProductResultParser.mm new file mode 100644 index 000000000..f24d9d36b --- /dev/null +++ b/iphone/ZXingWidget/Classes/resultParsers/ProductResultParser.mm @@ -0,0 +1,65 @@ +// +// ProductResultParser.m +// ZXing +// +// Ported to Objective-C by George Nachman on 7/7/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 "ProductResultParser.h" +#import "ProductParsedResult.h" +#import "CBarcodeFormat.h" +#include "../../../../cpp/core/src/zxing/oned/UPCEReader.h" + +@implementation ProductResultParser + ++ (void)load { + [ResultParser registerResultParserClass:self]; +} + ++ (ParsedResult *)parsedResultForString:(NSString *)s format:(BarcodeFormat)format { + // Treat all UPC and EAN variants as UPCs, in the sense that they are all + // product barcodes. + if (format != BarcodeFormat_UPC_E && + format != BarcodeFormat_UPC_A && + format != BarcodeFormat_EAN_8 && + format != BarcodeFormat_EAN_13) { + return nil; + } + + // Barcode must be all digits. + for (unsigned int i = 0; i < [s length]; i++) { + unichar c = [s characterAtIndex:i]; + if (c < '0' || c > '9') { + return nil; + } + } + + NSString *normalizedProductID; + // Expand UPC-E for purposes of searching + if (format == BarcodeFormat_UPC_E) { + std::string textStr = std::string([s UTF8String]); + std::string normal = zxing::oned::UPCEReader::convertUPCEtoUPCA(textStr); + normalizedProductID = [NSString stringWithUTF8String:normal.c_str()]; + } else { + normalizedProductID = s; + } + + return [[ProductParsedResult alloc] initWithProductID:s + normalizedProductID:normalizedProductID]; +} + +@end diff --git a/iphone/ZXingWidget/Classes/resultParsers/UniversalResultParser.m b/iphone/ZXingWidget/Classes/resultParsers/UniversalResultParser.m index 3a6f2512f..31cddaa26 100644 --- a/iphone/ZXingWidget/Classes/resultParsers/UniversalResultParser.m +++ b/iphone/ZXingWidget/Classes/resultParsers/UniversalResultParser.m @@ -19,6 +19,7 @@ #import "GeoResultParser.h" #import "TextResultParser.h" #import "CBarcodeFormat.h" +#import "ProductResultParser.h" @implementation UniversalResultParser static NSMutableArray *sTheResultParsers = nil; @@ -50,6 +51,7 @@ static NSMutableArray *sTheResultParsers = nil; [self addParserClass:[EmailDoCoMoResultParser class]]; [self addParserClass:[BookmarkDoCoMoResultParser class]]; [self addParserClass:[GeoResultParser class]]; + [self addParserClass:[ProductResultParser class]]; [self addParserClass:[TextResultParser class]]; } diff --git a/iphone/ZXingWidget/ZXingWidget.xcodeproj/project.pbxproj b/iphone/ZXingWidget/ZXingWidget.xcodeproj/project.pbxproj index a7502b912..3ed555097 100644 --- a/iphone/ZXingWidget/ZXingWidget.xcodeproj/project.pbxproj +++ b/iphone/ZXingWidget/ZXingWidget.xcodeproj/project.pbxproj @@ -9,6 +9,10 @@ /* Begin PBXBuildFile section */ 1DFA090C13CE1A3900599044 /* CBarcodeFormat.h in Headers */ = {isa = PBXBuildFile; fileRef = 1DFA090A13CE1A3900599044 /* CBarcodeFormat.h */; }; 1DFA090D13CE1A3900599044 /* CBarcodeFormat.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1DFA090B13CE1A3900599044 /* CBarcodeFormat.mm */; }; + 1DFA092413CE251600599044 /* ProductParsedResult.h in Headers */ = {isa = PBXBuildFile; fileRef = 1DFA092213CE251600599044 /* ProductParsedResult.h */; }; + 1DFA092513CE251600599044 /* ProductParsedResult.m in Sources */ = {isa = PBXBuildFile; fileRef = 1DFA092313CE251600599044 /* ProductParsedResult.m */; }; + 1DFA092A13CE252300599044 /* ProductResultParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 1DFA092813CE252300599044 /* ProductResultParser.h */; }; + 1DFA092B13CE252300599044 /* ProductResultParser.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1DFA092913CE252300599044 /* ProductResultParser.mm */; }; 1F027FAB11A7BEAF006B06DE /* Decoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F027F9F11A7BEAF006B06DE /* Decoder.h */; }; 1F027FAC11A7BEAF006B06DE /* Decoder.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1F027FA011A7BEAF006B06DE /* Decoder.mm */; }; 1F027FAD11A7BEAF006B06DE /* DecoderDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F027FA111A7BEAF006B06DE /* DecoderDelegate.h */; }; @@ -240,6 +244,10 @@ /* Begin PBXFileReference section */ 1DFA090A13CE1A3900599044 /* CBarcodeFormat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CBarcodeFormat.h; path = Classes/CBarcodeFormat.h; sourceTree = ""; }; 1DFA090B13CE1A3900599044 /* CBarcodeFormat.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = CBarcodeFormat.mm; path = Classes/CBarcodeFormat.mm; sourceTree = ""; }; + 1DFA092213CE251600599044 /* ProductParsedResult.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ProductParsedResult.h; path = Classes/parsedResults/ProductParsedResult.h; sourceTree = ""; }; + 1DFA092313CE251600599044 /* ProductParsedResult.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ProductParsedResult.m; path = Classes/parsedResults/ProductParsedResult.m; sourceTree = ""; }; + 1DFA092813CE252300599044 /* ProductResultParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ProductResultParser.h; path = Classes/resultParsers/ProductResultParser.h; sourceTree = ""; }; + 1DFA092913CE252300599044 /* ProductResultParser.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = ProductResultParser.mm; path = Classes/resultParsers/ProductResultParser.mm; sourceTree = ""; }; 1F027F9F11A7BEAF006B06DE /* Decoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Decoder.h; path = Classes/Decoder.h; sourceTree = ""; }; 1F027FA011A7BEAF006B06DE /* Decoder.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = Decoder.mm; path = Classes/Decoder.mm; sourceTree = ""; }; 1F027FA111A7BEAF006B06DE /* DecoderDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DecoderDelegate.h; path = Classes/DecoderDelegate.h; sourceTree = ""; }; @@ -804,6 +812,8 @@ 1F02800411A7BF06006B06DE /* MeCardParser.m */, 1F02800511A7BF06006B06DE /* PlainEmailResultParser.h */, 1F02800611A7BF06006B06DE /* PlainEmailResultParser.m */, + 1DFA092813CE252300599044 /* ProductResultParser.h */, + 1DFA092913CE252300599044 /* ProductResultParser.mm */, 1F02800711A7BF06006B06DE /* ResultParser.h */, 1F02800811A7BF06006B06DE /* ResultParser.m */, 1F02800911A7BF06006B06DE /* SMSResultParser.h */, @@ -833,6 +843,8 @@ 1F027FE011A7BEEB006B06DE /* GeoParsedResult.m */, 1F027FE111A7BEEB006B06DE /* ParsedResult.h */, 1F027FE211A7BEEB006B06DE /* ParsedResult.m */, + 1DFA092213CE251600599044 /* ProductParsedResult.h */, + 1DFA092313CE251600599044 /* ProductParsedResult.m */, 1F027FE311A7BEEB006B06DE /* SMSParsedResult.h */, 1F027FE411A7BEEB006B06DE /* SMSParsedResult.m */, 1F027FE511A7BEEB006B06DE /* TelParsedResult.h */, @@ -993,6 +1005,8 @@ 3B72D97012130EF6007CEF32 /* ResultPointCallback.h in Headers */, 1FB4319F12901C76002D63E8 /* UniversalResultParser.h in Headers */, 1DFA090C13CE1A3900599044 /* CBarcodeFormat.h in Headers */, + 1DFA092413CE251600599044 /* ProductParsedResult.h in Headers */, + 1DFA092A13CE252300599044 /* ProductResultParser.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1157,6 +1171,8 @@ 3B72D96F12130EF6007CEF32 /* ResultPointCallback.cpp in Sources */, 1FB431A012901C76002D63E8 /* UniversalResultParser.m in Sources */, 1DFA090D13CE1A3900599044 /* CBarcodeFormat.mm in Sources */, + 1DFA092513CE251600599044 /* ProductParsedResult.m in Sources */, + 1DFA092B13CE252300599044 /* ProductResultParser.mm in Sources */, ); runOnlyForDeploymentPostprocessing = 0; };