| 1 |
#include <stdint.h> |
| 2 |
#include <wchar.h> |
| 3 |
#include <uchar.h> |
| 4 |
#include <stdlib.h> |
| 5 |
|
| 6 |
static struct { |
| 7 |
char c8; |
| 8 |
char16_t c16; |
| 9 |
char32_t c32; |
| 10 |
|
| 11 |
const char *s8; |
| 12 |
const char16_t *s16; |
| 13 |
const char32_t *s32; |
| 14 |
} strings = { |
| 15 |
's', u't', U'p', |
| 16 |
// various encodings of "stapΑΩ☺😈" |
| 17 |
u8"stap\u0391\u03A9\u263A\U0001F608", |
| 18 |
u"stap\u0391\u03A9\u263A\U0001F608", |
| 19 |
U"stap\u0391\u03A9\u263A\U0001F608", |
| 20 |
}; |
| 21 |
|
| 22 |
mbstate_t mbs; |
| 23 |
|
| 24 |
int main() |
| 25 |
{ |
| 26 |
const char16_t* pt = strings.s16; |
| 27 |
char buffer [MB_CUR_MAX]; |
| 28 |
size_t length; |
| 29 |
|
| 30 |
mbrlen (NULL,0,&mbs); /* initialize mbs */ |
| 31 |
|
| 32 |
while (*pt) { |
| 33 |
length = c16rtomb(buffer,*pt,&mbs); |
| 34 |
if ((length==0)||(length>MB_CUR_MAX)) break; |
| 35 |
++pt; |
| 36 |
} |
| 37 |
|
| 38 |
main_return: |
| 39 |
return 0; |
| 40 |
} |