1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2009 Index Data
3 * See the file LICENSE for details.
8 * \brief UTF-16 string utilities for ICU
16 #include <yaz/xmalloc.h>
18 #include <yaz/icu_I18N.h>
26 #include <unicode/ustring.h> /* some more string fcns*/
27 #include <unicode/uchar.h> /* char names */
29 struct icu_buf_utf16 * icu_buf_utf16_create(size_t capacity)
31 struct icu_buf_utf16 * buf16
32 = (struct icu_buf_utf16 *) xmalloc(sizeof(struct icu_buf_utf16));
40 buf16->utf16 = (UChar *) xmalloc(sizeof(UChar) * capacity);
41 buf16->utf16[0] = (UChar) 0;
42 buf16->utf16_cap = capacity;
47 struct icu_buf_utf16 * icu_buf_utf16_clear(struct icu_buf_utf16 * buf16)
52 buf16->utf16[0] = (UChar) 0;
58 struct icu_buf_utf16 * icu_buf_utf16_resize(struct icu_buf_utf16 * buf16,
66 if (0 == buf16->utf16)
67 buf16->utf16 = (UChar *) xmalloc(sizeof(UChar) * capacity);
70 = (UChar *) xrealloc(buf16->utf16, sizeof(UChar) * capacity);
72 icu_buf_utf16_clear(buf16);
73 buf16->utf16_cap = capacity;
87 struct icu_buf_utf16 * icu_buf_utf16_copy(struct icu_buf_utf16 * dest16,
88 const struct icu_buf_utf16 * src16)
90 if (!dest16 || !src16 || dest16 == src16)
93 if (dest16->utf16_cap < src16->utf16_len)
94 icu_buf_utf16_resize(dest16, src16->utf16_len * 2);
96 u_strncpy(dest16->utf16, src16->utf16, src16->utf16_len);
97 dest16->utf16_len = src16->utf16_len;
102 void icu_buf_utf16_destroy(struct icu_buf_utf16 * buf16)
110 #endif /* YAZ_HAVE_ICU */
115 * c-file-style: "Stroustrup"
116 * indent-tabs-mode: nil
118 * vim: shiftwidth=4 tabstop=8 expandtab