示例#1
0
// converts LENDIAN unicode to utf8
static status_t
_lendian_unicode_to_utf8(
	const char *src,
	size_t *srcLen,
	char *dst,
	size_t *dstLen)
{
	size_t srcLimit = *srcLen;
	size_t dstLimit = *dstLen;
	size_t srcCount = 0;
	size_t dstCount = 0;
	status_t status = B_ERROR;

	for (srcCount = 0; srcCount < srcLimit; srcCount += 2) {
		uint16  *UNICODE = (uint16 *)&src[srcCount];
		if (*UNICODE == 0)
			break;
		uchar	utf8[4];
		uchar	*UTF8 = utf8;
		int32 utf8Len;
		int32 j;

		u_lendian_to_utf8(UTF8, UNICODE);

		utf8Len = UTF8 - utf8;
		if ((dstCount + utf8Len) > dstLimit) {
			status = B_BUFFER_OVERFLOW;
			break;
		}

		for (j = 0; j < utf8Len; j++)
			dst[dstCount + j] = utf8[j];
		dstCount += utf8Len;
		status = B_OK;
	}

	*srcLen = srcCount;
	*dstLen = dstCount;
	dst[dstCount] = '\0';

	return status;
}
示例#2
0
// converts LENDIAN unicode to utf8
static status_t
_lendian_unicode_to_utf8(
	const char *src,
	int32 *srcLen,
	char *dst,
	uint32 *dstLen)
{
	int32 srcLimit = *srcLen;
	int32 dstLimit = *dstLen;
	int32 srcCount = 0;
	int32 dstCount = 0;

	for (srcCount = 0; srcCount < srcLimit; srcCount += 2) {
		uint16  *UNICODE = (uint16 *)&src[srcCount];
		if (*UNICODE == 0)
			break;
		uchar	utf8[4];
		uchar	*UTF8 = utf8;
		int32 utf8Len;
		int32 j;

		u_lendian_to_utf8(UTF8, UNICODE);

		utf8Len = UTF8 - utf8;
		if ((dstCount + utf8Len) > dstLimit)
			break;

		for (j = 0; j < utf8Len; j++)
			dst[dstCount + j] = utf8[j];
		dstCount += utf8Len;
	}

	*srcLen = srcCount;
	*dstLen = dstCount;
	dst[dstCount] = '\0';
	
	return ((dstCount > 0) ? B_NO_ERROR : B_ERROR);
}