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