New function, doing the same as g_convert but taking a GIConv argument.
authorAlexander Larsson <alla@lysator.liu.se>
Sat, 25 Aug 2001 03:22:16 +0000 (03:22 +0000)
committerAlexander Larsson <alexl@src.gnome.org>
Sat, 25 Aug 2001 03:22:16 +0000 (03:22 +0000)
2001-08-24  Alexander Larsson  <alla@lysator.liu.se>

* glib/gconvert.[ch] (g_convert_with_iconv):
New function, doing the same as g_convert but taking
a GIConv argument. The old g_convert is just
a call to this with a newly opened GIConv.

ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
glib/gconvert.c
glib/gconvert.h

index a3a156b..a92d1e2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2001-08-24  Alexander Larsson  <alla@lysator.liu.se>
+
+       * glib/gconvert.[ch] (g_convert_with_iconv):
+       New function, doing the same as g_convert but taking
+       a GIConv argument. The old g_convert is just
+       a call to this with a newly opened GIConv.
+
 2001-08-24  Darin Adler  <darin@bentspoon.com>
 
        * tests/shell-test.c: (check_string_result): Fix bad indenting.
index a3a156b..a92d1e2 100644 (file)
@@ -1,3 +1,10 @@
+2001-08-24  Alexander Larsson  <alla@lysator.liu.se>
+
+       * glib/gconvert.[ch] (g_convert_with_iconv):
+       New function, doing the same as g_convert but taking
+       a GIConv argument. The old g_convert is just
+       a call to this with a newly opened GIConv.
+
 2001-08-24  Darin Adler  <darin@bentspoon.com>
 
        * tests/shell-test.c: (check_string_result): Fix bad indenting.
index a3a156b..a92d1e2 100644 (file)
@@ -1,3 +1,10 @@
+2001-08-24  Alexander Larsson  <alla@lysator.liu.se>
+
+       * glib/gconvert.[ch] (g_convert_with_iconv):
+       New function, doing the same as g_convert but taking
+       a GIConv argument. The old g_convert is just
+       a call to this with a newly opened GIConv.
+
 2001-08-24  Darin Adler  <darin@bentspoon.com>
 
        * tests/shell-test.c: (check_string_result): Fix bad indenting.
index a3a156b..a92d1e2 100644 (file)
@@ -1,3 +1,10 @@
+2001-08-24  Alexander Larsson  <alla@lysator.liu.se>
+
+       * glib/gconvert.[ch] (g_convert_with_iconv):
+       New function, doing the same as g_convert but taking
+       a GIConv argument. The old g_convert is just
+       a call to this with a newly opened GIConv.
+
 2001-08-24  Darin Adler  <darin@bentspoon.com>
 
        * tests/shell-test.c: (check_string_result): Fix bad indenting.
index a3a156b..a92d1e2 100644 (file)
@@ -1,3 +1,10 @@
+2001-08-24  Alexander Larsson  <alla@lysator.liu.se>
+
+       * glib/gconvert.[ch] (g_convert_with_iconv):
+       New function, doing the same as g_convert but taking
+       a GIConv argument. The old g_convert is just
+       a call to this with a newly opened GIConv.
+
 2001-08-24  Darin Adler  <darin@bentspoon.com>
 
        * tests/shell-test.c: (check_string_result): Fix bad indenting.
index a3a156b..a92d1e2 100644 (file)
@@ -1,3 +1,10 @@
+2001-08-24  Alexander Larsson  <alla@lysator.liu.se>
+
+       * glib/gconvert.[ch] (g_convert_with_iconv):
+       New function, doing the same as g_convert but taking
+       a GIConv argument. The old g_convert is just
+       a call to this with a newly opened GIConv.
+
 2001-08-24  Darin Adler  <darin@bentspoon.com>
 
        * tests/shell-test.c: (check_string_result): Fix bad indenting.
index a3a156b..a92d1e2 100644 (file)
@@ -1,3 +1,10 @@
+2001-08-24  Alexander Larsson  <alla@lysator.liu.se>
+
+       * glib/gconvert.[ch] (g_convert_with_iconv):
+       New function, doing the same as g_convert but taking
+       a GIConv argument. The old g_convert is just
+       a call to this with a newly opened GIConv.
+
 2001-08-24  Darin Adler  <darin@bentspoon.com>
 
        * tests/shell-test.c: (check_string_result): Fix bad indenting.
index a3a156b..a92d1e2 100644 (file)
@@ -1,3 +1,10 @@
+2001-08-24  Alexander Larsson  <alla@lysator.liu.se>
+
+       * glib/gconvert.[ch] (g_convert_with_iconv):
+       New function, doing the same as g_convert but taking
+       a GIConv argument. The old g_convert is just
+       a call to this with a newly opened GIConv.
+
 2001-08-24  Darin Adler  <darin@bentspoon.com>
 
        * tests/shell-test.c: (check_string_result): Fix bad indenting.
index 2a4cbeb..ae072e3 100644 (file)
@@ -186,15 +186,8 @@ g_convert (const gchar *str,
           gsize       *bytes_written, 
           GError     **error)
 {
-  gchar *dest;
-  gchar *outp;
-  const gchar *p;
-  gsize inbytes_remaining;
-  gsize outbytes_remaining;
-  gsize err;
+  gchar *res;
   GIConv cd;
-  gsize outbuf_size;
-  gboolean have_error = FALSE;
   
   g_return_val_if_fail (str != NULL, NULL);
   g_return_val_if_fail (to_codeset != NULL, NULL);
@@ -213,6 +206,59 @@ g_convert (const gchar *str,
       return NULL;
     }
 
+  res = g_convert_with_iconv (str, len, cd,
+                             bytes_read, bytes_written,
+                             error);
+  
+  g_iconv_close (cd);
+
+  return res;
+}
+
+/**
+ * g_convert_with_iconv:
+ * @str:           the string to convert
+ * @len:           the length of the string
+ * @converter:     conversion descriptor from g_iconv_open()
+ * @bytes_read:    location to store the number of bytes in the
+ *                 input string that were successfully converted, or %NULL.
+ *                 Even if the conversion was succesful, this may be 
+ *                 less than len if there were partial characters
+ *                 at the end of the input. If the error
+ *                 G_CONVERT_ERROR_ILLEGAL_SEQUENCE occurs, the value
+ *                 stored will the byte fofset after the last valid
+ *                 input sequence.
+ * @bytes_written: the stored in the output buffer (not including the
+ *                 terminating nul.
+ * @error:         location to store the error occuring, or %NULL to ignore
+ *                 errors. Any of the errors in #GConvertError may occur.
+ *
+ * Convert a string from one character set to another.
+ *
+ * Return value: If the conversion was successful, a newly allocated
+ *               NUL-terminated string, which must be freed with
+ *               g_free. Otherwise %NULL and @error will be set.
+ **/
+gchar*
+g_convert_with_iconv (const gchar *str,
+                     gssize       len,
+                     GIConv       converter,
+                     gsize       *bytes_read, 
+                     gsize       *bytes_written, 
+                     GError     **error)
+{
+  gchar *dest;
+  gchar *outp;
+  const gchar *p;
+  gsize inbytes_remaining;
+  gsize outbytes_remaining;
+  gsize err;
+  gsize outbuf_size;
+  gboolean have_error = FALSE;
+  
+  g_return_val_if_fail (str != NULL, NULL);
+  g_return_val_if_fail (converter != (GIConv) -1, NULL);
+     
   if (len < 0)
     len = strlen (str);
 
@@ -225,7 +271,7 @@ g_convert (const gchar *str,
 
  again:
   
-  err = g_iconv (cd, (char **)&p, &inbytes_remaining, &outp, &outbytes_remaining);
+  err = g_iconv (converter, (char **)&p, &inbytes_remaining, &outp, &outbytes_remaining);
 
   if (err == (size_t) -1)
     {
@@ -262,8 +308,6 @@ g_convert (const gchar *str,
 
   *outp = '\0';
   
-  g_iconv_close (cd);
-
   if (bytes_read)
     *bytes_read = p - str;
   else
index 63e0835..4f515d3 100644 (file)
@@ -64,6 +64,12 @@ gchar* g_convert               (const gchar  *str,
                                gsize        *bytes_read,     
                                gsize        *bytes_written,  
                                GError      **error);
+gchar* g_convert_with_iconv    (const gchar  *str,
+                               gssize        len,
+                               GIConv        converter,
+                               gsize        *bytes_read,     
+                               gsize        *bytes_written,  
+                               GError      **error);
 gchar* g_convert_with_fallback (const gchar  *str,
                                gssize        len,            
                                const gchar  *to_codeset,