• 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 SERVICES_INCLUDE_UTILS_H
17 #define SERVICES_INCLUDE_UTILS_H
18 
19 #include <string>
20 
21 #include "input_method_info.h"
22 #include "input_method_property.h"
23 #include "input_method_status.h"
24 #include "string_ex.h"
25 
26 namespace OHOS ::MiscServices {
27 class Utils {
28 public:
29     static constexpr int USER_ID_CHANGE_VALUE = 200000;
30 
ToStr8(const std::u16string & str16)31     static std::string ToStr8(const std::u16string &str16)
32     {
33         return Str16ToStr8(str16);
34     }
35 
ToStr16(const std::string & str)36     static std::u16string ToStr16(const std::string &str)
37     {
38         return Str8ToStr16(str);
39     }
40 
ToProperty(const std::vector<InputMethodInfo> & properties)41     static std::vector<Property> ToProperty(const std::vector<InputMethodInfo> &properties)
42     {
43         std::vector<Property> props;
44         for (const auto &property : properties) {
45             props.push_back({ Str16ToStr8(property.mPackageName), Str16ToStr8(property.mAbilityName) });
46         }
47         return props;
48     }
49 
ToProperty(const InputMethodInfo & property)50     static Property ToProperty(const InputMethodInfo &property)
51     {
52         return { Str16ToStr8(property.mPackageName), Str16ToStr8(property.mAbilityName) };
53     }
54 
ToUserId(uint32_t uid)55     static uint32_t ToUserId(uint32_t uid)
56     {
57         return uid / USER_ID_CHANGE_VALUE;
58     }
59 };
60 } // namespace OHOS::MiscServices
61 
62 #endif // SERVICES_INCLUDE_UTILS_H
63