From abc8235dff9262e0f674c1a6e248b0f2b5852b1e Mon Sep 17 00:00:00 2001 From: Gustavo Sverzut Barbieri Date: Tue, 19 Jun 2012 19:59:35 +0000 Subject: [PATCH] better usage of eina_strbuf SVN revision: 72504 --- src/bin/termio.c | 20 ++++++++++++-------- src/bin/utf8.c | 10 ++++++++-- src/bin/utf8.h | 2 +- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/bin/termio.c b/src/bin/termio.c index aea9e443..2745edc1 100644 --- a/src/bin/termio.c +++ b/src/bin/termio.c @@ -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'); } } diff --git a/src/bin/utf8.c b/src/bin/utf8.c index 1de8669e..f7879d22 100644 --- a/src/bin/utf8.c +++ b/src/bin/utf8.c @@ -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; } } - diff --git a/src/bin/utf8.h b/src/bin/utf8.h index 0ac231e4..53d38ac0 100644 --- a/src/bin/utf8.h +++ b/src/bin/utf8.h @@ -1,2 +1,2 @@ -void glyph_to_utf8(int g, char *txt); +int glyph_to_utf8(int g, char *txt);