diff --git a/libxfce4util/libxfce4util.symbols b/libxfce4util/libxfce4util.symbols index 15f7fd6..b28cc79 100644 --- a/libxfce4util/libxfce4util.symbols +++ b/libxfce4util/libxfce4util.symbols @@ -122,6 +122,7 @@ xfce_putenv xfce_setenv xfce_unsetenv xfce_expand_variables G_GNUC_MALLOC +xfce_looks_like_an_uri #endif #endif diff --git a/libxfce4util/xfce-miscutils.c b/libxfce4util/xfce-miscutils.c index f52af5e..4d9165a 100644 --- a/libxfce4util/xfce-miscutils.c +++ b/libxfce4util/xfce-miscutils.c @@ -612,5 +612,34 @@ xfce_expand_variables (const gchar *command, +/** + * xfce_looks_like_an_uri: + * @string : an input string. + * + * Returns %TRUE if the @string looks like an URI + * according to RFC 2396, %FALSE otherwise. + * + * Since: 4.7 + **/ +gboolean +xfce_looks_like_an_uri (const gchar *string) +{ + const gchar *s = string; + + /* starts with an alpha character */ + if (g_ascii_isalpha (*s)) + { + /* continues with (alpha | digit | "+" | "-" | ".")* */ + for (++s; g_ascii_isalnum (*s) || *s == '+' || *s == '-' || *s == '.'; ++s); + + /* must be followed by ":" */ + return (*s == ':'); + } + + return FALSE; +} + + + #define __XFCE_MISCUTILS_C__ #include diff --git a/libxfce4util/xfce-miscutils.h b/libxfce4util/xfce-miscutils.h index d3b81bc..99cfedf 100644 --- a/libxfce4util/xfce-miscutils.h +++ b/libxfce4util/xfce-miscutils.h @@ -96,6 +96,8 @@ void xfce_unsetenv (const gchar *name); gchar* xfce_expand_variables (const gchar *command, gchar **envp) G_GNUC_MALLOC; +gboolean xfce_looks_like_an_uri (const gchar *string); + G_END_DECLS #endif /* __XFCE_MISCUTILS_H__ */