You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ZXAbstractExpandedDecoder.m 3.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright 2012 ZXing authors
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import "ZXAbstractExpandedDecoder.h"
  17. #import "ZXAI013103decoder.h"
  18. #import "ZXAI01320xDecoder.h"
  19. #import "ZXAI01392xDecoder.h"
  20. #import "ZXAI01393xDecoder.h"
  21. #import "ZXAI013x0x1xDecoder.h"
  22. #import "ZXAI01AndOtherAIs.h"
  23. #import "ZXAnyAIDecoder.h"
  24. #import "ZXBitArray.h"
  25. #import "ZXRSSExpandedGeneralAppIdDecoder.h"
  26. @implementation ZXAbstractExpandedDecoder
  27. - (id)initWithInformation:(ZXBitArray *)information {
  28. if (self = [super init]) {
  29. _information = information;
  30. _generalDecoder = [[ZXRSSExpandedGeneralAppIdDecoder alloc] initWithInformation:information];
  31. }
  32. return self;
  33. }
  34. - (NSString *)parseInformationWithError:(NSError **)error {
  35. @throw [NSException exceptionWithName:NSInternalInconsistencyException
  36. reason:[NSString stringWithFormat:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]
  37. userInfo:nil];
  38. }
  39. + (ZXAbstractExpandedDecoder *)createDecoder:(ZXBitArray *)information {
  40. if ([information get:1]) {
  41. return [[ZXAI01AndOtherAIs alloc] initWithInformation:information];
  42. }
  43. if (![information get:2]) {
  44. return [[ZXAnyAIDecoder alloc] initWithInformation:information];
  45. }
  46. int fourBitEncodationMethod = [ZXRSSExpandedGeneralAppIdDecoder extractNumericValueFromBitArray:information pos:1 bits:4];
  47. switch (fourBitEncodationMethod) {
  48. case 4:
  49. return [[ZXAI013103decoder alloc] initWithInformation:information];
  50. case 5:
  51. return [[ZXAI01320xDecoder alloc] initWithInformation:information];
  52. }
  53. int fiveBitEncodationMethod = [ZXRSSExpandedGeneralAppIdDecoder extractNumericValueFromBitArray:information pos:1 bits:5];
  54. switch (fiveBitEncodationMethod) {
  55. case 12:
  56. return [[ZXAI01392xDecoder alloc] initWithInformation:information];
  57. case 13:
  58. return [[ZXAI01393xDecoder alloc] initWithInformation:information];
  59. }
  60. int sevenBitEncodationMethod = [ZXRSSExpandedGeneralAppIdDecoder extractNumericValueFromBitArray:information pos:1 bits:7];
  61. switch (sevenBitEncodationMethod) {
  62. case 56:
  63. return [[ZXAI013x0x1xDecoder alloc] initWithInformation:information firstAIdigits:@"310" dateCode:@"11"];
  64. case 57:
  65. return [[ZXAI013x0x1xDecoder alloc] initWithInformation:information firstAIdigits:@"320" dateCode:@"11"];
  66. case 58:
  67. return [[ZXAI013x0x1xDecoder alloc] initWithInformation:information firstAIdigits:@"310" dateCode:@"13"];
  68. case 59:
  69. return [[ZXAI013x0x1xDecoder alloc] initWithInformation:information firstAIdigits:@"320" dateCode:@"13"];
  70. case 60:
  71. return [[ZXAI013x0x1xDecoder alloc] initWithInformation:information firstAIdigits:@"310" dateCode:@"15"];
  72. case 61:
  73. return [[ZXAI013x0x1xDecoder alloc] initWithInformation:information firstAIdigits:@"320" dateCode:@"15"];
  74. case 62:
  75. return [[ZXAI013x0x1xDecoder alloc] initWithInformation:information firstAIdigits:@"310" dateCode:@"17"];
  76. case 63:
  77. return [[ZXAI013x0x1xDecoder alloc] initWithInformation:information firstAIdigits:@"320" dateCode:@"17"];
  78. }
  79. @throw [NSException exceptionWithName:NSInternalInconsistencyException
  80. reason:[NSString stringWithFormat:@"unknown decoder: %@", information]
  81. userInfo:nil];
  82. }
  83. @end