Improve handling of whitespace in contacts.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent 476047e24a
commit 72730c06a6

@ -1,3 +1,7 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "Contact.h" #import "Contact.h"
#import "PhoneNumber.h" #import "PhoneNumber.h"
#import "SignalRecipient.h" #import "SignalRecipient.h"
@ -25,8 +29,8 @@ NS_ASSUME_NONNULL_BEGIN
return self; return self;
} }
_firstName = firstName; _firstName = [self trimName:firstName];
_lastName = lastName; _lastName = [self trimName:lastName];
_uniqueId = [self.class uniqueIdFromABRecordId:record]; _uniqueId = [self.class uniqueIdFromABRecordId:record];
_recordID = record; _recordID = record;
_userTextPhoneNumbers = phoneNumbers; _userTextPhoneNumbers = phoneNumbers;
@ -46,8 +50,8 @@ NS_ASSUME_NONNULL_BEGIN
} }
_cnContact = contact; _cnContact = contact;
_firstName = contact.givenName; _firstName = [self trimName:contact.givenName];
_lastName = contact.familyName; _lastName = [self trimName:contact.familyName];
_uniqueId = contact.identifier; _uniqueId = contact.identifier;
NSMutableArray<NSString *> *phoneNumbers = [NSMutableArray new]; NSMutableArray<NSString *> *phoneNumbers = [NSMutableArray new];
@ -75,6 +79,11 @@ NS_ASSUME_NONNULL_BEGIN
return self; return self;
} }
- (NSString *)trimName:(NSString *)name
{
return [name stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
}
+ (NSString *)uniqueIdFromABRecordId:(ABRecordID)recordId + (NSString *)uniqueIdFromABRecordId:(ABRecordID)recordId
{ {
return [NSString stringWithFormat:@"ABRecordId:%d", recordId]; return [NSString stringWithFormat:@"ABRecordId:%d", recordId];

Loading…
Cancel
Save