From: Alexander Larsson Date: Sat, 25 Aug 2001 03:22:16 +0000 (+0000) Subject: New function, doing the same as g_convert but taking a GIConv argument. X-Git-Tag: GLIB_1_3_7~17 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1424212c3f356fea0cd6662022c5f0293d4bcc0b;p=platform%2Fupstream%2Fglib.git New function, doing the same as g_convert but taking a GIConv argument. 2001-08-24 Alexander Larsson * 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. --- diff --git a/ChangeLog b/ChangeLog index a3a156b..a92d1e2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2001-08-24 Alexander Larsson + + * 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 * tests/shell-test.c: (check_string_result): Fix bad indenting. diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index a3a156b..a92d1e2 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,10 @@ +2001-08-24 Alexander Larsson + + * 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 * tests/shell-test.c: (check_string_result): Fix bad indenting. diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index a3a156b..a92d1e2 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,10 @@ +2001-08-24 Alexander Larsson + + * 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 * tests/shell-test.c: (check_string_result): Fix bad indenting. diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index a3a156b..a92d1e2 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,10 @@ +2001-08-24 Alexander Larsson + + * 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 * tests/shell-test.c: (check_string_result): Fix bad indenting. diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index a3a156b..a92d1e2 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,10 @@ +2001-08-24 Alexander Larsson + + * 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 * tests/shell-test.c: (check_string_result): Fix bad indenting. diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index a3a156b..a92d1e2 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,10 @@ +2001-08-24 Alexander Larsson + + * 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 * tests/shell-test.c: (check_string_result): Fix bad indenting. diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index a3a156b..a92d1e2 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,10 @@ +2001-08-24 Alexander Larsson + + * 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 * tests/shell-test.c: (check_string_result): Fix bad indenting. diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index a3a156b..a92d1e2 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,10 @@ +2001-08-24 Alexander Larsson + + * 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 * tests/shell-test.c: (check_string_result): Fix bad indenting. diff --git a/glib/gconvert.c b/glib/gconvert.c index 2a4cbeb..ae072e3 100644 --- a/glib/gconvert.c +++ b/glib/gconvert.c @@ -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 diff --git a/glib/gconvert.h b/glib/gconvert.h index 63e0835..4f515d3 100644 --- a/glib/gconvert.h +++ b/glib/gconvert.h @@ -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,