From bd0695d1b51c90b786080f68b5d711709f0005dd Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Wed, 16 Feb 2011 16:00:17 +0000 Subject: [PATCH] Evas encoding: Removed Evas_Encoding and moved to eina_unicode_utf8* instead. SVN revision: 57096 --- legacy/evas/src/lib/canvas/evas_object_text.c | 10 +- .../src/lib/canvas/evas_object_textblock.c | 8 +- .../evas/src/lib/engines/common/Makefile.am | 2 - .../src/lib/engines/common/evas_encoding.c | 259 ------------------ .../src/lib/engines/common/evas_encoding.h | 26 -- .../src/lib/engines/common/evas_font_main.c | 1 - .../engines/common/language/evas_bidi_utils.c | 1 - legacy/evas/src/lib/include/evas_common.h | 4 - 8 files changed, 9 insertions(+), 302 deletions(-) delete mode 100644 legacy/evas/src/lib/engines/common/evas_encoding.c delete mode 100644 legacy/evas/src/lib/engines/common/evas_encoding.h diff --git a/legacy/evas/src/lib/canvas/evas_object_text.c b/legacy/evas/src/lib/canvas/evas_object_text.c index 54579452d7..505cea5463 100644 --- a/legacy/evas/src/lib/canvas/evas_object_text.c +++ b/legacy/evas/src/lib/canvas/evas_object_text.c @@ -678,7 +678,7 @@ evas_object_text_text_set(Evas_Object *obj, const char *_text) { return; } - text = evas_common_encoding_utf8_to_unicode(_text, &len); + text = eina_unicode_utf8_to_unicode(_text, &len); if (!text) text = eina_unicode_strdup(EINA_UNICODE_EMPTY_STRING); was = evas_object_is_in_output_rect(obj, @@ -1668,7 +1668,7 @@ evas_string_char_next_get(const char *str, int pos, int *decoded) if (decoded) *decoded = 0; if ((!str) || (pos < 0)) return 0; p = pos; - d = evas_common_encoding_utf8_get_next(str, &p); + d = eina_unicode_utf8_get_next(str, &p); if (decoded) *decoded = d; return p; } @@ -1700,7 +1700,7 @@ evas_string_char_prev_get(const char *str, int pos, int *decoded) if (decoded) *decoded = 0; if ((!str) || (pos < 1)) return 0; p = pos; - d = evas_common_encoding_utf8_get_prev(str, &p); + d = eina_unicode_utf8_get_prev(str, &p); if (decoded) *decoded = d; return p; } @@ -1715,7 +1715,7 @@ EAPI int evas_string_char_len_get(const char *str) { if (!str) return 0; - return evas_common_encoding_utf8_get_len(str); + return eina_unicode_utf8_get_len(str); } /** @@ -2298,7 +2298,7 @@ _evas_object_text_recalc(Evas_Object *obj) if (o->items) _evas_object_text_items_clear(o); if (o->cur.utf8_text) - text = evas_common_encoding_utf8_to_unicode(o->cur.utf8_text, + text = eina_unicode_utf8_to_unicode(o->cur.utf8_text, NULL); if (!text) text = eina_unicode_strdup(EINA_UNICODE_EMPTY_STRING); diff --git a/legacy/evas/src/lib/canvas/evas_object_textblock.c b/legacy/evas/src/lib/canvas/evas_object_textblock.c index 6e932a7c46..7666613a31 100644 --- a/legacy/evas/src/lib/canvas/evas_object_textblock.c +++ b/legacy/evas/src/lib/canvas/evas_object_textblock.c @@ -2744,7 +2744,7 @@ _layout_text_append(Ctxt *c, Evas_Object_Textblock_Format *fmt, Evas_Object_Text str = alloca((off + 1) * sizeof(Eina_Unicode)); tbase = str; ind = 0; - urepch = evas_common_encoding_utf8_get_next(repch, &ind); + urepch = eina_unicode_utf8_get_next(repch, &ind); for (i = 0, ptr = (Eina_Unicode *)tbase; i < off; ptr++, i++) *ptr = urepch; *ptr = 0; @@ -4563,7 +4563,7 @@ _markup_get_format_append(Evas_Object_Textblock *o, Eina_Strbuf *txt, Evas_Objec static void _markup_get_text_append(Eina_Strbuf *txt, const Eina_Unicode *text) { - char *p = evas_common_encoding_unicode_to_utf8(text, NULL); + char *p = eina_unicode_unicode_to_utf8(text, NULL); char *base = p; while (*p) { @@ -6391,7 +6391,7 @@ evas_textblock_cursor_text_append(Evas_Textblock_Cursor *cur, const char *_text) int len = 0; if (!cur) return 0; - text = evas_common_encoding_utf8_to_unicode(_text, &len); + text = eina_unicode_utf8_to_unicode(_text, &len); o = (Evas_Object_Textblock *)(cur->obj->object_data); /* Update all the cursors after our position. */ _evas_textblock_cursors_update_offset(cur, cur->node, cur->pos, len); @@ -6885,7 +6885,7 @@ evas_textblock_cursor_content_get(const Evas_Textblock_Cursor *cur) ustr = eina_ustrbuf_string_get(cur->node->unicode); buf[0] = ustr[cur->pos]; buf[1] = 0; - s = evas_common_encoding_unicode_to_utf8(buf, NULL); + s = eina_unicode_unicode_to_utf8(buf, NULL); return s; } diff --git a/legacy/evas/src/lib/engines/common/Makefile.am b/legacy/evas/src/lib/engines/common/Makefile.am index c3f9dd8426..c3290b92ba 100644 --- a/legacy/evas/src/lib/engines/common/Makefile.am +++ b/legacy/evas/src/lib/engines/common/Makefile.am @@ -39,7 +39,6 @@ evas_convert_grypal_6.c \ evas_convert_yuv.c \ evas_cpu.c \ evas_draw_main.c \ -evas_encoding.c \ evas_font_draw.c \ evas_font_load.c \ evas_font_main.c \ @@ -82,7 +81,6 @@ evas_convert_rgb_32.h \ evas_convert_rgb_8.h \ evas_convert_yuv.h \ evas_draw.h \ -evas_encoding.h \ evas_font.h \ evas_font_private.h \ evas_image.h \ diff --git a/legacy/evas/src/lib/engines/common/evas_encoding.c b/legacy/evas/src/lib/engines/common/evas_encoding.c deleted file mode 100644 index ca7a556620..0000000000 --- a/legacy/evas/src/lib/engines/common/evas_encoding.c +++ /dev/null @@ -1,259 +0,0 @@ -#include "evas_common.h" -#include "evas_encoding.h" - -/* The replacement range that will be used for bad utf8 chars. */ -#define ERROR_REPLACEMENT_BASE 0xDC80 -#define ERROR_REPLACEMENT_END 0xDCFF -#define IS_INVALID_BYTE(x) ((x == 192) || (x == 193) || (x >= 245)) -#define IS_CONTINUATION_BYTE(x) ((x & 0xC0) == 0x80) - -EAPI Eina_Unicode -evas_common_encoding_utf8_get_next(const char *buf, int *iindex) -{ - /* Reads UTF8 bytes from @buf, starting at *@index and returns - * the decoded code point at iindex offset, and advances iindex - * to the next code point after this. - * - * Returns 0 to indicate there is no next char - */ - /* Note: we don't currently handle overlong forms and some other - * broken cases. */ - int index = *iindex; - Eina_Unicode r; - unsigned char d; - - /* if this char is the null terminator, exit */ - if ((d = buf[index++]) == 0) return 0; - - if ((d & 0x80) == 0) - { // 1 byte (7bit) - 0xxxxxxx - *iindex = index; - return d; - } - if ((d & 0xe0) == 0xc0) - { // 2 byte (11bit) - 110xxxxx 10xxxxxx - r = (d & 0x1f) << 6; - if (((d = buf[index++]) == 0) || IS_INVALID_BYTE(d) || - !IS_CONTINUATION_BYTE(d)) goto error; - r |= (d & 0x3f); - if (!r) goto error; - *iindex = index; - return r; - } - if ((d & 0xf0) == 0xe0) - { // 3 byte (16bit) - 1110xxxx 10xxxxxx 10xxxxxx - r = (d & 0x0f) << 12; - if (((d = buf[index++]) == 0) || IS_INVALID_BYTE(d) || - !IS_CONTINUATION_BYTE(d)) goto error; - r |= (d & 0x3f) << 6; - if (((d = buf[index++]) == 0) || IS_INVALID_BYTE(d) || - !IS_CONTINUATION_BYTE(d)) goto error; - r |= (d & 0x3f); - if (!r) goto error; - *iindex = index; - return r; - } - if ((d & 0xf8) == 0xf0) - { // 4 byte (21bit) - 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx - r = (d & 0x07) << 18; - if (((d = buf[index++]) == 0) || IS_INVALID_BYTE(d) || - !IS_CONTINUATION_BYTE(d)) goto error; - r |= (d & 0x3f) << 12; - if (((d = buf[index++]) == 0) || IS_INVALID_BYTE(d) || - !IS_CONTINUATION_BYTE(d)) goto error; - r |= (d & 0x3f) << 6; - if (((d = buf[index++]) == 0) || IS_INVALID_BYTE(d) || - !IS_CONTINUATION_BYTE(d)) goto error; - r |= (d & 0x3f); - if (!r) goto error; - *iindex = index; - return r; - } - if ((d & 0xfc) == 0xf8) - { // 5 byte (26bit) - 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx - r = (d & 0x03) << 24; - if (((d = buf[index++]) == 0) || IS_INVALID_BYTE(d) || - !IS_CONTINUATION_BYTE(d)) goto error; - r |= (d & 0x3f) << 18; - if (((d = buf[index++]) == 0) || IS_INVALID_BYTE(d) || - !IS_CONTINUATION_BYTE(d)) goto error; - r |= (d & 0x3f) << 12; - if (((d = buf[index++]) == 0) || IS_INVALID_BYTE(d) || - !IS_CONTINUATION_BYTE(d)) goto error; - r |= (d & 0x3f) << 6; - if (((d = buf[index++]) == 0) || IS_INVALID_BYTE(d) || - !IS_CONTINUATION_BYTE(d)) goto error; - r |= (d & 0x3f); - if (!r) goto error; - *iindex = index; - return r; - } - if ((d & 0xfe) == 0xfc) - { // 6 byte (31bit) - 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx - r = (d & 0x01) << 30; - if (((d = buf[index++]) == 0) || IS_INVALID_BYTE(d) || - !IS_CONTINUATION_BYTE(d)) goto error; - r |= (d & 0x3f) << 24; - if (((d = buf[index++]) == 0) || IS_INVALID_BYTE(d) || - !IS_CONTINUATION_BYTE(d)) goto error; - r |= (d & 0x3f) << 18; - if (((d = buf[index++]) == 0) || IS_INVALID_BYTE(d) || - !IS_CONTINUATION_BYTE(d)) goto error; - r |= (d & 0x3f) << 12; - if (((d = buf[index++]) == 0) || IS_INVALID_BYTE(d) || - !IS_CONTINUATION_BYTE(d)) goto error; - r |= (d & 0x3f) << 6; - if (((d = buf[index++]) == 0) || IS_INVALID_BYTE(d) || - !IS_CONTINUATION_BYTE(d)) goto error; - r |= (d & 0x3f); - if (!r) goto error; - *iindex = index; - return r; - } - -/* Gets here where there was an error and we want to replace the char - * we just use the invalid unicode codepoints 8 lower bits represent - * the original char */ -error: - d = buf[*iindex]; - (*iindex)++; - return ERROR_REPLACEMENT_BASE | d; -} - -EAPI Eina_Unicode -evas_common_encoding_utf8_get_prev(const char *buf, int *iindex) -{ - /* Reads UTF8 bytes from @buf, starting at *@index and returns - * the decoded code point at iindex offset, and advances iindex - * to the prev code point after this. - * - * Returns 0 to indicate there is no prev char - */ - - int r; - int index = *iindex; - /* First obtain the codepoint at iindex */ - r = evas_common_encoding_utf8_get_next(buf, &index); - - /* although when index == 0 there's no previous char, we still want to get - * the current char */ - if (*iindex < 0) - return r; - - /* Next advance iindex to previous codepoint */ - index = *iindex; - index--; - while ((index > 0) && ((buf[index] & 0xc0) == 0x80)) - index--; - - *iindex = index; - return r; -} - -EAPI Eina_Unicode -evas_common_encoding_utf8_get_last(const char *buf, int buflen) -{ - /* jumps to the nul byte at the buffer end and decodes backwards and - * returns the offset index byte in the buffer where the last character - * in the buffer begins. - * - * Returns -1 to indicate an error - */ - /* Go one character backwards and then return the char at the new place */ - evas_common_encoding_utf8_get_prev(buf, &buflen); - return evas_common_encoding_utf8_get_next(buf, &buflen); -} - -EAPI int -evas_common_encoding_utf8_get_len(const char *buf) -{ - /* returns the number of utf8 characters (not bytes) in the string */ - int i = 0, len = 0; - - while (evas_common_encoding_utf8_get_next(buf, &i)) - len++; - - return len; -} - -/* FIXME: Should optimize! */ -EAPI Eina_Unicode * -evas_common_encoding_utf8_to_unicode(const char *utf, int *_len) -{ - int len, i; - int index; - Eina_Unicode *buf, *ind; - - len = evas_common_encoding_utf8_get_len(utf); - if (_len) - *_len = len; - buf = (Eina_Unicode *) calloc(sizeof(Eina_Unicode), (len + 1)); - if (!buf) return buf; - - for (i = 0, index = 0, ind = buf ; i < len ; i++, ind++) - { - *ind = evas_common_encoding_utf8_get_next(utf, &index); - } - - return buf; -} - -EAPI char * -evas_common_encoding_unicode_to_utf8(const Eina_Unicode *uni, int *_len) -{ - char *buf; - const Eina_Unicode *uind; - char *ind; - int ulen, len; - - ulen = eina_unicode_strlen(uni); - buf = (char *) calloc(ulen + 1, EVAS_ENCODING_UTF8_BYTES_PER_CHAR); - - len = 0; - for (uind = uni, ind = buf ; *uind ; uind++) - { - if (*uind <= 0x7F) /* 1 byte char */ - { - *ind++ = *uind; - len += 1; - } - else if (*uind <= 0x7FF) /* 2 byte char */ - { - *ind++ = 0xC0 | (unsigned char) (*uind >> 6); - *ind++ = 0x80 | (unsigned char) (*uind & 0x3F); - len += 2; - } - else if (*uind <= 0xFFFF) /* 3 byte char */ - { - /* If it's a special replacement codepoint */ - if (*uind >= ERROR_REPLACEMENT_BASE && - *uind <= ERROR_REPLACEMENT_END) - { - *ind++ = *uind & 0xFF; - len += 1; - } - else - { - *ind++ = 0xE0 | (unsigned char) (*uind >> 12); - *ind++ = 0x80 | (unsigned char) ((*uind >> 6) & 0x3F); - *ind++ = 0x80 | (unsigned char) (*uind & 0x3F); - len += 3; - } - } - else /* 4 byte char */ - { - *ind++ = 0xF0 | (unsigned char) ((*uind >> 18) & 0x07); - *ind++ = 0x80 | (unsigned char) ((*uind >> 12) & 0x3F); - *ind++ = 0x80 | (unsigned char) ((*uind >> 6) & 0x3F); - *ind++ = 0x80 | (unsigned char) (*uind & 0x3F); - len += 4; - } - } - buf = realloc(buf, len + 1); - buf[len] = '\0'; - if (_len) - *_len = len; - return buf; -} - - diff --git a/legacy/evas/src/lib/engines/common/evas_encoding.h b/legacy/evas/src/lib/engines/common/evas_encoding.h deleted file mode 100644 index e278727a5d..0000000000 --- a/legacy/evas/src/lib/engines/common/evas_encoding.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef EVAS_ENCODING_H -#define EVAS_ENCODING_H -#include - -/* FIXME: An assumption that will probably break in the future */ -#define EVAS_ENCODING_UTF8_BYTES_PER_CHAR 4 - -EAPI Eina_Unicode -evas_common_encoding_utf8_get_next(const char *buf, int *iindex); - -EAPI Eina_Unicode -evas_common_encoding_utf8_get_prev(const char *buf, int *iindex); - -EAPI Eina_Unicode -evas_common_encoding_utf8_get_last(const char *buf, int buflen); - -EAPI int -evas_common_encoding_utf8_get_len(const char *buf); - -EAPI Eina_Unicode * -evas_common_encoding_utf8_to_unicode(const char *utf, int *_len) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_MALLOC; - -EAPI char * -evas_common_encoding_unicode_to_utf8(const Eina_Unicode *uni, int *_len) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_MALLOC; - -#endif diff --git a/legacy/evas/src/lib/engines/common/evas_font_main.c b/legacy/evas/src/lib/engines/common/evas_font_main.c index 9d37b4f504..821ab6ea0f 100644 --- a/legacy/evas/src/lib/engines/common/evas_font_main.c +++ b/legacy/evas/src/lib/engines/common/evas_font_main.c @@ -1,6 +1,5 @@ #include "evas_common.h" #include "evas_private.h" -#include "evas_encoding.h" #include "evas_font_private.h" diff --git a/legacy/evas/src/lib/engines/common/language/evas_bidi_utils.c b/legacy/evas/src/lib/engines/common/language/evas_bidi_utils.c index b05b2747d2..52964a4c2e 100644 --- a/legacy/evas/src/lib/engines/common/language/evas_bidi_utils.c +++ b/legacy/evas/src/lib/engines/common/language/evas_bidi_utils.c @@ -3,7 +3,6 @@ #include "evas_common.h" #include "evas_bidi_utils.h" -#include "evas_encoding.h" #include "evas_font_private.h" diff --git a/legacy/evas/src/lib/include/evas_common.h b/legacy/evas/src/lib/include/evas_common.h index 95e329b6ef..07203c38ef 100644 --- a/legacy/evas/src/lib/include/evas_common.h +++ b/legacy/evas/src/lib/include/evas_common.h @@ -49,10 +49,6 @@ extern EAPI int _evas_log_dom_global; #endif #define CRIT(...) EINA_LOG_DOM_CRIT(_EVAS_DEFAULT_LOG_DOM, __VA_ARGS__) -/************************ Unicode stuff **************************/ -#include "../engines/common/evas_encoding.h" -/*****************************************************************/ - #include "evas_options.h" #if defined(__ARM_ARCH_3M__)