1 /*
2 * Copyright (C) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "map_mse_vcard.h"
17 #include <algorithm>
18
19 namespace OHOS {
20 namespace bluetooth {
MapMseVcard(const MseVcard2 & vcard)21 MapMseVcard::MapMseVcard(const MseVcard2 &vcard)
22 : name_(vcard.name_),
23 version_(vcard.version_),
24 formattedName_(vcard.formattedName_),
25 phoneNumbers_(vcard.phoneNumbers_),
26 emailAddresses_(vcard.emailAddresses_),
27 envLevel_(vcard.envLevel_)
28 {}
29
MapMseVcard(const MseVcard3 & vcard)30 MapMseVcard::MapMseVcard(const MseVcard3 &vcard)
31 : name_(vcard.name_),
32 version_(vcard.version_),
33 formattedName_(vcard.formattedName_),
34 phoneNumbers_(vcard.phoneNumbers_),
35 emailAddresses_(vcard.emailAddresses_),
36 envLevel_(vcard.envLevel_),
37 btUids_(vcard.btUids_),
38 btUcis_(vcard.btUcis_)
39 {}
40
GetFirstPhoneNumber(void) const41 std::string MapMseVcard::GetFirstPhoneNumber(void) const
42 {
43 std::string number;
44 if (phoneNumbers_.size() > 0) {
45 number = phoneNumbers_.at(0);
46 }
47 return number;
48 }
49
GetEnvLevel(void) const50 int MapMseVcard::GetEnvLevel(void) const
51 {
52 return envLevel_;
53 }
54
GetName(void) const55 std::string MapMseVcard::GetName(void) const
56 {
57 return name_;
58 }
59
GetVersion(void) const60 std::string MapMseVcard::GetVersion(void) const
61 {
62 return version_;
63 }
64
GetFormattedName(void) const65 std::string MapMseVcard::GetFormattedName(void) const
66 {
67 return formattedName_;
68 }
69
GetPhoneNumbersText(void) const70 std::string MapMseVcard::GetPhoneNumbersText(void) const
71 {
72 std::string pn;
73 for (auto &iter : phoneNumbers_) {
74 pn.append(iter + ";");
75 }
76 return pn;
77 }
78
GetEmailAddressesText(void) const79 std::string MapMseVcard::GetEmailAddressesText(void) const
80 {
81 std::string addr = "";
82 for (auto &iter : emailAddresses_) {
83 if (iter != "") {
84 addr.append(iter + ";");
85 }
86 }
87 return addr;
88 }
89
GetBtUidsText(void) const90 std::string MapMseVcard::GetBtUidsText(void) const
91 {
92 std::string btUids = "";
93 for (auto &iter : btUids_) {
94 if (iter != "") {
95 btUids.append(iter + ";");
96 }
97 }
98 return btUids;
99 }
100
GetBtUcisText(void) const101 std::string MapMseVcard::GetBtUcisText(void) const
102 {
103 std::string btUcis = "";
104 for (auto &iter : btUcis_) {
105 if (iter != "") {
106 btUcis.append(iter + ";");
107 }
108 }
109 return btUcis;
110 }
111
GetFirstEmail(void) const112 std::string MapMseVcard::GetFirstEmail(void) const
113 {
114 std::string email;
115 if (emailAddresses_.size() > 0) {
116 email = emailAddresses_.at(0);
117 }
118 return email;
119 }
120
ToVcardString(const std::string & bmsgVersion)121 std::string MapMseVcard::ToVcardString(const std::string &bmsgVersion)
122 {
123 std::string vcd;
124 vcd.append("BEGIN:VCARD");
125 vcd.append("\n");
126 vcd.append("VERSION:" + version_);
127 vcd.append("\n");
128 vcd.append("N:" + name_);
129 vcd.append("\n");
130 if (version_ == "3.0") {
131 vcd.append("FN:" + formattedName_);
132 vcd.append("\n");
133 }
134 if (GetEmailAddressesText() != "") {
135 vcd.append("EMAIL:" + GetEmailAddressesText());
136 vcd.append("\n");
137 }
138 if (bmsgVersion == "1.1") {
139 if (GetBtUidsText() != "") {
140 vcd.append("X-BT-UID:" + GetBtUidsText());
141 vcd.append("\n");
142 }
143 if (GetBtUcisText() != "") {
144 vcd.append("X-BT-UCI:" + GetBtUcisText());
145 vcd.append("\n");
146 }
147 }
148 vcd.append("END:VCARD");
149 return vcd;
150 }
151 } // namespace bluetooth
152 } // namespace OHOS