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 = '\''; else if (s[0] == '`') endmatch = '\'';
else if (s[0] == '<') endmatch = '>'; else if (s[0] == '<') endmatch = '>';
if ((!strncasecmp((s + 1), "www.", 4)) || if ((casestartswith((s + 1), "www.")) ||
(!strncasecmp((s + 1), "ftp.", 4)) || (casestartswith((s + 1), "ftp.")) ||
(s[1] == '/')) (s[1] == '/'))
{ {
goback = EINA_FALSE; goback = EINA_FALSE;

View File

@ -54,10 +54,10 @@ theme_auto_reload_enable(Evas_Object *edje)
Eina_Bool Eina_Bool
link_is_protocol(const char *str) link_is_protocol(const char *str)
{ {
if ((!strncasecmp(str, "http://", 7))|| if (casestartswith(str, "http://") ||
(!strncasecmp(str, "https://", 8)) || casestartswith(str, "https://") ||
(!strncasecmp(str, "ftp://", 6)) || casestartswith(str, "ftp://") ||
(!strncasecmp(str, "file://", 7))) casestartswith(str, "file://"))
return EINA_TRUE; return EINA_TRUE;
return EINA_FALSE; return EINA_FALSE;
} }
@ -66,8 +66,8 @@ Eina_Bool
link_is_url(const char *str) link_is_url(const char *str)
{ {
if (link_is_protocol(str) || if (link_is_protocol(str) ||
(!strncasecmp(str, "www.", 4)) || casestartswith(str, "www.") ||
(!strncasecmp(str, "ftp.", 4))) casestartswith(str, "ftp."))
return EINA_TRUE; return EINA_TRUE;
return EINA_FALSE; 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_url(const char *str);
Eina_Bool link_is_email(const char *str); Eina_Bool link_is_email(const char *str);
#define casestartswith(str, constref) \
(!strncasecmp(str, constref, sizeof(constref) - 1))
#endif #endif