• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef STRING_UTILS_H
16 #define STRING_UTILS_H
17 #include <string>
18 #include <vector>
19 #include "singleton.h"
20 namespace OHOS {
21 namespace HiviewDFX {
22 class StringUtils : public Singleton<StringUtils> {
23 public:
24     StringUtils();
25     ~StringUtils();
26     StringUtils(StringUtils const &) = delete;
27     void operator=(StringUtils const &) = delete;
28 
29     void StringSplit(const std::string &str, const std::string &split, std::vector<std::string> &result);
30     void StringRegex(const std::string &str, const std::string &pattern, const int& idx, std::string &result);
31     bool IsBegin(const std::string &content, const std::string &begin);
32     bool IsEnd(const std::string &content, const std::string &end);
33     bool IsContain(const std::string &content, const std::string &contain);
34     bool IsSameStr(const std::string &first, const std::string &second);
35     void ReplaceAll(std::string &str, const std::string &oldValue, const std::string &newValue);
36     bool IsNum(std::string str);
37     bool Compare(const std::string &str, const std::vector<std::string> &strs);
38     void HexToDec(const std::string &str, uint64_t &value);
39     void SetWidth(const int &width, const char &fileStr, const bool &left, std::string &str);
40     char GetBlank();
41     char GetSeparator();
42 
43 private:
44     const int HEX_STR = 16;
45     const int DEC_STR = 10;
46 };
47 } // namespace HiviewDFX
48 } // namespace OHOS
49 #endif