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 ui.c


From: Göran Weinholt
Subject: [giFTcurs-commits] giFTcurs/src parse.c parse.h ui.c
Date: Thu, 06 Nov 2003 18:36:36 -0500

CVSROOT:        /cvsroot/giftcurs
Module name:    giFTcurs
Branch:         
Changes by:     Göran Weinholt <address@hidden> 03/11/06 18:36:36

Modified files:
        src            : parse.c parse.h ui.c 

Log message:
        Fixed handling of combining characters in the query field.

Patches:
Index: giFTcurs/src/parse.c
diff -u giFTcurs/src/parse.c:1.155 giFTcurs/src/parse.c:1.156
--- giFTcurs/src/parse.c:1.155  Tue Nov  4 18:56:10 2003
+++ giFTcurs/src/parse.c        Thu Nov  6 18:36:36 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.155 2003/11/04 23:56:10 weinholt Exp $
+ * $Id: parse.c,v 1.156 2003/11/06 23:36:36 weinholt Exp $
  */
 #include "giftcurs.h"
 
@@ -372,6 +372,9 @@
 {
        const char *p;
 
+       if (!utf8)
+               return visual;
+
        /* Note. continue scanning even if visual == 0, so that
         * combining characters are includes as well. */
 
@@ -384,6 +387,24 @@
        }
        return p - str;
 }
+
+char *utf8_find_next_char(gchar *p, gchar *end)
+{
+       for (;;) {
+               p = g_utf8_find_next_char(p, end);
+               if (!p || !*p || mk_wcwidth(g_utf8_get_char(p)) > 0)
+                       return p;
+       }
+}
+
+char *utf8_find_prev_char(gchar *str, gchar *p)
+{
+       for (;;) {
+               p = g_utf8_find_prev_char(str, p);
+               if (!p || mk_wcwidth(g_utf8_get_char(p)) > 0)
+                       return p;
+       }
+}
 #else
 glong vstrlen(const char *str)
 {
@@ -393,5 +414,15 @@
 int str_occupy(const char *str, int visual, int greedy)
 {
        return visual;
+}
+
+char *utf8_find_next_char(gchar *p, gchar *end)
+{
+       return g_utf8_find_next_char(p, end);
+}
+
+char *utf8_find_prev_char(gchar *str, gchar *p)
+{
+       return g_utf8_find_prev_char(str, p);
 }
 #endif
Index: giFTcurs/src/parse.h
diff -u giFTcurs/src/parse.h:1.94 giFTcurs/src/parse.h:1.95
--- giFTcurs/src/parse.h:1.94   Tue Nov  4 10:55:38 2003
+++ giFTcurs/src/parse.h        Thu Nov  6 18:36:36 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.94 2003/11/04 15:55:38 saturn Exp $
+ * $Id: parse.h,v 1.95 2003/11/06 23:36:36 weinholt Exp $
  */
 #ifndef _PARSE_H
 #define _PARSE_H
@@ -90,5 +90,9 @@
 /* Returns the number of bytes from str required to fill n slots on screen */
 /* greedy tells whether or not to include wide characters on the boundary */
 int str_occupy(const char *str, int n, int greedy);
+
+/* Find the previous/next character in the string that has a non-zero width. */
+char *utf8_find_next_char(gchar *p, gchar *end);
+char *utf8_find_prev_char(gchar *str, gchar *p);
 
 #endif
Index: giFTcurs/src/ui.c
diff -u giFTcurs/src/ui.c:1.115 giFTcurs/src/ui.c:1.116
--- giFTcurs/src/ui.c:1.115     Tue Nov  4 18:25:31 2003
+++ giFTcurs/src/ui.c   Thu Nov  6 18:36:36 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: ui.c,v 1.115 2003/11/04 23:25:31 weinholt Exp $
+ * $Id: ui.c,v 1.116 2003/11/06 23:36:36 weinholt Exp $
  */
 #include "giftcurs.h"
 
@@ -34,6 +34,7 @@
 #include "settings.h"
 #include "misc.h"
 #include "gift.h"                              /* FIXME */
+#include "wcwidth.h"
 
 static void ui_status_loghook(GLogLevelFlags log_level, const char *);
 static void ui_draw_buttonbar(void);
@@ -378,18 +379,24 @@
                break;
        case KEY_LEFT:
                if (use_utf8) {
-                       char *prevc = g_utf8_find_prev_char(foo->str, foo->str 
+ pos);
+                       char *prevc = utf8_find_prev_char(foo->str, foo->str + 
pos);
 
-                       pos = prevc - foo->str;
+                       if (!prevc)
+                               pos = 0;
+                       else
+                               pos = prevc - foo->str;
                } else {
                        pos--;
                }
                break;
        case KEY_RIGHT:
                if (use_utf8) {
-                       char *nextc = g_utf8_find_next_char(foo->str + pos, 
NULL);
+                       char *nextc = utf8_find_next_char(foo->str + pos, NULL);
 
-                       pos = nextc - foo->str;
+                       if (!nextc)
+                               pos = foo->len;
+                       else
+                               pos = nextc - foo->str;
                } else {
                        pos++;
                }
@@ -402,12 +409,12 @@
                        break;
                if (use_utf8) {
                        if (key == KEY_DC) {
-                               char *nextc = g_utf8_find_next_char(foo->str + 
pos, NULL);
+                               char *nextc = utf8_find_next_char(foo->str + 
pos, NULL);
                                int npos = nextc - foo->str;
 
                                g_string_erase(foo, pos, npos - pos);
                        } else {
-                               char *prevc = g_utf8_find_prev_char(foo->str, 
foo->str + pos);
+                               char *prevc = utf8_find_prev_char(foo->str, 
foo->str + pos);
                                int npos = prevc - foo->str;
 
                                g_string_erase(foo, npos, pos - npos);
@@ -435,10 +442,12 @@
 
        *posp = pos;
        if (use_utf8) {
+#ifdef WIDE_NCURSES
                char *p;
 
                for (p = foo->str, *vposp = 0; *p && p < foo->str + pos; p = 
g_utf8_next_char(p))
-                       *vposp += g_unichar_iswide(g_utf8_get_char(p)) ? 2 : 1;
+                       *vposp += mk_wcwidth(g_utf8_get_char(p));
+#endif
        } else {
                *vposp = pos;
        }




reply via email to

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