Rizin
unix-like reverse engineering framework and cli tools
rz_utf16.h File Reference
#include "rz_utf8.h"

Go to the source code of this file.

Functions

RZ_API int rz_utf16_decode (const ut8 *ptr, int ptrlen, RzRune *ch, bool bigendian)
 
RZ_API int rz_utf16le_decode (const ut8 *ptr, int ptrlen, RzRune *ch)
 
RZ_API int rz_utf16be_decode (const ut8 *ptr, int ptrlen, RzRune *ch)
 
RZ_API int rz_utf16le_encode (ut8 *ptr, RzRune ch)
 

Function Documentation

◆ rz_utf16_decode()

RZ_API int rz_utf16_decode ( const ut8 ptr,
int  ptrlen,
RzRune ch,
bool  bigendian 
)

Definition at line 8 of file utf16.c.

8  {
9  if (ptrlen < 1) {
10  return 0;
11  }
12  int high = bigendian ? 0 : 1;
13  int low = bigendian ? 1 : 0;
14  if (ptrlen > 3 && (ptr[high] & 0xdc) == 0xd8 && (ptr[high + 2] & 0xdc) == 0xdc) {
15  if (ch) {
16  *ch = ((ptr[high] & 3) << 24 | ptr[low] << 16 | (ptr[high + 2] & 3) << 8 | ptr[low + 2]) + 0x10000;
17  }
18  return 4;
19  }
20  if (ptrlen > 1 && ptr[high]) {
21  if (ch) {
22  *ch = ptr[high] << 8 | ptr[low];
23  }
24  return 2;
25  }
26  if (ptrlen > 1) {
27  if (ch) {
28  *ch = (ut32)ptr[low];
29  }
30  return 1;
31  }
32  return 0;
33 }
uint32_t ut32

Referenced by rz_str_escape_utf(), rz_utf16be_decode(), and rz_utf16le_decode().

◆ rz_utf16be_decode()

RZ_API int rz_utf16be_decode ( const ut8 ptr,
int  ptrlen,
RzRune ch 
)

Definition at line 41 of file utf16.c.

41  {
42  return rz_utf16_decode(ptr, ptrlen, ch, true);
43 }
RZ_API int rz_utf16_decode(const ut8 *ptr, int ptrlen, RzRune *ch, bool bigendian)
Definition: utf16.c:8

References rz_utf16_decode().

Referenced by process_one_string(), and rz_str_stringify_raw_buffer().

◆ rz_utf16le_decode()

RZ_API int rz_utf16le_decode ( const ut8 ptr,
int  ptrlen,
RzRune ch 
)

Definition at line 36 of file utf16.c.

36  {
37  return rz_utf16_decode(ptr, ptrlen, ch, false);
38 }

References rz_utf16_decode().

Referenced by process_one_string(), and rz_str_stringify_raw_buffer().

◆ rz_utf16le_encode()

RZ_API int rz_utf16le_encode ( ut8 ptr,
RzRune  ch 
)

Definition at line 46 of file utf16.c.

46  {
47  if (ch < 0x10000) {
48  ptr[0] = ch & 0xff;
49  ptr[1] = ch >> 8 & 0xff;
50  return 2;
51  }
52  if (ch < 0x110000) {
53  ch -= 0x10000;
54  RzRune high = 0xd800 + (ch >> 10 & 0x3ff);
55  RzRune low = 0xdc00 + (ch & 0x3ff);
56  ptr[0] = high & 0xff;
57  ptr[1] = high >> 8 & 0xff;
58  ptr[2] = low & 0xff;
59  ptr[3] = low >> 8 & 0xff;
60  return 4;
61  }
62  return 0;
63 }
ut32 RzRune
Definition: rz_utf8.h:13

Referenced by rz_search_keyword_new_wide().