* Copyright (C) 1995-2007, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: icu_I18N.c,v 1.16 2007-11-08 17:15:13 adam Exp $
+ * $Id: icu_I18N.c,v 1.17 2007-11-08 17:20:32 adam Exp $
*/
#if HAVE_CONFIG_H
#include <yaz/timing.h>
#endif
+#include <yaz/xmalloc.h>
#if YAZ_HAVE_ICU
#include <yaz/icu_I18N.h>
struct icu_buf_utf16 * icu_buf_utf16_create(size_t capacity)
{
struct icu_buf_utf16 * buf16
- = (struct icu_buf_utf16 *) malloc(sizeof(struct icu_buf_utf16));
+ = (struct icu_buf_utf16 *) xmalloc(sizeof(struct icu_buf_utf16));
buf16->utf16 = 0;
buf16->utf16_len = 0;
buf16->utf16_cap = 0;
if (capacity > 0){
- buf16->utf16 = (UChar *) malloc(sizeof(UChar) * capacity);
+ buf16->utf16 = (UChar *) xmalloc(sizeof(UChar) * capacity);
buf16->utf16[0] = (UChar) 0;
buf16->utf16_cap = capacity;
}
if (capacity > 0){
if (0 == buf16->utf16)
- buf16->utf16 = (UChar *) malloc(sizeof(UChar) * capacity);
+ buf16->utf16 = (UChar *) xmalloc(sizeof(UChar) * capacity);
else
buf16->utf16
- = (UChar *) realloc(buf16->utf16, sizeof(UChar) * capacity);
+ = (UChar *) xrealloc(buf16->utf16, sizeof(UChar) * capacity);
icu_buf_utf16_clear(buf16);
buf16->utf16_cap = capacity;
}
else {
- if (buf16->utf16)
- free(buf16->utf16);
+ xfree(buf16->utf16);
buf16->utf16 = 0;
buf16->utf16_len = 0;
buf16->utf16_cap = 0;
void icu_buf_utf16_destroy(struct icu_buf_utf16 * buf16)
{
- if (buf16){
- if (buf16->utf16)
- free(buf16->utf16);
- free(buf16);
- }
+ if (buf16)
+ xfree(buf16->utf16);
+ xfree(buf16);
}
-
-
-
struct icu_buf_utf8 * icu_buf_utf8_create(size_t capacity)
{
struct icu_buf_utf8 * buf8
- = (struct icu_buf_utf8 *) malloc(sizeof(struct icu_buf_utf8));
+ = (struct icu_buf_utf8 *) xmalloc(sizeof(struct icu_buf_utf8));
buf8->utf8 = 0;
buf8->utf8_len = 0;
buf8->utf8_cap = 0;
if (capacity > 0){
- buf8->utf8 = (uint8_t *) malloc(sizeof(uint8_t) * capacity);
+ buf8->utf8 = (uint8_t *) xmalloc(sizeof(uint8_t) * capacity);
buf8->utf8[0] = (uint8_t) 0;
buf8->utf8_cap = capacity;
}
if (capacity > 0){
if (0 == buf8->utf8)
- buf8->utf8 = (uint8_t *) malloc(sizeof(uint8_t) * capacity);
+ buf8->utf8 = (uint8_t *) xmalloc(sizeof(uint8_t) * capacity);
else
buf8->utf8
- = (uint8_t *) realloc(buf8->utf8, sizeof(uint8_t) * capacity);
+ = (uint8_t *) xrealloc(buf8->utf8, sizeof(uint8_t) * capacity);
icu_buf_utf8_clear(buf8);
buf8->utf8_cap = capacity;
}
else {
- if (buf8->utf8)
- free(buf8->utf8);
+ xfree(buf8->utf8);
buf8->utf8 = 0;
buf8->utf8_len = 0;
buf8->utf8_cap = 0;
void icu_buf_utf8_destroy(struct icu_buf_utf8 * buf8)
{
- if (buf8){
- if (buf8->utf8)
- free(buf8->utf8);
- free(buf8);
- }
+ if (buf8)
+ xfree(buf8->utf8);
+ xfree(buf8);
}
struct icu_casemap * icu_casemap_create(char action, UErrorCode *status)
{
struct icu_casemap * casemap
- = (struct icu_casemap *) malloc(sizeof(struct icu_casemap));
+ = (struct icu_casemap *) xmalloc(sizeof(struct icu_casemap));
casemap->action = action;
switch(casemap->action) {
void icu_casemap_destroy(struct icu_casemap * casemap)
{
- if (casemap)
- free(casemap);
+ xfree(casemap);
}
UErrorCode *status)
{
struct icu_tokenizer * tokenizer
- = (struct icu_tokenizer *) malloc(sizeof(struct icu_tokenizer));
+ = (struct icu_tokenizer *) xmalloc(sizeof(struct icu_tokenizer));
tokenizer->action = action;
tokenizer->bi = 0;
if (tokenizer) {
if (tokenizer->bi)
ubrk_close(tokenizer->bi);
- free(tokenizer);
+ xfree(tokenizer);
}
}
{
struct icu_normalizer * normalizer
- = (struct icu_normalizer *) malloc(sizeof(struct icu_normalizer));
+ = (struct icu_normalizer *) xmalloc(sizeof(struct icu_normalizer));
normalizer->action = action;
normalizer->trans = 0;
icu_buf_utf16_destroy(normalizer->rules16);
if (normalizer->trans)
utrans_close(normalizer->trans);
- free(normalizer);
+ xfree(normalizer);
}
}
if(!chain || !type || !rule)
return 0;
- step = (struct icu_chain_step *) malloc(sizeof(struct icu_chain_step));
+ step = (struct icu_chain_step *) xmalloc(sizeof(struct icu_chain_step));
step->type = type;
default:
break;
}
- free(step);
+ xfree(step);
}
{
struct icu_chain * chain
- = (struct icu_chain *) malloc(sizeof(struct icu_chain));
+ = (struct icu_chain *) xmalloc(sizeof(struct icu_chain));
*status = U_ZERO_ERROR;
icu_buf_utf16_destroy(chain->src16);
icu_chain_step_destroy(chain->steps);
- free(chain);
+ xfree(chain);
}
}