create a common function for the many places where all nodes in the table
[platform/upstream/glib.git] / glib / gconvert.c
index ab0b18e..f0eddab 100644 (file)
 
 #include "config.h"
 
+#include "glib.h"
+
+#ifndef G_OS_WIN32
 #include <iconv.h>
+#endif
 #include <errno.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 
-#include "glib.h"
 #include "gprintfint.h"
 #include "gthreadprivate.h"
 #include "gunicode.h"
 
 #include "galias.h"
 
+#ifdef G_OS_WIN32
+#include "win_iconv.c"
+#endif
+
 GQuark 
 g_convert_error_quark (void)
 {
@@ -228,7 +235,7 @@ iconv_cache_init (void)
 }
 
 
-/**
+/*
  * iconv_cache_bucket_new:
  * @key: cache key
  * @cd: iconv descriptor
@@ -263,7 +270,7 @@ iconv_cache_bucket_new (gchar *key, GIConv cd)
 }
 
 
-/**
+/*
  * iconv_cache_bucket_expire:
  * @node: cache bucket's node
  * @bucket: cache bucket
@@ -308,7 +315,7 @@ iconv_cache_bucket_expire (GList *node, struct _iconv_cache_bucket *bucket)
 }
 
 
-/**
+/*
  * iconv_cache_expire_unused:
  *
  * Expires as many unused cache buckets as it needs to in order to get
@@ -573,13 +580,13 @@ g_convert_with_iconv (const gchar *str,
   gchar *dest;
   gchar *outp;
   const gchar *p;
-  const gchar *shift_p = NULL;
   gsize inbytes_remaining;
   gsize outbytes_remaining;
   gsize err;
   gsize outbuf_size;
   gboolean have_error = FALSE;
   gboolean done = FALSE;
+  gboolean reset = FALSE;
   
   g_return_val_if_fail (converter != (GIConv) -1, NULL);
      
@@ -595,7 +602,10 @@ g_convert_with_iconv (const gchar *str,
 
   while (!done && !have_error)
     {
-      err = g_iconv (converter, (char **)&p, &inbytes_remaining, &outp, &outbytes_remaining);
+      if (reset)
+        err = g_iconv (converter, NULL, &inbytes_remaining, &outp, &outbytes_remaining);
+      else
+        err = g_iconv (converter, (char **)&p, &inbytes_remaining, &outp, &outbytes_remaining);
 
       if (err == (gsize) -1)
        {
@@ -633,11 +643,10 @@ g_convert_with_iconv (const gchar *str,
        }
       else 
        {
-         if (!shift_p)
+         if (!reset)
            {
              /* call g_iconv with NULL inbuf to cleanup shift state */
-             shift_p = p;
-             p = NULL;
+             reset = TRUE;
              inbytes_remaining = 0;
            }
          else
@@ -645,9 +654,6 @@ g_convert_with_iconv (const gchar *str,
        }
     }
 
-  if (shift_p)
-    p = shift_p;
-
   *outp = '\0';
   
   if (bytes_read)