• 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     int Gsm7bitToUtf8(uint8_t *dest, int maxLength, const uint8_t *src, int srcLength, const MsgLangInfo &langInfo);
39     int Ucs2ToUtf8(uint8_t *dest, int maxLength, const uint8_t *src, int srcLength);
40     int EuckrToUtf8(uint8_t *dest, int maxLength, const uint8_t *src, int srcLength);
41     int ShiftjisToUtf8(uint8_t *dest, int maxLength, const uint8_t *src, int srcLength) const;
42 
43 private:
44     TextCoder();
45     virtual ~TextCoder();
46     int Ucs2ToGsm7bit(uint8_t *dest, int maxLength, const uint8_t *src, int srcLength, MSG_LANGUAGE_ID_T &langId);
47     int Ucs2ToGsm7bitAuto(uint8_t *dest, int maxLength, const uint8_t *src, int srcLength, bool &unknown);
48     int Ucs2ToAscii(uint8_t *dest, int maxLength, const uint8_t *src, int srcLength, bool &unknown);
49     uint8_t GetLangType(const uint8_t *src, int srcLength);
50     int FindGsm7bitExt(uint8_t *dest, int maxLength, const uint16_t inText);
51     int FindTurkish(uint8_t *dest, int maxLength, const uint16_t inText);
52     int FindSpanish(uint8_t *dest, int maxLength, const uint16_t inText);
53     int FindPortu(uint8_t *dest, int maxLength, const uint16_t inText);
54     uint8_t FindReplaceChar(const uint16_t inText);
55 
56     int Gsm7bitToUcs2(uint8_t *dest, int maxLength, const uint8_t *src, int srcLength, const MsgLangInfo &langInfo);
57     int EscapeTurkishLockingToUcs2(const uint8_t *src, int srcLen, const MsgLangInfo &langInfo, uint16_t &result);
58     int EscapePortuLockingToUcs2(const uint8_t *src, int srcLen, const MsgLangInfo &langInfo, uint16_t &result);
59     int EscapeGsm7bitToUcs2(const uint8_t *src, int srcLen, const MsgLangInfo &langInfo, uint16_t &result);
60     uint16_t EscapeToUcs2(const uint8_t srcText, const MsgLangInfo &langInfo);
61 
62     void GetTurkishSingleToUcs2(const uint8_t &srcText, uint16_t &result);
63     void GetSpanishSingleToUcs2(const uint8_t &srcText, uint16_t &result);
64     void GetGsm7BitExtToUcs2(const uint8_t &srcText, uint16_t &result);
65     void GetPortuSingleToUcs2(const uint8_t &srcText, uint16_t &result);
66 
67     void InitExtCharMap();
68     void InitGsm7bitDefMap();
69     void InitGsm7bitExtMap();
70     void InitTurkishMap();
71     void InitSpanishMap();
72     void InitPortuMap();
73     void InitReplaceCharMap();
74 
75 private:
76     std::map<uint16_t, uint8_t> extCharMap_;
77     std::map<uint16_t, uint8_t> gsm7bitDefMap_;
78     std::map<uint16_t, uint8_t> gsm7bitExtMap_;
79     std::map<uint16_t, uint8_t> turkishMap_;
80     std::map<uint16_t, uint8_t> spanishMap_;
81     std::map<uint16_t, uint8_t> portuMap_;
82     std::map<uint16_t, uint8_t> replaceCharMap_;
83 };
84 } // namespace Telephony
85 } // namespace OHOS
86 #endif
87