Header updates
[yaz-moved-to-github.git] / src / icu_transform.c
index 10ace94..e8d2012 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2009 Index Data
+ * Copyright (C) 1995-2011 Index Data
  * See the file LICENSE for details.
  */
 
@@ -19,6 +19,7 @@
 
 #include <yaz/log.h>
 
+#include <assert.h>
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -32,6 +33,19 @@ struct icu_transform
     UTransliterator * trans;
 };
 
+struct icu_transform *icu_transform_clone(struct icu_transform *old)
+{
+    struct icu_transform *transform
+        = (struct icu_transform *) xmalloc(sizeof(struct icu_transform));
+    UErrorCode status = U_ZERO_ERROR;
+    assert(old);
+    transform->action = old->action;
+    assert(old->trans);
+    transform->trans = utrans_clone(old->trans, &status);
+    assert(transform->trans);
+    return transform;
+}
+
 struct icu_transform * icu_transform_create(const char *id, char action,
                                             const char *rules, 
                                             UErrorCode *status)
@@ -47,6 +61,7 @@ struct icu_transform * icu_transform_create(const char *id, char action,
 
     if (id)
         icu_utf16_from_utf8_cstr(id16, id, status);
+
     if (rules)
         icu_utf16_from_utf8_cstr(rules16, rules, status);
 
@@ -99,7 +114,7 @@ void icu_transform_destroy(struct icu_transform * transform)
 
 int icu_transform_trans(struct icu_transform * transform,
                         struct icu_buf_utf16 * dest16,
-                        struct icu_buf_utf16 * src16,
+                        const struct icu_buf_utf16 * src16,
                         UErrorCode *status)
 {
     if (!transform || !transform->trans 
@@ -118,7 +133,7 @@ int icu_transform_trans(struct icu_transform * transform,
     utrans_transUChars (transform->trans, 
                         dest16->utf16, &(dest16->utf16_len),
                         dest16->utf16_cap,
-                        0, &(src16->utf16_len), status);
+                        0, &(dest16->utf16_len), status);
 
     if (U_FAILURE(*status))
         icu_buf_utf16_clear(dest16);