From 72730c06a60b2437f3f9c9ded63c0b1c086f6c04 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 20 Apr 2017 18:04:00 -0400 Subject: [PATCH] Improve handling of whitespace in contacts. // FREEBIE --- src/Contacts/Contact.m | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Contacts/Contact.m b/src/Contacts/Contact.m index 717de82c3..abf555f69 100644 --- a/src/Contacts/Contact.m +++ b/src/Contacts/Contact.m @@ -1,3 +1,7 @@ +// +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// + #import "Contact.h" #import "PhoneNumber.h" #import "SignalRecipient.h" @@ -25,8 +29,8 @@ NS_ASSUME_NONNULL_BEGIN return self; } - _firstName = firstName; - _lastName = lastName; + _firstName = [self trimName:firstName]; + _lastName = [self trimName:lastName]; _uniqueId = [self.class uniqueIdFromABRecordId:record]; _recordID = record; _userTextPhoneNumbers = phoneNumbers; @@ -46,8 +50,8 @@ NS_ASSUME_NONNULL_BEGIN } _cnContact = contact; - _firstName = contact.givenName; - _lastName = contact.familyName; + _firstName = [self trimName:contact.givenName]; + _lastName = [self trimName:contact.familyName]; _uniqueId = contact.identifier; NSMutableArray *phoneNumbers = [NSMutableArray new]; @@ -75,6 +79,11 @@ NS_ASSUME_NONNULL_BEGIN return self; } +- (NSString *)trimName:(NSString *)name +{ + return [name stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; +} + + (NSString *)uniqueIdFromABRecordId:(ABRecordID)recordId { return [NSString stringWithFormat:@"ABRecordId:%d", recordId];