1 /*
2  * Copyright (c) 2022 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 #ifndef VCARD_UTILS_H
17 #define VCARD_UTILS_H
18 
19 #include <string>
20 #include <vector>
21 
22 namespace OHOS {
23 namespace Telephony {
24 class VCardUtils {
25 public:
26     static bool EqualsIgnoreCase(const std::string &str1, const std::string &str2);
27     static std::vector<std::string> Split(const std::string &input, const std::string &delimiter);
28     static std::string Trim(std::string &str);
29     static std::string ToUpper(const std::string &str);
30     static bool StartWith(const std::string &str, const std::string &prefix);
31     static bool EndWith(const std::string &fullString, const std::string &ending);
32     static std::string EncodeBase64(const std::string &from);
33     static std::string DecodeBase64(const std::string &encoded);
34     static std::string ConvertCharset(
35         const std::string &input, const std::string &fromCharset, const std::string &toCharset, int32_t &errorCode);
36     static std::string ConvertCharset(
37         const std::string &decodedBytes, const std::string &targetCharset, int32_t &errorCode);
38     static std::string GetBytes(const std::string &str, const std::string &charset);
39     static std::string CreateFileName();
40     static void SaveFile(const std::string &fileStr, const std::string &path);
41     static bool IsPrintableAscii(std::vector<std::string> strs);
42     static bool IsPrintableAscii(const std::string &str);
43     static bool IsPrintableAscii(char c);
44     static bool IsWrapPrintableAscii(std::vector<std::string> strs);
45     static std::string GetTypeFromImLabelId(std::string labelId);
46     static std::vector<std::string> GetTypeFromPhoneLabelId(std::string labelId);
47     static std::string GetImageType(std::string bytes);
48     static bool IsNum(const std::string &str);
49     static std::string TrimListToString(const std::vector<std::string> &strs);
50     static std::vector<std::string> ConstructListFromValue(const std::string &value, std::string vcardType);
51     static void GetPhoneTypeFromStrings(
52         const std::vector<std::string> &types, std::string number, std::tuple<int32_t, std::string> &result);
53     static int32_t VcardtypeToInt(const std::string &vcardType);
54     static std::string FormatNumber(std::string source);
55     static int32_t GetPhoneNumberFormat(const int32_t vcardType);
56     static bool IsAllEmpty(std::vector<std::string> values);
57     static int32_t GetLabelIdFromImType(std::string type);
58     static std::string HandleCh(char nextCh, std::string vcardType);
59     static void HandleTypeAndLabel(int32_t &type, std::string &label, std::string number, std::string typeStringOrg);
60 };
61 } // namespace Telephony
62 } // namespace OHOS
63 #endif /* VCARD_UTILS_H */
64