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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 "ZXCharacterSetECI.h"
  17. #import "ZXErrors.h"
  18. static NSMutableDictionary *VALUE_TO_ECI = nil;
  19. static NSMutableDictionary *ENCODING_TO_ECI = nil;
  20. @implementation ZXCharacterSetECI
  21. + (void)initialize {
  22. if ([self class] != [ZXCharacterSetECI class]) return;
  23. VALUE_TO_ECI = [[NSMutableDictionary alloc] initWithCapacity:29];
  24. ENCODING_TO_ECI = [[NSMutableDictionary alloc] initWithCapacity:29];
  25. [self addCharacterSet:0 encoding:(NSStringEncoding) 0x80000400];
  26. [self addCharacterSet:1 encoding:NSISOLatin1StringEncoding];
  27. [self addCharacterSet:2 encoding:(NSStringEncoding) 0x80000400];
  28. [self addCharacterSet:3 encoding:NSISOLatin1StringEncoding];
  29. [self addCharacterSet:4 encoding:NSISOLatin2StringEncoding];
  30. [self addCharacterSet:5 encoding:(NSStringEncoding) 0x80000203];
  31. [self addCharacterSet:6 encoding:(NSStringEncoding) 0x80000204];
  32. [self addCharacterSet:7 encoding:(NSStringEncoding) 0x80000205];
  33. [self addCharacterSet:8 encoding:(NSStringEncoding) 0x80000206];
  34. [self addCharacterSet:9 encoding:(NSStringEncoding) 0x80000207];
  35. [self addCharacterSet:10 encoding:(NSStringEncoding) 0x80000208];
  36. [self addCharacterSet:11 encoding:(NSStringEncoding) 0x80000209];
  37. [self addCharacterSet:12 encoding:(NSStringEncoding) 0x8000020A];
  38. [self addCharacterSet:13 encoding:(NSStringEncoding) 0x8000020B];
  39. [self addCharacterSet:15 encoding:(NSStringEncoding) 0x8000020D];
  40. [self addCharacterSet:16 encoding:(NSStringEncoding) 0x8000020E];
  41. [self addCharacterSet:17 encoding:(NSStringEncoding) 0x8000020F];
  42. [self addCharacterSet:18 encoding:(NSStringEncoding) 0x80000210];
  43. [self addCharacterSet:20 encoding:NSShiftJISStringEncoding];
  44. [self addCharacterSet:21 encoding:NSWindowsCP1250StringEncoding];
  45. [self addCharacterSet:22 encoding:NSWindowsCP1251StringEncoding];
  46. [self addCharacterSet:23 encoding:NSWindowsCP1252StringEncoding];
  47. [self addCharacterSet:24 encoding:(NSStringEncoding) 0x80000505];
  48. [self addCharacterSet:25 encoding:NSUTF16BigEndianStringEncoding];
  49. [self addCharacterSet:26 encoding:NSUTF8StringEncoding];
  50. [self addCharacterSet:27 encoding:NSASCIIStringEncoding];
  51. [self addCharacterSet:28 encoding:(NSStringEncoding) 0x80000A03];
  52. [self addCharacterSet:29 encoding:(NSStringEncoding) 0x80000632];
  53. [self addCharacterSet:30 encoding:(NSStringEncoding) 0x80000940];
  54. [self addCharacterSet:170 encoding:NSASCIIStringEncoding];
  55. }
  56. - (id)initWithValue:(int)value encoding:(NSStringEncoding)encoding {
  57. if (self = [super init]) {
  58. _value = value;
  59. _encoding = encoding;
  60. }
  61. return self;
  62. }
  63. + (void)addCharacterSet:(int)value encoding:(NSStringEncoding)encoding {
  64. ZXCharacterSetECI *eci = [[ZXCharacterSetECI alloc] initWithValue:value encoding:encoding];
  65. VALUE_TO_ECI[@(value)] = eci;
  66. ENCODING_TO_ECI[@(encoding)] = eci;
  67. }
  68. + (ZXCharacterSetECI *)characterSetECIByValue:(int)value {
  69. if (VALUE_TO_ECI == nil) {
  70. [self initialize];
  71. }
  72. if (value < 0 || value >= 900) {
  73. return nil;
  74. }
  75. return VALUE_TO_ECI[@(value)];
  76. }
  77. + (ZXCharacterSetECI *)characterSetECIByEncoding:(NSStringEncoding)encoding {
  78. if (ENCODING_TO_ECI == nil) {
  79. [self initialize];
  80. }
  81. return ENCODING_TO_ECI[@(encoding)];
  82. }
  83. @end