14 #ifdef UTF_ENDIAN_H_VERSION
15 #define __ALT(x, y) x ## y
16 #define _ALT(x, y) __ALT(x, y)
17 #define ALT(x) _ALT(x, UTF_ENDIAN_H_VERSION)
20 static transcript_error_t ALT(put_utf16)(uint_fast32_t codepoint,
char **outbuf,
const char *outbuflimit) {
21 CHECK_CODEPOINT_RANGE();
22 if (codepoint < UINT32_C(0xffff)) {
23 CHECK_OUTBYTESLEFT(2);
24 ALT(put16)(codepoint, *(
unsigned char **) outbuf);
27 CHECK_OUTBYTESLEFT(4);
28 codepoint -= UINT32_C(0x10000);
29 ALT(put16)(UINT32_C(0xd800) + (codepoint >> 10), *(
unsigned char **) outbuf);
30 ALT(put16)(UINT32_C(0xdc00) + (codepoint & 0x3ff), (*(
unsigned char **) outbuf) + 2);
37 static transcript_error_t ALT(put_utf32)(uint_fast32_t codepoint,
char **outbuf,
const char *outbuflimit) {
38 CHECK_CODEPOINT_RANGE();
40 CHECK_OUTBYTESLEFT(4);
41 ALT(put32)(codepoint, *(
unsigned char **) outbuf);
47 static uint_fast32_t ALT(get_utf16)(
const char **inbuf,
const char *inbuflimit, bool_t skip) {
48 uint_fast32_t codepoint, masked_codepoint;
50 if ((*inbuf) + 2 > inbuflimit)
51 return TRANSCRIPT_UTF_INCOMPLETE;
53 codepoint = ALT(get16)(*(
const unsigned char **) inbuf);
54 masked_codepoint = codepoint & UINT32_C(0xfc00);
56 if (masked_codepoint == UINT32_C(0xd800)) {
57 uint_fast32_t next_codepoint;
59 if ((*inbuf) + 4 > inbuflimit)
60 return TRANSCRIPT_UTF_INCOMPLETE;
62 next_codepoint = ALT(get16)((*(
const unsigned char **) inbuf) + 2);
63 if ((next_codepoint & UINT32_C(0xfc00)) != UINT32_C(0xdc00)) {
66 return TRANSCRIPT_UTF_ILLEGAL;
72 codepoint -= UINT32_C(0xd800);
74 codepoint += next_codepoint - UINT32_C(0xdc00);
75 codepoint += UINT32_C(0x10000);
78 CHECK_CODEPOINT_ILLEGAL();
84 if (masked_codepoint == UINT32_C(0xdc00)) {
86 return TRANSCRIPT_UTF_ILLEGAL;
88 CHECK_CODEPOINT_ILLEGAL();
96 static uint_fast32_t ALT(get_utf32)(
const char **inbuf,
const char *inbuflimit, bool_t skip) {
99 if ((*inbuf) + 4 > inbuflimit)
100 return TRANSCRIPT_UTF_INCOMPLETE;
102 memcpy(&codepoint, *inbuf, 4);
103 codepoint = ALT(get32)(*(
const unsigned char **) inbuf);
105 CHECK_CODEPOINT_ILLEGAL();
106 CHECK_CODEPOINT_SURROGATES();
transcript_error_t
Error values.
Definition: transcript.h:91
All OK.
Definition: transcript.h:92