• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 RESSCHED_COMMON_INCLUDE_RES_SCHED_STRING_UTIL
17 #define RESSCHED_COMMON_INCLUDE_RES_SCHED_STRING_UTIL
18 #include <string>
19 
20 #include "nlohmann/json.hpp"
21 
22 namespace OHOS {
23 namespace ResourceSchedule {
24 namespace ResCommonUtil {
25 
26 /**
27  * @brief Converts a string to an float value.
28  *
29  * @param value Indicates the string to be converted
30  * @param result Indicates the `float` variable to store the result
31  * @return Returns 'true' is the operation is successful;
32  * return `false` otherwise
33  */
34 bool StrToFloat(const std::string& value, float& result);
35 
36 /**
37  * @brief Check a bundle name is vaild
38  *
39  * @param bundleName Indicates the bundle name to be check
40  * @return Returns 'true' is the bundle name valid;
41  * return `false` otherwise
42  */
43 bool CheckBundleName(const std::string &bundleName);
44 
45 /**
46  * @brief Converts a string to an int32_t value.
47  *
48  * @param value Indicates the string to be converted
49  * @param result Indicates the `int32_t` variable to store the result
50  * @return Returns 'true' is the operation is successful;
51  * return `false` otherwise
52  */
53 bool StrToInt32(const std::string& value, int32_t& result);
54 
55 /**
56  * @brief Converts a string to an int64_t value.
57  *
58  * @param value Indicates the string to be converted
59  * @param result Indicates the `int64_t` variable to store the result
60  * @return Returns 'true' is the operation is successful;
61  * return `false` otherwise
62  */
63 bool StrToInt64(const std::string& value, int64_t& result);
64 
65 /**
66  * @brief Converts a string to an uint32_t value.
67  *
68  * @param value Indicates the string to be converted
69  * @param result Indicates the `uint32_t` variable to store the result
70  * @return Returns 'true' is the operation is successful;
71  * return `false` otherwise
72  */
73 bool StrToUInt32(const std::string& value, uint32_t& result);
74 
75 /**
76  * @brief Judge string is number format
77  *
78  * @param value Indicates the string to be judged.
79  * @return Returns 'true' is the string is number format;
80  * return `false` otherwise
81  */
82 bool IsNumericString(const std::string& value);
83 
84 /**
85  * @brief Trim string(include '\f' '\v' '\r' '\t' '\n' ' ')
86  *
87  * @param value Indicates the string to be trimed.
88  * @return Returns trimed string;
89  */
90 std::string StringTrim(const std::string& str);
91 
92 /**
93  * @brief Trim string(only ' ')
94  *
95  * @param value Indicates the string to be trimed.
96  * @return Returns trimed string;
97  */
98 std::string StringTrimSpace(const std::string& value);
99 
100 /**
101  * @brief Convert a string to json object
102  *
103  * @param str Indicates the string to be converted.
104  * @return Returns 'true' if convert success;
105  */
106 bool StringToJson(const std::string& str, nlohmann::json& payload);
107 }
108 } // namespace ResourceSchedule
109 } // namespace OHOS
110 
111 #endif // RESSCHED_COMMON_INCLUDE_RES_SCHED_STRING_UTIL