// utf8 to LENDIAN unicode static status_t _utf8_to_lendian_unicode( const char *src, size_t *srcLen, char *dst, size_t *dstLen) { size_t srcLimit = *srcLen; size_t dstLimit = *dstLen - 1; size_t srcCount = 0; size_t dstCount = 0; status_t status = B_ERROR; while ((srcCount < srcLimit) && (dstCount < dstLimit)) { uint16 unicode; uint16 *UNICODE = &unicode; uchar *UTF8 = (uchar *)src + srcCount; int err_flag; if ((srcCount + utf8_char_len(src[srcCount])) > srcLimit) break; utf8_to_u_hostendian(UTF8, UNICODE, err_flag); if (err_flag == 1) return EINVAL; unicode = B_HOST_TO_LENDIAN_INT16(unicode); if ((dstCount + 1) > dstLimit) { status = B_BUFFER_OVERFLOW; break; } dst[dstCount++] = unicode & 0xFF; dst[dstCount++] = unicode >> 8; srcCount += UTF8 - ((uchar *)(src + srcCount)); status = B_OK; } *srcLen = srcCount; *dstLen = dstCount; return status; }
// utf8 to LENDIAN unicode static status_t _utf8_to_lendian_unicode( const char *src, int32 *srcLen, char *dst, uint32 *dstLen) { int32 srcLimit = *srcLen; int32 dstLimit = *dstLen - 1; int32 srcCount = 0; int32 dstCount = 0; while ((srcCount < srcLimit) && (dstCount < dstLimit)) { uint16 unicode; uint16 *UNICODE = &unicode; uchar *UTF8 = (uchar *)src + srcCount; int err_flag; if ((srcCount + utf8_char_len(src[srcCount])) > srcLimit) break; utf8_to_u_hostendian(UTF8, UNICODE, err_flag); if(err_flag == 1) return EINVAL; unicode = B_HOST_TO_LENDIAN_INT16(unicode); dst[dstCount++] = unicode & 0xFF; dst[dstCount++] = unicode >> 8; srcCount += UTF8 - ((uchar *)(src + srcCount)); } *srcLen = srcCount; *dstLen = dstCount; return ((dstCount > 0) ? B_NO_ERROR : B_ERROR); }