struct icu_buf_utf8 * src8,
UErrorCode * status)
{
- printf("icu_utf16_from_utf8 - needs correcting, see icu_utf16_from_utf8_cstr\n");
-
- u_strFromUTF8(dest16->utf16, dest16->utf16_cap, &(dest16->utf16_len),
+ int32_t utf16_len = 0;
+
+ u_strFromUTF8(dest16->utf16, dest16->utf16_cap,
+ &utf16_len,
(const char *) src8->utf8, src8->utf8_len, status);
-
+
// check for buffer overflow, resize and retry
- if (dest16->utf16_len > dest16->utf16_cap){
- printf("icu_utf16_from_utf8 need resize\n");
- icu_buf_utf16_resize(dest16, dest16->utf16_len * 2);
+ if (*status == U_BUFFER_OVERFLOW_ERROR
+ //|| dest16->utf16_len > dest16->utf16_cap
+ ){
+ icu_buf_utf16_resize(dest16, utf16_len * 2);
*status = U_ZERO_ERROR;
- u_strFromUTF8(dest16->utf16, dest16->utf16_cap, &(dest16->utf16_len),
- (const char*) src8->utf8, src8->utf8_len, status);
+ u_strFromUTF8(dest16->utf16, dest16->utf16_cap,
+ &utf16_len,
+ (const char *) src8->utf8, src8->utf8_len, status);
}
+ if (*status != U_BUFFER_OVERFLOW_ERROR
+ && utf16_len < dest16->utf16_cap)
+ dest16->utf16_len = utf16_len;
+ else {
+ dest16->utf16[0] = (UChar) 0;
+ dest16->utf16_len = 0;
+ }
+
return *status;
};
u_strFromUTF8(dest16->utf16, dest16->utf16_cap,
&utf16_len,
- //&(dest16->utf16_len),
src8cstr, src8cstr_len, status);
// check for buffer overflow, resize and retry
*status = U_ZERO_ERROR;
u_strFromUTF8(dest16->utf16, dest16->utf16_cap,
&utf16_len,
- //&(dest16->utf16_len),
src8cstr, src8cstr_len, status);
}