Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ZXAddressBookDoCoMoResultParser.m 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 "ZXAddressBookDoCoMoResultParser.h"
  17. #import "ZXAddressBookParsedResult.h"
  18. #import "ZXResult.h"
  19. @implementation ZXAddressBookDoCoMoResultParser
  20. - (ZXParsedResult *)parse:(ZXResult *)result {
  21. NSString *rawText = [ZXResultParser massagedText:result];
  22. if (![rawText hasPrefix:@"MECARD:"]) {
  23. return nil;
  24. }
  25. NSArray *rawName = [[self class] matchDoCoMoPrefixedField:@"N:" rawText:rawText trim:YES];
  26. if (rawName == nil) {
  27. return nil;
  28. }
  29. NSString *name = [self parseName:rawName[0]];
  30. NSString *pronunciation = [[self class] matchSingleDoCoMoPrefixedField:@"SOUND:" rawText:rawText trim:YES];
  31. NSArray *phoneNumbers = [[self class] matchDoCoMoPrefixedField:@"TEL:" rawText:rawText trim:YES];
  32. NSArray *emails = [[self class] matchDoCoMoPrefixedField:@"EMAIL:" rawText:rawText trim:YES];
  33. NSString *note = [[self class] matchSingleDoCoMoPrefixedField:@"NOTE:" rawText:rawText trim:NO];
  34. NSArray *addresses = [[self class] matchDoCoMoPrefixedField:@"ADR:" rawText:rawText trim:YES];
  35. NSString *birthday = [[self class] matchSingleDoCoMoPrefixedField:@"BDAY:" rawText:rawText trim:YES];
  36. if (![[self class] isStringOfDigits:birthday length:8]) {
  37. birthday = nil;
  38. }
  39. NSArray *urls = [[self class] matchDoCoMoPrefixedField:@"URL:" rawText:rawText trim:YES];
  40. // Although ORG may not be strictly legal in MECARD, it does exist in VCARD and we might as well
  41. // honor it when found in the wild.
  42. NSString *org = [[self class] matchSingleDoCoMoPrefixedField:@"ORG:" rawText:rawText trim:YES];
  43. return [ZXAddressBookParsedResult addressBookParsedResultWithNames:[self maybeWrap:name]
  44. nicknames:nil
  45. pronunciation:pronunciation
  46. phoneNumbers:phoneNumbers
  47. phoneTypes:nil
  48. emails:emails
  49. emailTypes:nil
  50. instantMessenger:nil
  51. note:note
  52. addresses:addresses
  53. addressTypes:nil
  54. org:org
  55. birthday:birthday
  56. title:nil
  57. urls:urls
  58. geo:nil];
  59. }
  60. - (NSString *)parseName:(NSString *)name {
  61. NSUInteger comma = [name rangeOfString:@","].location;
  62. if (comma != NSNotFound) {
  63. // Format may be last,first; switch it around
  64. return [NSString stringWithFormat:@"%@ %@", [name substringFromIndex:comma + 1], [name substringToIndex:comma]];
  65. }
  66. return name;
  67. }
  68. @end