• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 ConvertTo 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 OHOS_SIM_UTILS_H
17 #define OHOS_SIM_UTILS_H
18 
19 #include <stdlib.h>
20 #include <string>
21 
22 #include "event_handler.h"
23 #include "event_runner.h"
24 #include "string_ex.h"
25 #include "telephony_log_wrapper.h"
26 #include "sim_char_decode.h"
27 
28 namespace OHOS {
29 namespace Telephony {
30 static const int DECIMAL_MAX = 10;
31 static const int HALF_LEN = 2;
32 static const int HALF_BYTE_LEN = 4;
33 static const int UCS_FLAG = 0x81;
34 static const int UCS_WIDE_FLAG = 0x82;
35 static const int START_POS = 3;
36 static const int END_POS = 4;
37 static const int POS_NOT_BLANK = 1;
38 static char HEX_CHARS[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
39 
40 class SIMUtils {
41 public:
42     static unsigned char HexCharConvertToInt(char c);
43     static std::shared_ptr<unsigned char> HexStringConvertToBytes(const std::string &s, int &byteslen);
44     static std::string BytesConvertToHexString(const unsigned char *bytes, int byteLen);
45     static void ArrayCopy(const unsigned char *src, int srcPos, unsigned char *dest, int destPos, int length);
46     static bool IsShowableAscii(char c);
47     static bool IsShowableAsciiOnly(const std::string &str);
48     static std::string BcdPlmnConvertToString(const std::string &data, int offset);
49     static std::string DiallingNumberStringFieldConvertToString(
50         std::shared_ptr<unsigned char> array, int offset, int length, int offPos);
51     static std::shared_ptr<char16_t> CharsConvertToChar16(
52         const unsigned char *charBytes, int charBytesLen, int &outChar16Len, bool bigEndian);
53     static std::string Trim(std::string& str);
54 
55 private:
56     static std::string UcsCodeConvertToString(
57         std::shared_ptr<unsigned char> array, int offset, int length, int offPos);
58 };
59 } // namespace Telephony
60 } // namespace OHOS
61 #endif // OHOS_SIM_UTILS_H