• 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 
16 #ifndef HISYSEVENT_STRING_FILTER_H
17 #define HISYSEVENT_STRING_FILTER_H
18 
19 #include <string>
20 
21 namespace OHOS {
22 namespace HiviewDFX {
23 class StringFilter {
24 public:
25     StringFilter();
~StringFilter()26     ~StringFilter() {}
27     // Transform special char to escaped form ("lookup table" method)
28     std::string EscapeToRaw(const std::string &text);
29     // Check lexical ("finite state machine" method)
30     bool IsValidName(const std::string &text, unsigned int maxSize);
31     static StringFilter& GetInstance();
32 
33 private:
34     static constexpr int CHAR_RANGE = 128;
35     static constexpr int MAP_STR_LEN = 3;
36 
37     static constexpr int STATE_NUM = 2;
38     static constexpr int STATE_BEGIN = 0;
39     static constexpr int STATE_RUN = 1;
40     static constexpr int STATE_STOP = -1;
41 
42     static char charTab_[CHAR_RANGE][MAP_STR_LEN];
43     static int statTab_[STATE_NUM][CHAR_RANGE];
44     static StringFilter filter_;
45 };
46 } // namespace HiviewDFX
47 } // namespace OHOS
48 
49 #endif // HISYSEVENT_STRING_FILTER_H
50 
51