NBPhoneNumberDesc.m 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //
  2. // NBPhoneNumberDesc.m
  3. // libPhoneNumber
  4. //
  5. //
  6. #import "NBPhoneNumberDesc.h"
  7. #import "NSArray+NBAdditions.h"
  8. @implementation NBPhoneNumberDesc
  9. - (instancetype)initWithEntry:(NSArray *)entry {
  10. self = [super init];
  11. if (self && entry != nil) {
  12. _nationalNumberPattern = [entry nb_safeStringAtIndex:2];
  13. _possibleNumberPattern = [entry nb_safeStringAtIndex:3];
  14. _possibleLength = [entry nb_safeArrayAtIndex:9];
  15. _possibleLengthLocalOnly = [entry nb_safeArrayAtIndex:10];
  16. _exampleNumber = [entry nb_safeStringAtIndex:6];
  17. _nationalNumberMatcherData = [entry nb_safeDataAtIndex:7];
  18. _possibleNumberMatcherData = [entry nb_safeDataAtIndex:8];
  19. }
  20. return self;
  21. }
  22. - (NSString *)description {
  23. return [NSString stringWithFormat:
  24. @"nationalNumberPattern[%@] possibleNumberPattern[%@] possibleLength[%@] "
  25. @"possibleLengthLocalOnly[%@] exampleNumber[%@]",
  26. self.nationalNumberPattern, self.possibleNumberPattern, self.possibleLength,
  27. self.possibleLengthLocalOnly, self.exampleNumber];
  28. }
  29. #ifdef NB_USE_EXTENSIONS
  30. // We believe these methods are unused.
  31. // If you would like them back (not behind a flag) please file a bug with a reason for needing
  32. // them.
  33. - (instancetype)initWithCoder:(NSCoder *)coder {
  34. if (self = [super init]) {
  35. _nationalNumberPattern = [coder decodeObjectForKey:@"nationalNumberPattern"];
  36. _possibleNumberPattern = [coder decodeObjectForKey:@"possibleNumberPattern"];
  37. _possibleLength = [coder decodeObjectForKey:@"possibleLength"];
  38. _possibleLengthLocalOnly = [coder decodeObjectForKey:@"possibleLengthLocalOnly"];
  39. _exampleNumber = [coder decodeObjectForKey:@"exampleNumber"];
  40. _nationalNumberMatcherData = [coder decodeObjectForKey:@"nationalNumberMatcherData"];
  41. _possibleNumberMatcherData = [coder decodeObjectForKey:@"possibleNumberMatcherData"];
  42. }
  43. return self;
  44. }
  45. - (void)encodeWithCoder:(NSCoder *)coder {
  46. [coder encodeObject:self.nationalNumberPattern forKey:@"nationalNumberPattern"];
  47. [coder encodeObject:self.possibleNumberPattern forKey:@"possibleNumberPattern"];
  48. [coder encodeObject:self.possibleLength forKey:@"possibleLength"];
  49. [coder encodeObject:self.possibleLengthLocalOnly forKey:@"possibleLengthLocalOnly"];
  50. [coder encodeObject:self.exampleNumber forKey:@"exampleNumber"];
  51. [coder encodeObject:self.nationalNumberMatcherData forKey:@"nationalNumberMatcherData"];
  52. [coder encodeObject:self.possibleNumberMatcherData forKey:@"possibleNumberMatcherData"];
  53. }
  54. - (id)copyWithZone:(NSZone *)zone {
  55. return self;
  56. }
  57. - (BOOL)isEqual:(id)object {
  58. if ([object isKindOfClass:[NBPhoneNumberDesc class]] == NO) {
  59. return NO;
  60. }
  61. NBPhoneNumberDesc *other = object;
  62. return [self.nationalNumberPattern isEqual:other.nationalNumberPattern] &&
  63. [self.possibleNumberPattern isEqual:other.possibleNumberPattern] &&
  64. [self.possibleLength isEqual:other.possibleLength] &&
  65. [self.possibleLengthLocalOnly isEqual:other.possibleLengthLocalOnly] &&
  66. [self.exampleNumber isEqual:other.exampleNumber] &&
  67. [self.nationalNumberMatcherData isEqualToData:other.nationalNumberMatcherData] &&
  68. [self.possibleNumberMatcherData isEqualToData:other.possibleNumberMatcherData];
  69. }
  70. #endif // NB_USE_EXTENSIONS
  71. @end