giftcurs-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[giFTcurs-commits] giFTcurs/src parse.c parse.h


From: Göran Weinholt
Subject: [giFTcurs-commits] giFTcurs/src parse.c parse.h
Date: Tue, 14 Oct 2003 15:49:36 -0400

CVSROOT:        /cvsroot/giftcurs
Module name:    giFTcurs
Branch:         
Changes by:     Göran Weinholt <address@hidden> 03/10/14 15:49:36

Modified files:
        src            : parse.c parse.h 

Log message:
        New function convert_to_locale() which tries to convert a string to the 
current locale's charset.

Patches:
Index: giFTcurs/src/parse.c
diff -u giFTcurs/src/parse.c:1.147 giFTcurs/src/parse.c:1.148
--- giFTcurs/src/parse.c:1.147  Mon Sep 15 17:24:34 2003
+++ giFTcurs/src/parse.c        Tue Oct 14 15:49:35 2003
@@ -18,7 +18,7 @@
  * along with giFTcurs; if not, write to the Free Software Foundation,
  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,  USA.
  *
- * $Id: parse.c,v 1.147 2003/09/15 21:24:34 saturn Exp $
+ * $Id: parse.c,v 1.148 2003/10/14 19:49:35 weinholt Exp $
  */
 #include "giftcurs.h"
 
@@ -319,4 +319,32 @@
                        return (i << 3) + g_bit_nth_lsf(~bitmap[i], -1);
 
        return -1;
+}
+
+char *convert_to_locale(char *str)
+{
+       const char *from, *to;
+       char *tmp;
+
+       if (G_UNLIKELY(utf8)) {
+               /* TODO: autodetect the locale somehow? */
+               if (!g_utf8_validate(str, -1, NULL))
+                       from = "iso-8859-1", to = "utf-8";
+               else
+                       return str;
+       } else {
+               if (g_utf8_validate(str, -1, NULL))
+                       from = "utf-8", g_get_charset(&to);
+               else
+                       return str;
+       }
+
+       tmp = g_convert_with_fallback(str, -1, to, from, NULL, NULL, NULL, 
NULL);
+
+       if (tmp) {
+               /* Conversion succeeded. */
+               g_free(str);
+               return tmp;
+       }
+       return str;
 }
Index: giFTcurs/src/parse.h
diff -u giFTcurs/src/parse.h:1.90 giFTcurs/src/parse.h:1.91
--- giFTcurs/src/parse.h:1.90   Sun Aug 31 14:45:42 2003
+++ giFTcurs/src/parse.h        Tue Oct 14 15:49:35 2003
@@ -18,7 +18,7 @@
  * along with giFTcurs; if not, write to the Free Software Foundation,
  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,  USA.
  *
- * $Id: parse.h,v 1.90 2003/08/31 18:45:42 saturn Exp $
+ * $Id: parse.h,v 1.91 2003/10/14 19:49:35 weinholt Exp $
  */
 #ifndef _PARSE_H
 #define _PARSE_H
@@ -82,5 +82,9 @@
 void bitmap_set(guchar *bitmap, guint size, guint idx, gboolean value);
 gboolean bitmap_get(guchar *bitmap, guint size, guint idx);
 gint bitmap_find_unset(guchar *bitmap, guint size);
+
+/* Tries to convert from 'from' to 'to', freeing 'str' and returning the
+   newly allocated string if it worked. */
+char *convert_to_locale(char *str);
 
 #endif




reply via email to

[Prev in Thread] Current Thread [Next in Thread]