summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2019-09-15 17:47:07 +0200
committerBoris Faure <billiob@gmail.com>2019-09-15 17:47:07 +0200
commit259722a3f325972a38065583dbfd62e10ca7b300 (patch)
tree006858d98190984734d1a1e2cb50e95ba7cbc24e /src
parent7bfef215b0305d04579d98ba14c59f953163512c (diff)
move link_is_* to termiolink.c
Diffstat (limited to 'src')
-rw-r--r--src/bin/media.c1
-rw-r--r--src/bin/termiolink.c53
-rw-r--r--src/bin/termiolink.h5
-rw-r--r--src/bin/utils.c47
-rw-r--r--src/bin/utils.h4
5 files changed, 56 insertions, 54 deletions
diff --git a/src/bin/media.c b/src/bin/media.c
index bda41b4..b43eadc 100644
--- a/src/bin/media.c
+++ b/src/bin/media.c
@@ -9,6 +9,7 @@
9#include "media.h" 9#include "media.h"
10#include "config.h" 10#include "config.h"
11#include "utils.h" 11#include "utils.h"
12#include "termiolink.h"
12 13
13typedef struct _Media Media; 14typedef struct _Media Media;
14 15
diff --git a/src/bin/termiolink.c b/src/bin/termiolink.c
index 9b28648..58a7a6a 100644
--- a/src/bin/termiolink.c
+++ b/src/bin/termiolink.c
@@ -42,8 +42,55 @@ _local_path_get(const Evas_Object *obj, const char *relpath)
42 return _cwd_path_get(obj, relpath); 42 return _cwd_path_get(obj, relpath);
43} 43}
44 44
45static Eina_Bool 45Eina_Bool
46_is_file(const char *str) 46link_is_protocol(const char *str)
47{
48 const char *p = str;
49 int c = *p;
50
51 if (!isalpha(c))
52 return EINA_FALSE;
53
54 /* Try to follow RFC3986 a bit
55 * URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
56 * hier-part = "//" authority path-abempty
57 * [...] other stuff not taken into account
58 * scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
59 */
60
61 do
62 {
63 p++;
64 c = *p;
65 }
66 while (isalpha(c) || (c == '.') || (c == '-') || (c == '+'));
67
68 return (p[0] == ':') && (p[1] == '/') && (p[2] == '/');
69}
70
71Eina_Bool
72link_is_url(const char *str)
73{
74 if (link_is_protocol(str) ||
75 casestartswith(str, "www.") ||
76 casestartswith(str, "ftp."))
77 return EINA_TRUE;
78 return EINA_FALSE;
79}
80
81Eina_Bool
82link_is_email(const char *str)
83{
84 const char *at = strchr(str, '@');
85 if (at && strchr(at + 1, '.'))
86 return EINA_TRUE;
87 if (casestartswith(str, "mailto:"))
88 return EINA_TRUE;
89 return EINA_FALSE;
90}
91
92Eina_Bool
93link_is_file(const char *str)
47{ 94{
48 switch (str[0]) 95 switch (str[0])
49 { 96 {
@@ -402,7 +449,7 @@ termio_link_find(const Evas_Object *obj, int cx, int cy,
402out: 449out:
403 if (sb.len) 450 if (sb.len)
404 { 451 {
405 Eina_Bool is_file = _is_file(sb.buf); 452 Eina_Bool is_file = link_is_file(sb.buf);
406 453
407 if (is_file || 454 if (is_file ||
408 link_is_email(sb.buf) || 455 link_is_email(sb.buf) ||
diff --git a/src/bin/termiolink.h b/src/bin/termiolink.h
index bb97d90..7228119 100644
--- a/src/bin/termiolink.h
+++ b/src/bin/termiolink.h
@@ -2,5 +2,10 @@
2#define _TERMIO_LINK_H__ 1 2#define _TERMIO_LINK_H__ 1
3 3
4char *termio_link_find(const Evas_Object *obj, int cx, int cy, int *x1r, int *y1r, int *x2r, int *y2r); 4char *termio_link_find(const Evas_Object *obj, int cx, int cy, int *x1r, int *y1r, int *x2r, int *y2r);
5Eina_Bool link_is_protocol(const char *str);
6Eina_Bool link_is_file(const char *str);
7Eina_Bool link_is_url(const char *str);
8Eina_Bool link_is_email(const char *str);
9
5 10
6#endif 11#endif
diff --git a/src/bin/utils.c b/src/bin/utils.c
index 9232676..3c5c2d6 100644
--- a/src/bin/utils.c
+++ b/src/bin/utils.c
@@ -180,50 +180,3 @@ utils_need_scale_wizard(void)
180 180
181 return EINA_TRUE; 181 return EINA_TRUE;
182} 182}
183
184Eina_Bool
185link_is_protocol(const char *str)
186{
187 const char *p = str;
188 int c = *p;
189
190 if (!isalpha(c))
191 return EINA_FALSE;
192
193 /* Try to follow RFC3986 a bit
194 * URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
195 * hier-part = "//" authority path-abempty
196 * [...] other stuff not taken into account
197 * scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
198 */
199
200 do
201 {
202 p++;
203 c = *p;
204 }
205 while (isalpha(c) || (c == '.') || (c == '-') || (c == '+'));
206
207 return (p[0] == ':') && (p[1] == '/') && (p[2] == '/');
208}
209
210Eina_Bool
211link_is_url(const char *str)
212{
213 if (link_is_protocol(str) ||
214 casestartswith(str, "www.") ||
215 casestartswith(str, "ftp."))
216 return EINA_TRUE;
217 return EINA_FALSE;
218}
219
220Eina_Bool
221link_is_email(const char *str)
222{
223 const char *at = strchr(str, '@');
224 if (at && strchr(at + 1, '.'))
225 return EINA_TRUE;
226 if (casestartswith(str, "mailto:"))
227 return EINA_TRUE;
228 return EINA_FALSE;
229}
diff --git a/src/bin/utils.h b/src/bin/utils.h
index 01318ba..ca5b6e7 100644
--- a/src/bin/utils.h
+++ b/src/bin/utils.h
@@ -14,10 +14,6 @@ const char *theme_path_get(const char *name);
14Eina_Bool homedir_get(char *buf, size_t size); 14Eina_Bool homedir_get(char *buf, size_t size);
15Eina_Bool utils_need_scale_wizard(void); 15Eina_Bool utils_need_scale_wizard(void);
16 16
17Eina_Bool link_is_protocol(const char *str);
18Eina_Bool link_is_url(const char *str);
19Eina_Bool link_is_email(const char *str);
20
21#define casestartswith(str, constref) \ 17#define casestartswith(str, constref) \
22 (!strncasecmp(str, constref, sizeof(constref) - 1)) 18 (!strncasecmp(str, constref, sizeof(constref) - 1))
23 19