better usage of eina_strbuf
authorbarbieri <barbieri@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Tue, 19 Jun 2012 19:59:35 +0000 (19:59 +0000)
committerbarbieri <barbieri@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Tue, 19 Jun 2012 19:59:35 +0000 (19:59 +0000)
git-svn-id: http://svn.enlightenment.org/svn/e/trunk/terminology@72504 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/bin/termio.c
src/bin/utf8.c
src/bin/utf8.h

index aea9e44..2745edc 100644 (file)
@@ -1189,7 +1189,7 @@ termio_selection_get(Evas_Object *obj, int c1x, int c1y, int c2x, int c2y)
 {
    Termio *sd = evas_object_smart_data_get(obj);
    Eina_Strbuf *sb;
-   char *s, txt[8];
+   char *s;
    int x, y;
 
    if (!sd) return NULL;
@@ -1225,39 +1225,43 @@ termio_selection_get(Evas_Object *obj, int c1x, int c1y, int c2x, int c2y)
              else if (cells[x].att.newline)
                {
                   last0 = -1;
-                  eina_strbuf_append(sb, "\n");
+                  eina_strbuf_append_char(sb, '\n');
                   break;
                }
              else if (cells[x].att.tab)
                {
-                  eina_strbuf_append(sb, "\t");
+                  eina_strbuf_append_char(sb, '\t');
                   x = ((x + 8) / 8) * 8;
                   x--;
                }
              else
                {
+                  char txt[8];
+                  int txtlen;
+
                   if (last0 >= 0)
                     {
                        v = x - last0 - 1;
                        last0 = -1;
                        while (v >= 0)
                          {
-                            eina_strbuf_append(sb, " ");
+                            eina_strbuf_append_char(sb, ' ');
                             v--;
                          }
                        if (x == (w - 1))
                          {
                             if (!cells[x].att.autowrapped)
-                              eina_strbuf_append(sb, "\n");
+                              eina_strbuf_append_char(sb, '\n');
                          }
                     }
-                  glyph_to_utf8(cells[x].glyph, txt);
-                  eina_strbuf_append(sb, txt);
+                  txtlen = glyph_to_utf8(cells[x].glyph, txt);
+                  if (txtlen > 0)
+                    eina_strbuf_append_length(sb, txt, txtlen);
                }
           }
         if (last0 >= 0)
           {
-             eina_strbuf_append(sb, "\n");
+             eina_strbuf_append_char(sb, '\n');
           }
      }
 
index 1de8669..f7879d2 100644 (file)
@@ -1,18 +1,20 @@
 #include "utf8.h"
 
-void
+int
 glyph_to_utf8(int g, char *txt)
 {
    if (g < (1 << (7)))
      { // 0xxxxxxx
         txt[0] = g & 0x7f;
         txt[1] = 0;
+        return 1;
      }
    else if (g < (1 << (5 + 6)))
      { // 110xxxxx 10xxxxxx
         txt[0] = 0xc0 | ((g >> 6) & 0x1f);
         txt[1] = 0x80 | ((g     ) & 0x3f);
         txt[2] = 0;
+        return 2;
      }
    else if (g < (1 << (4 + 6 + 6)))
      { // 1110xxxx 10xxxxxx 10xxxxxx
@@ -20,6 +22,7 @@ glyph_to_utf8(int g, char *txt)
         txt[1] = 0x80 | ((g >> 6 ) & 0x3f);
         txt[2] = 0x80 | ((g      ) & 0x3f);
         txt[3] = 0;
+        return 3;
      }
    else if (g < (1 << (3 + 6 + 6 + 6)))
      { // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
@@ -28,6 +31,7 @@ glyph_to_utf8(int g, char *txt)
         txt[2] = 0x80 | ((g >> 6 ) & 0x3f);
         txt[3] = 0x80 | ((g      ) & 0x3f);
         txt[4] = 0;
+        return 4;
      }
    else if (g < (1 << (2 + 6 + 6 + 6 + 6)))
      { // 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
@@ -37,6 +41,7 @@ glyph_to_utf8(int g, char *txt)
         txt[3] = 0x80 | ((g >> 6 ) & 0x3f);
         txt[4] = 0x80 | ((g      ) & 0x3f);
         txt[5] = 0;
+        return 5;
      }
    else if (g < (1 << (1 + 6 + 6 + 6 + 6 + 6)))
      { // 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
@@ -47,10 +52,11 @@ glyph_to_utf8(int g, char *txt)
         txt[4] = 0x80 | ((g >> 6 ) & 0x3f);
         txt[5] = 0x80 | ((g      ) & 0x3f);
         txt[6]  = 0;
+        return 6;
      }
    else
      { // error - cant encode this in utf8
         txt[0] = 0;
+        return 0;
      }
 }
-
index 0ac231e..53d38ac 100644 (file)
@@ -1,2 +1,2 @@
-void glyph_to_utf8(int g, char *txt);
+int glyph_to_utf8(int g, char *txt);