• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #ifndef OHOS_HDI_STRING_HELPER_H
10 #define OHOS_HDI_STRING_HELPER_H
11 
12 #include <cstring>
13 #include <string>
14 #include <vector>
15 
16 namespace OHOS {
17 namespace HDI {
18 class StringHelper {
19 public:
20     static std::vector<std::string> Split(std::string sources, const std::string &limit);
21 
22     static bool StartWith(const std::string &value, char prefix);
23 
24     static bool StartWith(const std::string &value, const std::string &prefix);
25 
26     static bool EndWith(const std::string &value, char suffix);
27 
28     static bool EndWith(const std::string &value, const std::string &suffix);
29 
30     static std::string Replace(const std::string &value, char oldChar, char newChar);
31 
32     static std::string Replace(const std::string &value, const std::string &oldstr, const std::string &newstr);
33 
34     static std::string Replace(
35         const std::string &value, size_t position, const std::string &substr, const std::string &newstr);
36 
37     static std::string Replace(const std::string &value, size_t position, size_t len, const std::string &newStr);
38 
39     static std::string SubStr(const std::string &value, size_t start, size_t end = std::string::npos);
40 
41     static std::string StrToLower(const std::string &value);
42 
43     static std::string StrToUpper(const std::string &value);
44 
45     static std::string Format(const char *format, ...);
46 
47     static constexpr size_t lineMaxSize = 1024; // 1KB
48     static constexpr size_t maxSize = 262144;    // 256KB
49 };
50 } // namespace HDI
51 } // namespace OHOS
52 
53 #endif // OHOS_HDI_STRING_HELPER_H