52 |
* Convert character value to UTF-8 * |
* Convert character value to UTF-8 * |
53 |
*************************************************/ |
*************************************************/ |
54 |
|
|
55 |
/* This function takes an integer value in the range 0 - 0x7fffffff |
/* This function takes an integer value in the range 0 - 0x10ffff |
56 |
and encodes it as a UTF-8 character in 0 to 6 bytes. |
and encodes it as a UTF-8 character in 1 to 6 pcre_uchars. |
57 |
|
|
58 |
Arguments: |
Arguments: |
59 |
cvalue the character value |
cvalue the character value |
60 |
buffer pointer to buffer for result - at least 6 bytes long |
buffer pointer to buffer for result - at least 6 pcre_uchars long |
61 |
|
|
62 |
Returns: number of characters placed in the buffer |
Returns: number of characters placed in the buffer |
63 |
*/ |
*/ |
64 |
|
|
65 |
int |
int |
66 |
PRIV(ord2utf8)(int cvalue, pcre_uint8 *buffer) |
PRIV(ord2utf)(pcre_uint32 cvalue, pcre_uchar *buffer) |
67 |
{ |
{ |
68 |
#ifdef SUPPORT_UTF8 |
#ifdef SUPPORT_UTF8 |
69 |
|
|
70 |
register int i, j; |
register int i, j; |
71 |
|
|
72 |
|
/* Checking invalid cvalue character, encoded as invalid UTF-16 character. |
73 |
|
Should never happen in practice. */ |
74 |
|
if ((cvalue & 0xf800) == 0xd800 || cvalue >= 0x110000) |
75 |
|
cvalue = 0xfffe; |
76 |
|
|
77 |
for (i = 0; i < PRIV(utf8_table1_size); i++) |
for (i = 0; i < PRIV(utf8_table1_size); i++) |
78 |
if (cvalue <= PRIV(utf8_table1)[i]) break; |
if (cvalue <= PRIV(utf8_table1)[i]) break; |
79 |
buffer += i; |
buffer += i; |
84 |
} |
} |
85 |
*buffer = PRIV(utf8_table2)[i] | cvalue; |
*buffer = PRIV(utf8_table2)[i] | cvalue; |
86 |
return i + 1; |
return i + 1; |
87 |
|
|
88 |
#else |
#else |
89 |
|
|
90 |
(void)(cvalue); /* Keep compiler happy; this function won't ever be */ |
(void)(cvalue); /* Keep compiler happy; this function won't ever be */ |
91 |
(void)(buffer); /* called when SUPPORT_UTF8 is not defined. */ |
(void)(buffer); /* called when SUPPORT_UTF8 is not defined. */ |
92 |
return 0; |
return 0; |
93 |
|
|
94 |
#endif |
#endif |
95 |
} |
} |
96 |
|
|