11401458bSopenharmony_ci/* 21401458bSopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 31401458bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 41401458bSopenharmony_ci * you may not use this file except in compliance with the License. 51401458bSopenharmony_ci * You may obtain a copy of the License at 61401458bSopenharmony_ci * 71401458bSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 81401458bSopenharmony_ci * 91401458bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 101401458bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 111401458bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 121401458bSopenharmony_ci * See the License for the specific language governing permissions and 131401458bSopenharmony_ci * limitations under the License. 141401458bSopenharmony_ci */ 151401458bSopenharmony_ci#ifndef HISYSEVENT_STRING_UTIL 161401458bSopenharmony_ci#define HISYSEVENT_STRING_UTIL 171401458bSopenharmony_ci 181401458bSopenharmony_ci#include <string> 191401458bSopenharmony_ci#include <vector> 201401458bSopenharmony_ci 211401458bSopenharmony_cinamespace OHOS { 221401458bSopenharmony_cinamespace HiviewDFX { 231401458bSopenharmony_cinamespace StringUtil { 241401458bSopenharmony_ciint CopyCString(char* dst, const std::string& src, size_t len); 251401458bSopenharmony_ciint CreateCString(char** dst, const std::string& src, size_t len = 1024); // default maxLen is 1024 261401458bSopenharmony_ciint ConvertCString(const std::string& str, char** sp, size_t len = 8 * 1024); // default maxLen is 8*1024 271401458bSopenharmony_ciint ConvertCStringVec(const std::vector<std::string>& vec, char*** strs, size_t& len); 281401458bSopenharmony_civoid MemsetSafe(void* dest, size_t destSize); 291401458bSopenharmony_ci 301401458bSopenharmony_citemplate <typename T> void DeletePointer(T** p) 311401458bSopenharmony_ci{ 321401458bSopenharmony_ci if (p == nullptr || *p == nullptr) { 331401458bSopenharmony_ci return; 341401458bSopenharmony_ci } 351401458bSopenharmony_ci delete[] *p; 361401458bSopenharmony_ci *p = nullptr; 371401458bSopenharmony_ci} 381401458bSopenharmony_ci 391401458bSopenharmony_citemplate <typename T> void DeletePointers(T*** ps, size_t len) 401401458bSopenharmony_ci{ 411401458bSopenharmony_ci if (ps == nullptr || *ps == nullptr) { 421401458bSopenharmony_ci return; 431401458bSopenharmony_ci } 441401458bSopenharmony_ci auto realPs = *ps; 451401458bSopenharmony_ci for (size_t i = 0; i < len; i++) { 461401458bSopenharmony_ci DeletePointer<T>(&realPs[i]); 471401458bSopenharmony_ci } 481401458bSopenharmony_ci delete[] realPs; 491401458bSopenharmony_ci realPs = nullptr; 501401458bSopenharmony_ci} 511401458bSopenharmony_ci} // namespace StringUtil 521401458bSopenharmony_ci} // namespace HiviewDFX 531401458bSopenharmony_ci} // namespace OHOS 541401458bSopenharmony_ci#endif // HISYSEVENT_STRING_UTIL 55