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;
}
/* 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
_edje_format_param_parse(char *item, char **key, char **val)
{
@ -105,52 +81,14 @@ _edje_format_is_param(char *item)
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 *
_edje_format_reparse(Edje_File *edf, const char *str, Edje_Style_Tag **tag_ret)
{
char *s2, *item;
char *newstr = NULL;
Eina_Strbuf *txt;
char *s2, *item, *ret;
const char *s;
int newlen = 0, newalloc = 0;
txt = eina_strbuf_new();
s = str;
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))
{
char *tmpstr = NULL;
int tmplen = 0, tmpalloc = 0;
Eina_Strbuf *tmp;
tmpstr = _edje_strbuf_append2(tmpstr, "fonts/",
&tmplen, &tmpalloc);
tmpstr = _edje_strbuf_append2(tmpstr, val,
&tmplen, &tmpalloc);
(*tag_ret)->font = eina_stringshare_add(tmpstr);
free(tmpstr);
tmp = eina_strbuf_new();
eina_strbuf_append(tmp, "fonts/");
eina_strbuf_append(tmp, val);
(*tag_ret)->font = eina_stringshare_add(eina_strbuf_string_get(tmp));
eina_strbuf_free(tmp);
}
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 */
{
s2 = _edje_str_escape(item);
s2 = eina_str_escape(item);
if (s2)
{
if (newstr) newstr = _edje_strbuf_append2(newstr, " ", &newlen, &newalloc);
newstr = _edje_strbuf_append2(newstr, s2, &newlen, &newalloc);
if (eina_strbuf_length_get(txt)) eina_strbuf_append(txt, " ");
eina_strbuf_append(txt, s2);
free(s2);
}
}
@ -210,12 +146,14 @@ _edje_format_reparse(Edje_File *edf, const char *str, Edje_Style_Tag **tag_ret)
}
else
{
if (newstr) newstr = _edje_strbuf_append2(newstr, " ", &newlen, &newalloc);
newstr = _edje_strbuf_append2(newstr, item, &newlen, &newalloc);
if (eina_strbuf_length_get(txt)) eina_strbuf_append(txt, " ");
eina_strbuf_append(txt, 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
@ -234,8 +172,9 @@ _edje_textblock_style_all_update(Edje *ed)
{
Edje_Style_Tag *tag;
Edje_Text_Class *tc;
int bufalloc = 0, buflen = 0, found = 0;
char *buf = NULL, *fontset = NULL, *fontsource = NULL;
Eina_Strbuf *txt;
int found = 0;
char *fontset = NULL, *fontsource = NULL;
/* Make sure the style is already defined */
if (!stl->style) break;
@ -247,10 +186,11 @@ _edje_textblock_style_all_update(Edje *ed)
/* No text classes , goto next style */
if (!found) continue;
found = 0;
txt = eina_strbuf_new();
if (_edje_fontset_append)
fontset = _edje_str_escape(_edje_fontset_append);
fontsource = _edje_str_escape(ed->file->path);
fontset = eina_str_escape(_edje_fontset_append);
fontsource = eina_str_escape(ed->file->path);
/* Build the style from each tag */
EINA_LIST_FOREACH(stl->tags, ll, tag)
@ -258,8 +198,8 @@ _edje_textblock_style_all_update(Edje *ed)
if (!tag->key) continue;
/* Add Tag Key */
buf = _edje_strbuf_append2(buf, tag->key, &buflen, &bufalloc);
buf = _edje_strbuf_append2(buf, "='", &buflen, &bufalloc);
eina_strbuf_append(txt, tag->key);
eina_strbuf_append(txt, "='");
/* Configure fonts from text class if it exists */
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 */
buf = _edje_strbuf_append2(buf, tag->value, &buflen, &bufalloc);
eina_strbuf_append(txt, tag->value);
if (!strcmp(tag->key, "DEFAULT"))
{
if (fontset)
{
buf = _edje_strbuf_append2(buf, " ", &buflen, &bufalloc);
buf = _edje_strbuf_append2(buf, "font_fallbacks=", &buflen, &bufalloc);
buf = _edje_strbuf_append2(buf, fontset, &buflen, &bufalloc);
eina_strbuf_append(txt, " ");
eina_strbuf_append(txt, "font_fallbacks=");
eina_strbuf_append(txt, fontset);
}
buf = _edje_strbuf_append2(buf, " ", &buflen, &bufalloc);
buf = _edje_strbuf_append2(buf, "font_source=", &buflen, &bufalloc);
buf = _edje_strbuf_append2(buf, fontsource, &buflen, &bufalloc);
eina_strbuf_append(txt, " ");
eina_strbuf_append(txt, "font_source=");
eina_strbuf_append(txt, fontsource);
}
if (tag->font_size != 0)
{
@ -292,31 +232,31 @@ _edje_textblock_style_all_update(Edje *ed)
else
snprintf(font_size, sizeof(font_size), "%f", tag->font_size);
buf = _edje_strbuf_append2(buf, " ", &buflen, &bufalloc);
buf = _edje_strbuf_append2(buf, "font_size=", &buflen, &bufalloc);
buf = _edje_strbuf_append2(buf, font_size, &buflen, &bufalloc);
eina_strbuf_append(txt, " ");
eina_strbuf_append(txt, "font_size=");
eina_strbuf_append(txt, font_size);
}
/* Add font name last to save evas from multiple loads */
if (tag->font)
{
const char *f;
buf = _edje_strbuf_append2(buf, " ", &buflen, &bufalloc);
buf = _edje_strbuf_append2(buf, "font=", &buflen, &bufalloc);
eina_strbuf_append(txt, " ");
eina_strbuf_append(txt, "font=");
f = (found) ? tc->font : tag->font;
buf = _edje_strbuf_append2_escaped(buf, f, &buflen, &bufalloc);
eina_strbuf_append_escaped(txt, f);
}
found = 0;
buf = _edje_strbuf_append2(buf, "'", &buflen, &bufalloc);
eina_strbuf_append(txt, "'");
}
if (fontset) free(fontset);
if (fontsource) free(fontsource);
/* Configure the style */
evas_textblock_style_set(stl->style, buf);
free(buf);
evas_textblock_style_set(stl->style, eina_strbuf_string_get(txt));
eina_strbuf_free(txt);
}
}
@ -377,19 +317,19 @@ _edje_textblock_style_parse_and_fix(Edje_File *edf)
EINA_LIST_FOREACH(edf->styles, l, stl)
{
Edje_Style_Tag *tag;
char *buf = NULL;
int bufalloc = 0;
int buflen = 0;
Eina_Strbuf *txt;
char *fontset = NULL, *fontsource = NULL, *ts;
if (stl->style) break;
txt = eina_strbuf_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)
fontset = _edje_str_escape(_edje_fontset_append);
fontsource = _edje_str_escape(edf->path);
fontset = eina_str_escape(_edje_fontset_append);
fontsource = eina_str_escape(edf->path);
/* Build the style from each 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;
/* Add Tag Key */
buf = _edje_strbuf_append2(buf, tag->key, &buflen, &bufalloc);
buf = _edje_strbuf_append2(buf, "='", &buflen, &bufalloc);
eina_strbuf_append(txt, tag->key);
eina_strbuf_append(txt, "='");
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)
eina_stringshare_del(tag->value);
tag->value = eina_stringshare_add(ts);
buf = _edje_strbuf_append2(buf, tag->value, &buflen, &bufalloc);
eina_strbuf_append(txt, tag->value);
free(ts);
}
@ -416,38 +356,38 @@ _edje_textblock_style_parse_and_fix(Edje_File *edf)
{
if (fontset)
{
buf = _edje_strbuf_append2(buf, " ", &buflen, &bufalloc);
buf = _edje_strbuf_append2(buf, "font_fallbacks=", &buflen, &bufalloc);
buf = _edje_strbuf_append2(buf, fontset, &buflen, &bufalloc);
eina_strbuf_append(txt, " ");
eina_strbuf_append(txt, "font_fallbacks=");
eina_strbuf_append(txt, fontset);
}
buf = _edje_strbuf_append2(buf, " ", &buflen, &bufalloc);
buf = _edje_strbuf_append2(buf, "font_source=", &buflen, &bufalloc);
buf = _edje_strbuf_append2(buf, fontsource, &buflen, &bufalloc);
eina_strbuf_append(txt, " ");
eina_strbuf_append(txt, "font_source=");
eina_strbuf_append(txt, fontsource);
}
if (tag->font_size > 0)
{
char font_size[32];
snprintf(font_size, sizeof(font_size), "%f", tag->font_size);
buf = _edje_strbuf_append2(buf, " ", &buflen, &bufalloc);
buf = _edje_strbuf_append2(buf, "font_size=", &buflen, &bufalloc);
buf = _edje_strbuf_append2(buf, font_size, &buflen, &bufalloc);
eina_strbuf_append(txt, " ");
eina_strbuf_append(txt, "font_size=");
eina_strbuf_append(txt, font_size);
}
/* Add font name last to save evas from multiple loads */
if (tag->font)
{
buf = _edje_strbuf_append2(buf, " ", &buflen, &bufalloc);
buf = _edje_strbuf_append2(buf, "font=", &buflen, &bufalloc);
buf = _edje_strbuf_append2_escaped(buf, tag->font, &buflen, &bufalloc);
eina_strbuf_append(txt, " ");
eina_strbuf_append(txt, "font=");
eina_strbuf_append_escaped(txt, tag->font);
}
buf = _edje_strbuf_append2(buf, "'", &buflen, &bufalloc);
eina_strbuf_append(txt, "'");
}
if (fontset) free(fontset);
if (fontsource) free(fontsource);
/* Configure the style */
evas_textblock_style_set(stl->style, buf);
free(buf);
evas_textblock_style_set(stl->style, eina_strbuf_string_get(txt));
eina_strbuf_free(txt);
}
}