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 #include "mms_charset.h"
17
18 namespace OHOS {
19 namespace Telephony {
MmsCharSet()20 MmsCharSet::MmsCharSet()
21 {
22 mapCharSet_.emplace("US-ASCII", 0x03);
23 mapCharSet_.emplace("UTF-16", 0x03F7);
24 mapCharSet_.emplace("CSUNICODE", 0x03E8);
25 mapCharSet_.emplace("UTF-8", 0x6A);
26 mapCharSet_.emplace("ISO-2022-KR", 0x25);
27 mapCharSet_.emplace("KS_C_5601-1987", 0x24);
28 mapCharSet_.emplace("EUC-KR", 0x26);
29 mapCharSet_.emplace("ISO-2022-JP", 0x27);
30 mapCharSet_.emplace("ISO-2022-JP-2", 0x28);
31 mapCharSet_.emplace("ISO_8859-1", 0x04);
32 mapCharSet_.emplace("ISO_8859-2", 0x05);
33 mapCharSet_.emplace("ISO-8859-3", 0x06);
34 mapCharSet_.emplace("ISO-8859-4", 0x07);
35 mapCharSet_.emplace("ISO-8859-5", 0x08);
36 mapCharSet_.emplace("ISO-8859-6", 0x09);
37 mapCharSet_.emplace("ISO-8859-7", 0x0A);
38 mapCharSet_.emplace("ISO-8859-8", 0x0B);
39 mapCharSet_.emplace("ISO-8859-9", 0x0C);
40 mapCharSet_.emplace("ISO-8859-10", 0x0D);
41 mapCharSet_.emplace("ISO-8859-15", 0x6F);
42 mapCharSet_.emplace("SHIFT_JIS", 0x11);
43 mapCharSet_.emplace("EUC-JP", 0x13);
44 mapCharSet_.emplace("GB2312", 0x07E9);
45 mapCharSet_.emplace("BIG5", 0x0d);
46 mapCharSet_.emplace("WINDOWS-1251", 0x08CB);
47 mapCharSet_.emplace("KOI8-R", 0x0824);
48 mapCharSet_.emplace("KOI8-U", 0x0828);
49 }
50
~MmsCharSet()51 MmsCharSet::~MmsCharSet()
52 {
53 mapCharSet_.clear();
54 }
55
GetCharSetIntFromString(uint32_t & charSet,const std::string & strCharSet)56 bool MmsCharSet::GetCharSetIntFromString(uint32_t &charSet, const std::string &strCharSet)
57 {
58 auto iterMap = mapCharSet_.find(strCharSet);
59 if (iterMap != mapCharSet_.end()) {
60 charSet = iterMap->second;
61 return true;
62 }
63 return false;
64 }
65
GetCharSetStrFromInt(std::string & strCharSet,uint32_t charSet)66 bool MmsCharSet::GetCharSetStrFromInt(std::string &strCharSet, uint32_t charSet)
67 {
68 for (auto it = mapCharSet_.begin(); it != mapCharSet_.end(); it++) {
69 if (it->second == charSet) {
70 strCharSet = it->first;
71 return true;
72 }
73 }
74 return false;
75 }
76 } // namespace Telephony
77 } // namespace OHOS
78