blob: 3880d149c1f3c767c9368553d9a94d7db37968b8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
//
// Created by martial.simon on 2/26/25.
//
#include "contact_details.hh"
#include <iostream>
#include <stdexcept>
ContactDetails ContactDetails::makeDetails(const std::string& telephone_number,
const std::string& personal_email)
{
for (auto digit : telephone_number)
{
if (!isdigit(digit))
throw std::invalid_argument{
"Phone number must only contain digits."
};
}
size_t i;
for (i = 0; i < personal_email.length(); ++i)
{
if (personal_email[i] == '@')
break;
}
if (i == personal_email.length())
throw std::invalid_argument{ "Email must contain at least one '@'." };
return ContactDetails{ telephone_number, personal_email };
}
std::ostream& operator<<(std::ostream& os, const ContactDetails& dt)
{
os << dt.phone_ << ", " << dt.email_ << "\n";
return os;
}
ContactDetails::ContactDetails(const std::string& telephone_number,
const std::string& personal_email)
: phone_{ telephone_number }
, email_{ personal_email }
{}
|