xrtMailCharsetSupported
判断字符集名称是否属于内置的小型转换集合(UTF-8、ASCII、Latin-1、Windows-1252)。
XRT_API bool xrtMailCharsetSupported(xstrview Charset);
| 参数 | 说明 |
|---|---|
| xstrview Charset | 字符集名称;大小写不敏感 |
返回:受支持返回 true;否则 false。
示例已编译验证
printf("utf8=%d latin1=%d big5=%d\n",
xrtMailCharsetSupported(SV("UTF-8")) ? 1 : 0,
xrtMailCharsetSupported(SV("ISO-8859-1")) ? 1 : 0,
xrtMailCharsetSupported(SV("BIG5")) ? 1 : 0);
输出
utf8=1 latin1=1 big5=0xrtMailCharsetToUtf8
把 UTF-8、ASCII、Latin-1 或 Windows-1252 字节转换成 UTF-8。
XRT_API str xrtMailCharsetToUtf8( xstrview Charset, xbytesview Source, size_t* pOutputSize );
| 参数 | 说明 |
|---|---|
| xstrview Charset | 源字符集名称 |
| xbytesview Source | 源字节视图 |
| size_t* pOutputSize | 出:结果字节数(不含结尾零);可传 NULL |
返回:成功返回由 xrtFree 释放的 UTF-8 文本;字符集不支持或分配失败返回 NULL。
示例已编译验证
unsigned char src[4] = { 'c', 'a', 'f', 0xE9 }; /* café */
size_t n = 0;
str out = xrtMailCharsetToUtf8(SV("ISO-8859-1"),
(xbytesview){ src, 4 }, &n);
printf("%s len=%u\n", out, (unsigned)n);
xrtFree(out);
输出
café len=5xrtMailCharsetToUtf8Write
把转换结果写入调用方缓冲区;查询模式使用空输出和零容量,实际容量必须包含末尾零字节。
XRT_API bool xrtMailCharsetToUtf8Write( xstrview Charset, xbytesview Source, char* sOutput, size_t iCapacity, size_t* pOutputSize );
| 参数 | 说明 |
|---|---|
| xstrview Charset | 源字符集名称 |
| xbytesview Source | 源字节视图 |
| char* sOutput | 出:目标缓冲区;查询模式传 NULL |
| size_t iCapacity | 目标容量(含结尾零) |
| size_t* pOutputSize | 出:不含结尾零的结果长度 |
返回:成功返回 true;容量不足或字符集不支持返回 false。
示例已编译验证
unsigned char src[4] = { 'c', 'a', 'f', 0xE9 };
char buf[16];
size_t n = 0;
bool ok = xrtMailCharsetToUtf8Write(SV("ISO-8859-1"),
(xbytesview){ src, 4 }, buf, sizeof(buf), &n);
printf("ok=%d %s len=%u\n", ok ? 1 : 0, buf, (unsigned)n);
输出
ok=1 café len=5