Skip to content

Commit

Permalink
smsops: fix utf8 to ucs2 conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
herlesupreeth authored and miconda committed Dec 28, 2023
1 parent 75de09f commit 61d91d7
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/modules/smsops/smsops_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -606,17 +606,17 @@ int utf8_to_ucs2(char *utf8, int utf8_len, char *ucs2, int buffer_len)
} else if((utf8_char & 0xF0) == 0xE0) {
// Three-byte UTF-8 character
codepoint = ((utf8_char & 0x0F) << 12)
| (((unsigned char)utf8[utf8_index + 1] & 0x3F) << 6)
| ((unsigned char)utf8[utf8_index + 2] & 0x3F);
| (((unsigned char)utf8[utf8_index] & 0x3F) << 6)
| ((unsigned char)utf8[utf8_index + 1] & 0x3F);
utf8_index += 2;
tmp_buff[ucs2_index++] = (uint8_t)(codepoint >> 8);
tmp_buff[ucs2_index++] = (uint8_t)(codepoint & 0xFF);
} else if((utf8_char & 0xF8) == 0xF0) {
// Four-byte UTF-8 character
codepoint = ((utf8_char & 0x07) << 18)
| (((unsigned char)utf8[utf8_index + 1] & 0x3F) << 12)
| (((unsigned char)utf8[utf8_index + 2] & 0x3F) << 6)
| ((unsigned char)utf8[utf8_index + 3] & 0x3F);
| (((unsigned char)utf8[utf8_index] & 0x3F) << 12)
| (((unsigned char)utf8[utf8_index + 1] & 0x3F) << 6)
| ((unsigned char)utf8[utf8_index + 2] & 0x3F);
utf8_index += 3;
// Convert to UCS-2 surrogate pair
codepoint -= 0x10000;
Expand Down

0 comments on commit 61d91d7

Please sign in to comment.