move link_is_* to termiolink.c

This commit is contained in:
Boris Faure 2019-09-15 17:47:07 +02:00
parent 7bfef215b0
commit 259722a3f3
5 changed files with 56 additions and 54 deletions

View File

@ -9,6 +9,7 @@
#include "media.h"
#include "config.h"
#include "utils.h"
#include "termiolink.h"
typedef struct _Media Media;

View File

@ -42,8 +42,55 @@ _local_path_get(const Evas_Object *obj, const char *relpath)
return _cwd_path_get(obj, relpath);
}
static Eina_Bool
_is_file(const char *str)
Eina_Bool
link_is_protocol(const char *str)
{
const char *p = str;
int c = *p;
if (!isalpha(c))
return EINA_FALSE;
/* Try to follow RFC3986 a bit
* URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
* hier-part = "//" authority path-abempty
* [...] other stuff not taken into account
* scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
*/
do
{
p++;
c = *p;
}
while (isalpha(c) || (c == '.') || (c == '-') || (c == '+'));
return (p[0] == ':') && (p[1] == '/') && (p[2] == '/');
}
Eina_Bool
link_is_url(const char *str)
{
if (link_is_protocol(str) ||
casestartswith(str, "www.") ||
casestartswith(str, "ftp."))
return EINA_TRUE;
return EINA_FALSE;
}
Eina_Bool
link_is_email(const char *str)
{
const char *at = strchr(str, '@');
if (at && strchr(at + 1, '.'))
return EINA_TRUE;
if (casestartswith(str, "mailto:"))
return EINA_TRUE;
return EINA_FALSE;
}
Eina_Bool
link_is_file(const char *str)
{
switch (str[0])
{
@ -402,7 +449,7 @@ termio_link_find(const Evas_Object *obj, int cx, int cy,
out:
if (sb.len)
{
Eina_Bool is_file = _is_file(sb.buf);
Eina_Bool is_file = link_is_file(sb.buf);
if (is_file ||
link_is_email(sb.buf) ||

View File

@ -2,5 +2,10 @@
#define _TERMIO_LINK_H__ 1
char *termio_link_find(const Evas_Object *obj, int cx, int cy, int *x1r, int *y1r, int *x2r, int *y2r);
Eina_Bool link_is_protocol(const char *str);
Eina_Bool link_is_file(const char *str);
Eina_Bool link_is_url(const char *str);
Eina_Bool link_is_email(const char *str);
#endif

View File

@ -180,50 +180,3 @@ utils_need_scale_wizard(void)
return EINA_TRUE;
}
Eina_Bool
link_is_protocol(const char *str)
{
const char *p = str;
int c = *p;
if (!isalpha(c))
return EINA_FALSE;
/* Try to follow RFC3986 a bit
* URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
* hier-part = "//" authority path-abempty
* [...] other stuff not taken into account
* scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
*/
do
{
p++;
c = *p;
}
while (isalpha(c) || (c == '.') || (c == '-') || (c == '+'));
return (p[0] == ':') && (p[1] == '/') && (p[2] == '/');
}
Eina_Bool
link_is_url(const char *str)
{
if (link_is_protocol(str) ||
casestartswith(str, "www.") ||
casestartswith(str, "ftp."))
return EINA_TRUE;
return EINA_FALSE;
}
Eina_Bool
link_is_email(const char *str)
{
const char *at = strchr(str, '@');
if (at && strchr(at + 1, '.'))
return EINA_TRUE;
if (casestartswith(str, "mailto:"))
return EINA_TRUE;
return EINA_FALSE;
}

View File

@ -14,10 +14,6 @@ const char *theme_path_get(const char *name);
Eina_Bool homedir_get(char *buf, size_t size);
Eina_Bool utils_need_scale_wizard(void);
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))