Skip to content
Snippets Groups Projects
Commit 2647eaaf authored by Nicolas Jager's avatar Nicolas Jager
Browse files

contact : trim contact white space

- removes the white spaces from the begin and the end of contacts
during their add.

Change-Id: I6d01d84cdd68c6b044da8b16c6ee89fbf9e721e8
Tuleap: #979
parent 655df54f
No related branches found
No related tags found
No related merge requests found
......@@ -71,8 +71,9 @@ ContactsViewModel::findContactByName(String^ name)
Contact^
ContactsViewModel::addNewContact(String^ name, String^ ringId)
{
if (contactsList_ && !findContactByName(name)) {
Contact^ contact = ref new Contact(name, name);
auto trimedName = Utils::Trim(name);
if (contactsList_ && !findContactByName(trimedName)) {
Contact^ contact = ref new Contact(trimedName, trimedName);
contactsList_->Append(contact);
saveContactsToFile();
return contact;
......
......@@ -74,5 +74,19 @@ Platform::String^ toPlatformString(const std::string& str)
return ref new Platform::String(wsstr.c_str(), wsstr.length());
}
Platform::String^ Trim(Platform::String^ s)
{
const WCHAR* first = s->Begin();
const WCHAR* last = s->End();
while (first != last && iswspace(*first))
++first;
while (first != last && iswspace(last[-1]))
--last;
return ref new Platform::String(first, static_cast<unsigned int>(last - first));
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment