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 
16 #ifndef OHOS_ACELITE_NUMBER_PARSER_H
17 #define OHOS_ACELITE_NUMBER_PARSER_H
18 
19 #include <cstdint>
20 #include "non_copyable.h"
21 
22 namespace OHOS {
23 namespace ACELite {
24 /**
25  * Utils class for number formating operations.
26  */
27 class NumberParser final {
28 public:
29     ACE_DISALLOW_COPY_AND_MOVE(NumberParser);
30     NumberParser() = delete;
31     ~NumberParser() = delete;
32 
33     /**
34      * @brief ParsePercentValue convert percent string to number value
35      * @param percentStr the under processing percent string, for example "10%"
36      * @param strLength the given percent string length
37      * @param outValue the converted result
38      * @return the process result, false for converting failed, true for success, caller
39      * should check the returned value before using outValue.
40      */
41     static bool ParsePercentValue(const char *percentStr, uint16_t strLength, float &outValue);
42 
43 private:
44     /**
45      * @brief IsValidString check if the input target string is valid
46      * @param str the given under processing string
47      * @param strLength the given string's length
48      * @return true for valid string, false for not
49      */
50     static bool IsValidString(const char *str, uint16_t strLength);
51 };
52 } // namespace ACELite
53 } // namespace OHOS
54 
55 #endif // OHOS_ACELITE_NUMBER_PARSER_H
56