• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 TEXT_CODER_H
17 #define TEXT_CODER_H
18 
19 #include <map>
20 
21 #include "gsm_pdu_code_type.h"
22 #include "msg_text_convert_common.h"
23 
24 namespace OHOS {
25 namespace Telephony {
26 
27 class TextCoder {
28 public:
29     static TextCoder &Instance();
30     void Base64Encode(const std::string &src, std::string &dest);
31     void Base64Decode(const std::string &src, std::string &dest);
32     bool GetEncodeString(
33         std::string &encodeString, uint32_t charset, uint32_t valLength, const std::string &strEncodeString);
34     int Utf8ToGsm7bit(uint8_t *dest, int maxLength, const uint8_t *src, int srcLength, MSG_LANGUAGE_ID_T &langId);
35     int Utf8ToUcs2(uint8_t *dest, int maxLength, const uint8_t *src, int srcLength);
36     int CdmaUtf8ToAuto(uint8_t *dest, int maxLength, const uint8_t *src, int srcLength, DataCodingScheme &scheme);
37     int GsmUtf8ToAuto(uint8_t *dest, int maxLength, const uint8_t *src, int srcLength, DataCodingScheme &scheme,
38         SmsCodingNationalType codingNationalType, MSG_LANGUAGE_ID_T &langId);
39     int Gsm7bitToUtf8(uint8_t *dest, int maxLength, const uint8_t *src, int srcLength, const MsgLangInfo &langInfo);
40     int Ucs2ToUtf8(uint8_t *dest, int maxLength, const uint8_t *src, int srcLength);
41     int EuckrToUtf8(uint8_t *dest, int maxLength, const uint8_t *src, int srcLength);
42     int ShiftjisToUtf8(uint8_t *dest, int maxLength, const uint8_t *src, int srcLength) const;
43 
44 private:
45     TextCoder();
46     virtual ~TextCoder();
47     int Ucs2ToGsm7bit(uint8_t *dest, int maxLength, const uint8_t *src, int srcLength, MSG_LANGUAGE_ID_T &langId);
48     int Ucs2ToGsm7bitAuto(uint8_t *dest, int maxLength, const uint8_t *src, int srcLength, bool &unknown,
49         SmsCodingNationalType codingNationalType);
50     int Ucs2ToAscii(uint8_t *dest, int maxLength, const uint8_t *src, int srcLength, bool &unknown);
51     uint8_t GetLangType(const uint8_t *src, int srcLength);
52     int FindGsm7bitExt(uint8_t *dest, int maxLength, const uint16_t inText);
53     int FindTurkish(uint8_t *dest, int maxLength, const uint16_t inText);
54     int FindSpanish(uint8_t *dest, int maxLength, const uint16_t inText);
55     int FindPortu(uint8_t *dest, int maxLength, const uint16_t inText);
56     uint8_t FindReplaceChar(const uint16_t inText);
57     std::map<uint16_t, uint8_t> Get7BitCodingExtMap(SmsCodingNationalType codingNationalType) const;
58 
59     int Gsm7bitToUcs2(uint8_t *dest, int maxLength, const uint8_t *src, int srcLength, const MsgLangInfo &langInfo);
60     int EscapeTurkishLockingToUcs2(const uint8_t *src, int srcLen, const MsgLangInfo &langInfo, uint16_t &result);
61     int EscapePortuLockingToUcs2(const uint8_t *src, int srcLen, const MsgLangInfo &langInfo, uint16_t &result);
62     int EscapeGsm7bitToUcs2(const uint8_t *src, int srcLen, const MsgLangInfo &langInfo, uint16_t &result);
63     uint16_t EscapeToUcs2(const uint8_t srcText, const MsgLangInfo &langInfo);
64 
65     void GetTurkishSingleToUcs2(const uint8_t &srcText, uint16_t &result);
66     void GetSpanishSingleToUcs2(const uint8_t &srcText, uint16_t &result);
67     void GetGsm7BitExtToUcs2(const uint8_t &srcText, uint16_t &result);
68     void GetPortuSingleToUcs2(const uint8_t &srcText, uint16_t &result);
69 
70     void InitExtCharMap();
71     void InitGsm7bitDefMap();
72     void InitGsm7bitExtMap();
73     void InitTurkishMap();
74     void InitSpanishMap();
75     void InitPortuMap();
76     void InitReplaceCharMap();
77 
78 private:
79     std::map<uint16_t, uint8_t> extCharMap_;
80     std::map<uint16_t, uint8_t> gsm7bitDefMap_;
81     std::map<uint16_t, uint8_t> gsm7bitExtMap_;
82     std::map<uint16_t, uint8_t> turkishMap_;
83     std::map<uint16_t, uint8_t> spanishMap_;
84     std::map<uint16_t, uint8_t> portuMap_;
85     std::map<uint16_t, uint8_t> replaceCharMap_;
86 };
87 } // namespace Telephony
88 } // namespace OHOS
89 #endif
90