casestartswith() macro to help strncasecmp() with static comparison.

SVN revision: 77654
This commit is contained in:
Gustavo Sverzut Barbieri 2012-10-09 15:14:24 +00:00
parent 2a0e0fd2b4
commit 08e164ce10
3 changed files with 11 additions and 8 deletions

View File

@ -83,8 +83,8 @@ _termio_link_find(Evas_Object *obj, int cx, int cy, int *x1r, int *y1r, int *x2r
else if (s[0] == '\'') endmatch = '\'';
else if (s[0] == '`') endmatch = '\'';
else if (s[0] == '<') endmatch = '>';
if ((!strncasecmp((s + 1), "www.", 4)) ||
(!strncasecmp((s + 1), "ftp.", 4)) ||
if ((casestartswith((s + 1), "www.")) ||
(casestartswith((s + 1), "ftp.")) ||
(s[1] == '/'))
{
goback = EINA_FALSE;

View File

@ -54,10 +54,10 @@ theme_auto_reload_enable(Evas_Object *edje)
Eina_Bool
link_is_protocol(const char *str)
{
if ((!strncasecmp(str, "http://", 7))||
(!strncasecmp(str, "https://", 8)) ||
(!strncasecmp(str, "ftp://", 6)) ||
(!strncasecmp(str, "file://", 7)))
if (casestartswith(str, "http://") ||
casestartswith(str, "https://") ||
casestartswith(str, "ftp://") ||
casestartswith(str, "file://"))
return EINA_TRUE;
return EINA_FALSE;
}
@ -66,8 +66,8 @@ Eina_Bool
link_is_url(const char *str)
{
if (link_is_protocol(str) ||
(!strncasecmp(str, "www.", 4)) ||
(!strncasecmp(str, "ftp.", 4)))
casestartswith(str, "www.") ||
casestartswith(str, "ftp."))
return EINA_TRUE;
return EINA_FALSE;
}

View File

@ -12,4 +12,7 @@ Eina_Bool link_is_protocol(const char *str);
Eina_Bool link_is_url(const char *str);
Eina_Bool link_is_email(const char *str);
#define casestartswith(str, constref) \
(!strncasecmp(str, constref, sizeof(constref) - 1))
#endif