better escaping!

SVN revision: 36954
This commit is contained in:
Carsten Haitzler 2008-10-22 04:44:22 +00:00
parent 1cefba4012
commit e4e3b0d5a2
2 changed files with 183 additions and 185 deletions

View File

@ -624,6 +624,9 @@ extern "C" {
} Evas_Textblock_Text_Type;
EAPI Evas_Object *evas_object_textblock_add(Evas *e);
EAPI const char *evas_textblock_escape_string_get(const char *escape);
EAPI const char *evas_textblock_string_escape_get(const char *string, int *len_ret);
EAPI Evas_Textblock_Style *evas_textblock_style_new(void);
EAPI void evas_textblock_style_free(Evas_Textblock_Style *ts);

View File

@ -530,184 +530,153 @@ _nodes_adjacent_merge(const Evas_Object *obj, Evas_Object_Textblock_Node *n1)
*/
static const char escape_strings[] =
/* most common escaped stuff */
"<\0\x3c\0"
">\0\x3e\0"
"&\0\x26\0"
" \0\x20\0" /* NOTE: this here to avoid escaping to &nbsp */
" \0\x20\0" /* NOTE: we allow nsbp's to break as we map early - maybe map to ascii 0x01 and then make the rendering code think 0x01 -> 0x20 */
""\0\x22\0"
" \0" "\x20\0" /* NOTE: this here to avoid escaping to &nbsp */
" \0" "\x20\0" /* NOTE: we allow nsbp's to break as we map early - maybe map to ascii 0x01 and then make the rendering code think 0x01 -> 0x20 */
""\0" "\x22\0"
"&\0" "\x26\0"
"<\0" "\x3c\0"
">\0" "\x3e\0"
/* all the rest */
"©\0\xc2\xa9\0"
"®\0\xc2\xae\0"
"…\0\xe2\x80\xa6\0"
"Ñ\0\xc3\x91\0"
"ñ\0\xc3\xb1\0"
"Ç\0\xc3\x87\0"
"ç\0\xc3\xa7\0"
"ß\0\xc3\x9f\0"
"Þ\0\xc3\x9e\0"
"þ\0\xc3\xbe\0"
"Ð\0\xc3\x90\0"
"ð\0\xc3\xb0\0"
"´\0\xc2\xb4\0"
"¸\0\xc2\xb8\0"
"°\0\xc2\xb0\0"
"¨\0\xc2\xa8\0"
"¢\0\xc2\xa2\0"
"£\0\xc2\xa3\0"
"¤\0\xc2\xa4\0"
"¥\0\xc2\xa5\0"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\0" "\xc3\xb5\0"
"ö\0" "\xc3\xb6\0"
"÷\0" "\xc3\xb7\0"
"ø\0" "\xc3\xb8\0"
"ù\0" "\xc3\xb9\0"
"ú\0" "\xc3\xba\0"
"û\0" "\xc3\xbb\0"
"ü\0" "\xc3\xbc\0"
"ý\0" "\xc3\xbd\0"
"þ\0" "\xc3\xbe\0"
"ÿ\0" "\xc3\xbf\0"
"α\0" "\xce\x91\0"
"β\0" "\xce\x92\0"
"γ\0" "\xce\x93\0"
"δ\0" "\xce\x94\0"
"ε\0" "\xce\x95\0"
"ζ\0" "\xce\x96\0"
"η\0" "\xce\x97\0"
"θ\0" "\xce\x98\0"
"ι\0" "\xce\x99\0"
"κ\0" "\xce\x9a\0"
"λ\0" "\xce\x9b\0"
"μ\0" "\xce\x9c\0"
"ν\0" "\xce\x9d\0"
"ξ\0" "\xce\x9e\0"
"ο\0" "\xce\x9f\0"
"π\0" "\xce\xa0\0"
"ρ\0" "\xce\xa1\0"
"σ\0" "\xce\xa3\0"
"τ\0" "\xce\xa4\0"
"υ\0" "\xce\xa5\0"
"φ\0" "\xce\xa6\0"
"χ\0" "\xce\xa7\0"
"ψ\0" "\xce\xa8\0"
"ω\0" "\xce\xa9\0"
"…\0" "\xe2\x80\xa6\0"
"€\0" "\xe2\x82\xac\0"
"←\0" "\xe2\x86\x90\0"
"↑\0" "\xe2\x86\x91\0"
"→\0" "\xe2\x86\x92\0"
"↓\0" "\xe2\x86\x93\0"
"↔\0" "\xe2\x86\x94\0"
"←\0" "\xe2\x87\x90\0"
"→\0" "\xe2\x87\x92\0"
"∀\0" "\xe2\x88\x80\0"
"∃\0" "\xe2\x88\x83\0"
"∇\0" "\xe2\x88\x87\0"
"∏\0" "\xe2\x88\x8f\0"
"∑\0" "\xe2\x88\x91\0"
"∧\0" "\xe2\x88\xa7\0"
"∨\0" "\xe2\x88\xa8\0"
"∫\0" "\xe2\x88\xab\0"
"≠\0" "\xe2\x89\xa0\0"
"≡\0" "\xe2\x89\xa1\0"
"⊕\0" "\xe2\x8a\x95\0"
"⊥\0" "\xe2\x8a\xa5\0"
;
@ -2615,6 +2584,7 @@ _escaped_char_match(const char *s, int *adv)
match = 1;
while ((*mc) && (*sc))
{
if ((unsigned char)*sc < (unsigned char)*mc) return NULL;
if (*sc != *mc) match = 0;
mc++;
sc++;
@ -2629,9 +2599,8 @@ _escaped_char_match(const char *s, int *adv)
return NULL;
}
static inline void
_append_escaped_char(Evas_Textblock_Cursor *cur, const char *s,
const char *s_end)
static inline const char *
_escaped_char_get(const char *s, const char *s_end)
{
const char *map_itr, *map_end;
@ -2641,14 +2610,36 @@ _append_escaped_char(Evas_Textblock_Cursor *cur, const char *s,
while (map_itr < map_end)
{
if (_is_eq_and_advance(s, s_end, &map_itr, map_end))
{
evas_textblock_cursor_text_append(cur, map_itr);
return;
}
return map_itr;
if (map_itr < map_itr)
_advance_after_end_of_string(&map_itr);
}
return NULL;
}
EAPI const char *
evas_textblock_escape_string_get(const char *escape)
{
/* &amp; -> & */
return _escaped_char_get(escape, escape + strlen(escape));
}
EAPI const char *
evas_textblock_string_escape_get(const char *string, int *len_ret)
{
/* & -> &amp; */
return _escaped_char_match(string, len_ret);
}
static inline void
_append_escaped_char(Evas_Textblock_Cursor *cur, const char *s,
const char *s_end)
{
const char *escape;
escape = _escaped_char_get(s, s_end);
if (escape)
evas_textblock_cursor_text_append(cur, escape);
}
static inline void
@ -3521,6 +3512,7 @@ evas_textblock_cursor_text_append(Evas_Textblock_Cursor *cur, const char *text)
free(o->markup_text);
o->markup_text = NULL;
}
_nodes_adjacent_merge(cur->obj, n);
evas_object_change(cur->obj);
}
@ -3595,6 +3587,7 @@ evas_textblock_cursor_text_prepend(Evas_Textblock_Cursor *cur, const char *text)
free(o->markup_text);
o->markup_text = NULL;
}
_nodes_adjacent_merge(cur->obj, n);
evas_object_change(cur->obj);
}
@ -3611,6 +3604,7 @@ evas_textblock_cursor_format_append(Evas_Textblock_Cursor *cur, const char *form
Evas_Object_Textblock_Node *n, *nc, *n2;
if (!cur) return;
if ((!format) || (format[0] == 0)) return;
o = (Evas_Object_Textblock *)(cur->obj->object_data);
nc = cur->node;
n = calloc(1, sizeof(Evas_Object_Textblock_Node));
@ -3688,6 +3682,7 @@ evas_textblock_cursor_format_prepend(Evas_Textblock_Cursor *cur, const char *for
Evas_Object_Textblock_Node *n, *nc, *n2;
if (!cur) return;
if ((!format) || (format[0] == 0)) return;
o = (Evas_Object_Textblock *)(cur->obj->object_data);
nc = cur->node;
n = calloc(1, sizeof(Evas_Object_Textblock_Node));