Simplify icu_buf_utf{8,16}_{create,resize}
authorAdam Dickmeiss <adam@indexdata.dk>
Fri, 18 Jan 2013 09:56:42 +0000 (10:56 +0100)
committerAdam Dickmeiss <adam@indexdata.dk>
Fri, 18 Jan 2013 09:56:42 +0000 (10:56 +0100)
src/icu_utf16.c
src/icu_utf8.c

index 5bb74ec..3036d0a 100644 (file)
@@ -32,16 +32,15 @@ struct icu_buf_utf16 *icu_buf_utf16_create(size_t capacity)
     struct icu_buf_utf16 *buf16
         = (struct icu_buf_utf16 *) xmalloc(sizeof(struct icu_buf_utf16));
 
-    buf16->utf16 = 0;
     buf16->utf16_len = 0;
-    buf16->utf16_cap = 0;
-
+    buf16->utf16_cap = capacity;
     if (capacity > 0)
     {
         buf16->utf16 = (UChar *) xmalloc(sizeof(UChar) * capacity);
         buf16->utf16[0] = (UChar) 0;
-        buf16->utf16_cap = capacity;
     }
+    else
+        buf16->utf16 = 0;
     return buf16;
 }
 
@@ -74,7 +73,6 @@ struct icu_buf_utf16 *icu_buf_utf16_resize(struct icu_buf_utf16 *buf16,
     {
         xfree(buf16->utf16);
         buf16->utf16 = 0;
-        buf16->utf16_len = 0;
     }
     buf16->utf16_cap = capacity;
     return buf16;
index dd392d1..ee670a1 100644 (file)
@@ -31,16 +31,15 @@ struct icu_buf_utf8 *icu_buf_utf8_create(size_t capacity)
     struct icu_buf_utf8 *buf8
         = (struct icu_buf_utf8 *) xmalloc(sizeof(struct icu_buf_utf8));
 
-    buf8->utf8 = 0;
     buf8->utf8_len = 0;
-    buf8->utf8_cap = 0;
-
+    buf8->utf8_cap = capacity;
     if (capacity > 0)
     {
         buf8->utf8 = (uint8_t *) xmalloc(sizeof(uint8_t) * capacity);
         buf8->utf8[0] = (uint8_t) 0;
-        buf8->utf8_cap = capacity;
     }
+    else
+        buf8->utf8 = 0;
     return buf8;
 }
 
@@ -75,7 +74,6 @@ struct icu_buf_utf8 *icu_buf_utf8_resize(struct icu_buf_utf8 *buf8,
     {
         xfree(buf8->utf8);
         buf8->utf8 = 0;
-        buf8->utf8_len = 0;
         buf8->utf8_cap = 0;
     }