1 /* 2 * Copyright (c) 2021-2023 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 COMMUNICATIONNETSTACK_COMMON_UTILS_H 17 #define COMMUNICATIONNETSTACK_COMMON_UTILS_H 18 19 #include <iosfwd> 20 #include <list> 21 #include <vector> 22 23 namespace OHOS::NetStack::CommonUtils { 24 std::vector<std::string> Split(const std::string &str, const std::string &sep); 25 26 std::vector<std::string> Split(const std::string &str, const std::string &sep, size_t size); 27 28 std::string Strip(const std::string &str, char ch = ' '); 29 30 std::string ToLower(const std::string &s); 31 32 std::string ToString(const std::list<std::string> &lists, char tab = ','); 33 34 bool HasInternetPermission(); 35 36 bool EndsWith(const std::string &str, const std::string &suffix); 37 38 std::string Trim(std::string str); 39 40 bool IsMatch(const std::string &str, const std::string &patternStr); 41 42 std::string InsertCharBefore(const std::string &input, const char from, const char preChar, const char nextChar); 43 44 std::string ReplaceCharacters(const std::string &input); 45 46 bool IsRegexValid(const std::string ®ex); 47 48 std::string GetHostnameFromURL(const std::string& url); 49 50 bool IsExcluded(const std::string &str, const std::string &exclusions, const std::string &split); 51 52 bool IsHostNameExcluded(const std::string &url, const std::string &exclusions, const std::string &split); 53 54 bool IsValidIP(const std::string& ip, int af); 55 56 bool IsValidIPV4(const std::string &ip); 57 58 bool IsValidIPV6(const std::string &ip); 59 60 std::string MaskIpv4(std::string &maskedResult); 61 62 std::string MaskIpv6(std::string &maskedResult); 63 64 std::string AnonymizeIp(std::string &input); 65 } // namespace OHOS::NetStack::CommonUtils 66 #endif /* COMMUNICATIONNETSTACK_COMMON_UTILS_H */ 67