b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 1 | // |
| 2 | // Created by hitmoon on 15-12-10. |
| 3 | // |
| 4 | |
| 5 | |
| 6 | struct map_node { |
| 7 | unsigned short key; |
| 8 | unsigned short value; |
| 9 | }; |
| 10 | |
| 11 | |
| 12 | #define map_size(map) (sizeof(map) / sizeof(struct map_node)) |
| 13 | |
| 14 | |
| 15 | // Unicode编码到GSM编码转换 |
| 16 | struct map_node UCS2ToBIT7[] = { |
| 17 | {0x000C, 0x1B0A}, |
| 18 | {0x0024, 0x0002}, |
| 19 | {0x0040, 0x0000}, |
| 20 | {0x005B, 0x1B3C}, |
| 21 | {0x005C, 0x1B2F}, |
| 22 | {0x005D, 0x1B3E}, |
| 23 | {0x005E, 0x1B14}, |
| 24 | {0x005F, 0x0011}, |
| 25 | {0x007B, 0x1B28}, |
| 26 | {0x007C, 0x1B40}, |
| 27 | {0x007D, 0x1B29}, |
| 28 | {0x007E, 0x1B3D}, |
| 29 | {0x00A0, 0x001B}, |
| 30 | {0x00A1, 0x0040}, |
| 31 | {0x00A3, 0x0001}, |
| 32 | {0x00A4, 0x0024}, |
| 33 | {0x00A5, 0x0003}, |
| 34 | {0x00A7, 0x005F}, |
| 35 | {0x00BF, 0x0060}, |
| 36 | {0x00C4, 0x005B}, |
| 37 | {0x00C5, 0x000E}, |
| 38 | {0x00C6, 0x001C}, |
| 39 | {0x00C9, 0x001F}, |
| 40 | {0x00D1, 0x005D}, |
| 41 | {0x00D6, 0x005C}, |
| 42 | {0x00D8, 0x000B}, |
| 43 | {0x00DC, 0x005E}, |
| 44 | {0x00DF, 0x001E}, |
| 45 | {0x00E0, 0x007F}, |
| 46 | {0x00E4, 0x007B}, |
| 47 | {0x00E5, 0x000F}, |
| 48 | {0x00E6, 0x001D}, |
| 49 | {0x00E7, 0x0009}, |
| 50 | {0x00E8, 0x0004}, |
| 51 | {0x00E9, 0x0005}, |
| 52 | {0x00EC, 0x0007}, |
| 53 | {0x00F1, 0x007D}, |
| 54 | {0x00F2, 0x0008}, |
| 55 | {0x00F6, 0x007C}, |
| 56 | {0x00F8, 0x000C}, |
| 57 | {0x00F9, 0x0006}, |
| 58 | {0x00FC, 0x007E}, |
| 59 | {0x0393, 0x0013}, |
| 60 | {0x0394, 0x0010}, |
| 61 | {0x0398, 0x0019}, |
| 62 | {0x039B, 0x0014}, |
| 63 | {0x039E, 0x001A}, |
| 64 | {0x03A0, 0x0016}, |
| 65 | {0x03A3, 0x0018}, |
| 66 | {0x03A6, 0x0012}, |
| 67 | {0x03A8, 0x0017}, |
| 68 | {0x03A9, 0x0015}, |
| 69 | {0x20AC, 0x1B65} |
| 70 | }; |
| 71 | |
| 72 | // GSM编码到Unicode编码转换 |
| 73 | struct map_node BIT7ToUCS2[] = { |
| 74 | {0x0000, 0x0040}, |
| 75 | {0x0001, 0x00A3}, |
| 76 | {0x0002, 0x0024}, |
| 77 | {0x0003, 0x00A5}, |
| 78 | {0x0004, 0x00E8}, |
| 79 | {0x0005, 0x00E9}, |
| 80 | {0x0006, 0x00F9}, |
| 81 | {0x0007, 0x00EC}, |
| 82 | {0x0008, 0x00F2}, |
| 83 | {0x0009, 0x00E7}, |
| 84 | {0x000B, 0x00D8}, |
| 85 | {0x000C, 0x00F8}, |
| 86 | {0x000E, 0x00C5}, |
| 87 | {0x000F, 0x00E5}, |
| 88 | {0x0010, 0x0394}, |
| 89 | {0x0011, 0x005F}, |
| 90 | {0x0012, 0x03A6}, |
| 91 | {0x0013, 0x0393}, |
| 92 | {0x0014, 0x039B}, |
| 93 | {0x0015, 0x03A9}, |
| 94 | {0x0016, 0x03A0}, |
| 95 | {0x0017, 0x03A8}, |
| 96 | {0x0018, 0x03A3}, |
| 97 | {0x0019, 0x0398}, |
| 98 | {0x001A, 0x039E}, |
| 99 | {0x001B, 0x00A0}, |
| 100 | {0x001C, 0x00C6}, |
| 101 | {0x001D, 0x00E6}, |
| 102 | {0x001E, 0x00DF}, |
| 103 | {0x001F, 0x00C9}, |
| 104 | {0x0024, 0x00A4}, |
| 105 | {0x0040, 0x00A1}, |
| 106 | {0x005B, 0x00C4}, |
| 107 | {0x005C, 0x00D6}, |
| 108 | {0x005D, 0x00D1}, |
| 109 | {0x005E, 0x00DC}, |
| 110 | {0x005F, 0x00A7}, |
| 111 | {0x0060, 0x00BF}, |
| 112 | {0x007B, 0x00E4}, |
| 113 | {0x007C, 0x00F6}, |
| 114 | {0x007D, 0x00F1}, |
| 115 | {0x007E, 0x00FC}, |
| 116 | {0x007F, 0x00E0} |
| 117 | }; |
| 118 | // GSM编码转义序列到Unicode编码转换 |
| 119 | struct map_node BIT7EToUCS2[] = { |
| 120 | {0x000A, 0x000C}, |
| 121 | {0x0014, 0x005E}, |
| 122 | {0x0028, 0x007B}, |
| 123 | {0x0029, 0x007D}, |
| 124 | {0x002F, 0x005C}, |
| 125 | {0x003C, 0x005B}, |
| 126 | {0x003D, 0x007E}, |
| 127 | {0x003E, 0x005D}, |
| 128 | {0x0040, 0x007C}, |
| 129 | {0x0065, 0x20AC} |
| 130 | }; |
| 131 | |
| 132 | // map 中查询键值 |
| 133 | int32_t map_get_value(struct map_node *map, unsigned int size, unsigned short key) { |
| 134 | int i = 0; |
| 135 | for (i = 0; i < size; i++) { |
| 136 | if (map[i].key == key) |
| 137 | return map[i].value; |
| 138 | } |
| 139 | return -1; |
| 140 | } |