internal strbuf -> eina_strbuf

SVN revision: 45951
This commit is contained in:
Sebastian Dransfeld 2010-02-06 21:43:12 +00:00
parent 522a0ab1ab
commit fc5f097b7e
1 changed files with 65 additions and 125 deletions

View File

@ -13,30 +13,6 @@ _edje_font_is_embedded(Edje_File *edf, char *font __UNUSED__)
return 1; return 1;
} }
/* Put a \ before and Space( ), \ or ' in a string.
* A newly allocated string is returned.
*/
static char *
_edje_str_escape(const char *str)
{
char *s2, *d;
const char *s;
s2 = malloc((strlen(str) * 2) + 1);
if (!s2) return NULL;
for (s = str, d = s2; *s != 0; s++, d++)
{
if ((*s == ' ') || (*s == '\\') || (*s == '\''))
{
*d = '\\';
d++;
}
*d = *s;
}
*d = 0;
return s2;
}
static void static void
_edje_format_param_parse(char *item, char **key, char **val) _edje_format_param_parse(char *item, char **key, char **val)
{ {
@ -105,52 +81,14 @@ _edje_format_is_param(char *item)
return 0; return 0;
} }
static char *
_edje_strbuf_append2(char *s, const char *s2, int *len, int *alloc)
{
int l2, tlen;
if (!s2) return s;
l2 = strlen(s2);
tlen = *len + l2;
if (tlen > *alloc)
{
char *ts;
int talloc;
talloc = ((tlen + 31) >> 5) << 5;
ts = realloc(s, talloc + 1);
if (!ts) return s;
s = ts;
*alloc = talloc;
}
strcpy(s + *len, s2);
*len = tlen;
return s;
}
static char *
_edje_strbuf_append2_escaped(char *s, const char *unescaped_s, int *len, int *alloc)
{
char *tmp;
tmp = _edje_str_escape(unescaped_s);
if (!tmp) return s;
s = _edje_strbuf_append2(s, tmp, len, alloc);
free(tmp);
return s;
}
static char * static char *
_edje_format_reparse(Edje_File *edf, const char *str, Edje_Style_Tag **tag_ret) _edje_format_reparse(Edje_File *edf, const char *str, Edje_Style_Tag **tag_ret)
{ {
char *s2, *item; Eina_Strbuf *txt;
char *newstr = NULL; char *s2, *item, *ret;
const char *s; const char *s;
int newlen = 0, newalloc = 0;
txt = eina_strbuf_new();
s = str; s = str;
while ((item = _edje_format_parse(&s))) while ((item = _edje_format_parse(&s)))
{ {
@ -179,15 +117,13 @@ _edje_format_reparse(Edje_File *edf, const char *str, Edje_Style_Tag **tag_ret)
{ {
if (_edje_font_is_embedded(edf, val)) if (_edje_font_is_embedded(edf, val))
{ {
char *tmpstr = NULL; Eina_Strbuf *tmp;
int tmplen = 0, tmpalloc = 0;
tmpstr = _edje_strbuf_append2(tmpstr, "fonts/", tmp = eina_strbuf_new();
&tmplen, &tmpalloc); eina_strbuf_append(tmp, "fonts/");
tmpstr = _edje_strbuf_append2(tmpstr, val, eina_strbuf_append(tmp, val);
&tmplen, &tmpalloc); (*tag_ret)->font = eina_stringshare_add(eina_strbuf_string_get(tmp));
(*tag_ret)->font = eina_stringshare_add(tmpstr); eina_strbuf_free(tmp);
free(tmpstr);
} }
else else
{ {
@ -197,11 +133,11 @@ _edje_format_reparse(Edje_File *edf, const char *str, Edje_Style_Tag **tag_ret)
} }
else /* Otherwise add to tag buffer */ else /* Otherwise add to tag buffer */
{ {
s2 = _edje_str_escape(item); s2 = eina_str_escape(item);
if (s2) if (s2)
{ {
if (newstr) newstr = _edje_strbuf_append2(newstr, " ", &newlen, &newalloc); if (eina_strbuf_length_get(txt)) eina_strbuf_append(txt, " ");
newstr = _edje_strbuf_append2(newstr, s2, &newlen, &newalloc); eina_strbuf_append(txt, s2);
free(s2); free(s2);
} }
} }
@ -210,12 +146,14 @@ _edje_format_reparse(Edje_File *edf, const char *str, Edje_Style_Tag **tag_ret)
} }
else else
{ {
if (newstr) newstr = _edje_strbuf_append2(newstr, " ", &newlen, &newalloc); if (eina_strbuf_length_get(txt)) eina_strbuf_append(txt, " ");
newstr = _edje_strbuf_append2(newstr, item, &newlen, &newalloc); eina_strbuf_append(txt, item);
} }
free(item); free(item);
} }
return newstr; ret = eina_strbuf_string_remove(txt);
eina_strbuf_free(txt);
return ret;
} }
/* Update all evas_styles which are in an edje /* Update all evas_styles which are in an edje
@ -234,8 +172,9 @@ _edje_textblock_style_all_update(Edje *ed)
{ {
Edje_Style_Tag *tag; Edje_Style_Tag *tag;
Edje_Text_Class *tc; Edje_Text_Class *tc;
int bufalloc = 0, buflen = 0, found = 0; Eina_Strbuf *txt;
char *buf = NULL, *fontset = NULL, *fontsource = NULL; int found = 0;
char *fontset = NULL, *fontsource = NULL;
/* Make sure the style is already defined */ /* Make sure the style is already defined */
if (!stl->style) break; if (!stl->style) break;
@ -247,10 +186,11 @@ _edje_textblock_style_all_update(Edje *ed)
/* No text classes , goto next style */ /* No text classes , goto next style */
if (!found) continue; if (!found) continue;
found = 0; found = 0;
txt = eina_strbuf_new();
if (_edje_fontset_append) if (_edje_fontset_append)
fontset = _edje_str_escape(_edje_fontset_append); fontset = eina_str_escape(_edje_fontset_append);
fontsource = _edje_str_escape(ed->file->path); fontsource = eina_str_escape(ed->file->path);
/* Build the style from each tag */ /* Build the style from each tag */
EINA_LIST_FOREACH(stl->tags, ll, tag) EINA_LIST_FOREACH(stl->tags, ll, tag)
@ -258,8 +198,8 @@ _edje_textblock_style_all_update(Edje *ed)
if (!tag->key) continue; if (!tag->key) continue;
/* Add Tag Key */ /* Add Tag Key */
buf = _edje_strbuf_append2(buf, tag->key, &buflen, &bufalloc); eina_strbuf_append(txt, tag->key);
buf = _edje_strbuf_append2(buf, "='", &buflen, &bufalloc); eina_strbuf_append(txt, "='");
/* Configure fonts from text class if it exists */ /* Configure fonts from text class if it exists */
if ((tc = _edje_text_class_find(ed, tag->text_class))) if ((tc = _edje_text_class_find(ed, tag->text_class)))
@ -269,19 +209,19 @@ _edje_textblock_style_all_update(Edje *ed)
} }
/* Add and Ha`ndle tag parsed data */ /* Add and Ha`ndle tag parsed data */
buf = _edje_strbuf_append2(buf, tag->value, &buflen, &bufalloc); eina_strbuf_append(txt, tag->value);
if (!strcmp(tag->key, "DEFAULT")) if (!strcmp(tag->key, "DEFAULT"))
{ {
if (fontset) if (fontset)
{ {
buf = _edje_strbuf_append2(buf, " ", &buflen, &bufalloc); eina_strbuf_append(txt, " ");
buf = _edje_strbuf_append2(buf, "font_fallbacks=", &buflen, &bufalloc); eina_strbuf_append(txt, "font_fallbacks=");
buf = _edje_strbuf_append2(buf, fontset, &buflen, &bufalloc); eina_strbuf_append(txt, fontset);
} }
buf = _edje_strbuf_append2(buf, " ", &buflen, &bufalloc); eina_strbuf_append(txt, " ");
buf = _edje_strbuf_append2(buf, "font_source=", &buflen, &bufalloc); eina_strbuf_append(txt, "font_source=");
buf = _edje_strbuf_append2(buf, fontsource, &buflen, &bufalloc); eina_strbuf_append(txt, fontsource);
} }
if (tag->font_size != 0) if (tag->font_size != 0)
{ {
@ -292,31 +232,31 @@ _edje_textblock_style_all_update(Edje *ed)
else else
snprintf(font_size, sizeof(font_size), "%f", tag->font_size); snprintf(font_size, sizeof(font_size), "%f", tag->font_size);
buf = _edje_strbuf_append2(buf, " ", &buflen, &bufalloc); eina_strbuf_append(txt, " ");
buf = _edje_strbuf_append2(buf, "font_size=", &buflen, &bufalloc); eina_strbuf_append(txt, "font_size=");
buf = _edje_strbuf_append2(buf, font_size, &buflen, &bufalloc); eina_strbuf_append(txt, font_size);
} }
/* Add font name last to save evas from multiple loads */ /* Add font name last to save evas from multiple loads */
if (tag->font) if (tag->font)
{ {
const char *f; const char *f;
buf = _edje_strbuf_append2(buf, " ", &buflen, &bufalloc); eina_strbuf_append(txt, " ");
buf = _edje_strbuf_append2(buf, "font=", &buflen, &bufalloc); eina_strbuf_append(txt, "font=");
f = (found) ? tc->font : tag->font; f = (found) ? tc->font : tag->font;
buf = _edje_strbuf_append2_escaped(buf, f, &buflen, &bufalloc); eina_strbuf_append_escaped(txt, f);
} }
found = 0; found = 0;
buf = _edje_strbuf_append2(buf, "'", &buflen, &bufalloc); eina_strbuf_append(txt, "'");
} }
if (fontset) free(fontset); if (fontset) free(fontset);
if (fontsource) free(fontsource); if (fontsource) free(fontsource);
/* Configure the style */ /* Configure the style */
evas_textblock_style_set(stl->style, buf); evas_textblock_style_set(stl->style, eina_strbuf_string_get(txt));
free(buf); eina_strbuf_free(txt);
} }
} }
@ -377,19 +317,19 @@ _edje_textblock_style_parse_and_fix(Edje_File *edf)
EINA_LIST_FOREACH(edf->styles, l, stl) EINA_LIST_FOREACH(edf->styles, l, stl)
{ {
Edje_Style_Tag *tag; Edje_Style_Tag *tag;
char *buf = NULL; Eina_Strbuf *txt;
int bufalloc = 0;
int buflen = 0;
char *fontset = NULL, *fontsource = NULL, *ts; char *fontset = NULL, *fontsource = NULL, *ts;
if (stl->style) break; if (stl->style) break;
txt = eina_strbuf_new();
stl->style = evas_textblock_style_new(); stl->style = evas_textblock_style_new();
evas_textblock_style_set(stl->style, buf); evas_textblock_style_set(stl->style, NULL);
if (_edje_fontset_append) if (_edje_fontset_append)
fontset = _edje_str_escape(_edje_fontset_append); fontset = eina_str_escape(_edje_fontset_append);
fontsource = _edje_str_escape(edf->path); fontsource = eina_str_escape(edf->path);
/* Build the style from each tag */ /* Build the style from each tag */
EINA_LIST_FOREACH(stl->tags, ll, tag) EINA_LIST_FOREACH(stl->tags, ll, tag)
@ -397,8 +337,8 @@ _edje_textblock_style_parse_and_fix(Edje_File *edf)
if (!tag->key) continue; if (!tag->key) continue;
/* Add Tag Key */ /* Add Tag Key */
buf = _edje_strbuf_append2(buf, tag->key, &buflen, &bufalloc); eina_strbuf_append(txt, tag->key);
buf = _edje_strbuf_append2(buf, "='", &buflen, &bufalloc); eina_strbuf_append(txt, "='");
ts = _edje_format_reparse(edf, tag->value, &(tag)); ts = _edje_format_reparse(edf, tag->value, &(tag));
@ -408,7 +348,7 @@ _edje_textblock_style_parse_and_fix(Edje_File *edf)
if (eet_dictionary_string_check(eet_dictionary_get(edf->ef), tag->value) == 0) if (eet_dictionary_string_check(eet_dictionary_get(edf->ef), tag->value) == 0)
eina_stringshare_del(tag->value); eina_stringshare_del(tag->value);
tag->value = eina_stringshare_add(ts); tag->value = eina_stringshare_add(ts);
buf = _edje_strbuf_append2(buf, tag->value, &buflen, &bufalloc); eina_strbuf_append(txt, tag->value);
free(ts); free(ts);
} }
@ -416,38 +356,38 @@ _edje_textblock_style_parse_and_fix(Edje_File *edf)
{ {
if (fontset) if (fontset)
{ {
buf = _edje_strbuf_append2(buf, " ", &buflen, &bufalloc); eina_strbuf_append(txt, " ");
buf = _edje_strbuf_append2(buf, "font_fallbacks=", &buflen, &bufalloc); eina_strbuf_append(txt, "font_fallbacks=");
buf = _edje_strbuf_append2(buf, fontset, &buflen, &bufalloc); eina_strbuf_append(txt, fontset);
} }
buf = _edje_strbuf_append2(buf, " ", &buflen, &bufalloc); eina_strbuf_append(txt, " ");
buf = _edje_strbuf_append2(buf, "font_source=", &buflen, &bufalloc); eina_strbuf_append(txt, "font_source=");
buf = _edje_strbuf_append2(buf, fontsource, &buflen, &bufalloc); eina_strbuf_append(txt, fontsource);
} }
if (tag->font_size > 0) if (tag->font_size > 0)
{ {
char font_size[32]; char font_size[32];
snprintf(font_size, sizeof(font_size), "%f", tag->font_size); snprintf(font_size, sizeof(font_size), "%f", tag->font_size);
buf = _edje_strbuf_append2(buf, " ", &buflen, &bufalloc); eina_strbuf_append(txt, " ");
buf = _edje_strbuf_append2(buf, "font_size=", &buflen, &bufalloc); eina_strbuf_append(txt, "font_size=");
buf = _edje_strbuf_append2(buf, font_size, &buflen, &bufalloc); eina_strbuf_append(txt, font_size);
} }
/* Add font name last to save evas from multiple loads */ /* Add font name last to save evas from multiple loads */
if (tag->font) if (tag->font)
{ {
buf = _edje_strbuf_append2(buf, " ", &buflen, &bufalloc); eina_strbuf_append(txt, " ");
buf = _edje_strbuf_append2(buf, "font=", &buflen, &bufalloc); eina_strbuf_append(txt, "font=");
buf = _edje_strbuf_append2_escaped(buf, tag->font, &buflen, &bufalloc); eina_strbuf_append_escaped(txt, tag->font);
} }
buf = _edje_strbuf_append2(buf, "'", &buflen, &bufalloc); eina_strbuf_append(txt, "'");
} }
if (fontset) free(fontset); if (fontset) free(fontset);
if (fontsource) free(fontsource); if (fontsource) free(fontsource);
/* Configure the style */ /* Configure the style */
evas_textblock_style_set(stl->style, buf); evas_textblock_style_set(stl->style, eina_strbuf_string_get(txt));
free(buf); eina_strbuf_free(txt);
} }
} }