/* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2009 Index Data
+ * Copyright (C) 1995-2012 Index Data
* See the file LICENSE for details.
*/
struct icu_buf_utf8 *icu_buf_utf8_create(size_t capacity)
{
- struct icu_buf_utf8 * buf8
+ struct icu_buf_utf8 * buf8
= (struct icu_buf_utf8 *) xmalloc(sizeof(struct icu_buf_utf8));
buf8->utf8 = 0;
if (!buf8)
return 0;
- if (capacity > 0)
+ if (capacity > 0)
{
if (0 == buf8->utf8)
buf8->utf8 = (uint8_t *) xmalloc(sizeof(uint8_t) * capacity);
else
- buf8->utf8
+ buf8->utf8
= (uint8_t *) xrealloc(buf8->utf8, sizeof(uint8_t) * capacity);
-
+
buf8->utf8_cap = capacity;
- }
- else {
+ }
+ else
+ {
xfree(buf8->utf8);
buf8->utf8 = 0;
buf8->utf8_len = 0;
buf8->utf8_cap = 0;
}
-
+
return buf8;
}
*status = U_ZERO_ERROR;
src8cstr_len = strlen(src8cstr);
-
+
u_strFromUTF8(dest16->utf16, dest16->utf16_cap,
&utf16_len,
src8cstr, src8cstr_len, status);
-
+
/* check for buffer overflow, resize and retry */
if (*status == U_BUFFER_OVERFLOW_ERROR)
{
src8cstr, src8cstr_len, status);
}
- if (U_SUCCESS(*status)
- && utf16_len <= dest16->utf16_cap)
+ if (U_SUCCESS(*status) && utf16_len <= dest16->utf16_cap)
dest16->utf16_len = utf16_len;
- else
+ else
icu_buf_utf16_clear(dest16);
-
+
return *status;
}
UErrorCode * status)
{
int32_t utf8_len = 0;
-
+
u_strToUTF8((char *) dest8->utf8, dest8->utf8_cap,
&utf8_len,
src16->utf16, src16->utf16_len, status);
-
+
/* check for buffer overflow, resize and retry */
if (*status == U_BUFFER_OVERFLOW_ERROR)
{
src16->utf16, src16->utf16_len, status);
}
- if (U_SUCCESS(*status)
- && utf8_len <= dest8->utf8_cap)
+ if (U_SUCCESS(*status) && utf8_len <= dest8->utf8_cap)
dest8->utf8_len = utf8_len;
- else
+ else
icu_buf_utf8_clear(dest8);
-
+
return *status;
}