• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 CHARACTER_TRANSLITERATE_H
17 #define CHARACTER_TRANSLITERATE_H
18 
19 #include <map>
20 #include <string>
21 #include <vector>
22 
23 namespace OHOS {
24 namespace Contacts {
25 struct ChineseTable {
26     // The first letter of Pinyin
27     std::string initials;
28     // Pinyin
29     std::string nameFullFight_;
30     std::string chineseCharacters_;
31 };
32 
33 struct Container {
34     // The container of first letter
35     std::vector<std::vector<std::wstring>> initialsContainer_;
36     // Pinyin container
37     std::vector<std::vector<std::wstring>> nameFullFightContainer_;
38 };
39 
40 class CharacterTransliterate {
41 public:
42     CharacterTransliterate();
43     ~CharacterTransliterate();
44     static ChineseTable chineseTable_[];
45     bool IsChineseCharacter(wchar_t chineseCharacter);
46     Container GetContainer(std::wstring wChinese);
47     std::wstring Join(std::vector<std::vector<std::wstring>> strVector, std::wstring split);
48     void GetCommonPronunciation(
49         std::wstring &chineseCharacter, std::vector<std::wstring> &initials, std::vector<std::wstring> &nameFullFights);
50     std::vector<std::vector<std::wstring>> GetCombinedVector(std::vector<std::vector<std::wstring>> sourceVector);
51     std::wstring StringToWstring(std::string str);
52     std::string WstringToString(std::wstring str);
53 private:
54     static std::map<std::string, std::string> multiPronunciationMap;
55     std::string getMultiPronunciation(std::string chineseCharacter);
56 };
57 } // namespace Contacts
58 } // namespace OHOS
59 #endif // CHARACTER_TRANSLITERATE_H
60