[Xfce4-commits] <exo:master> Add function exo_str_looks_like_an_uri (bug #5710).
Nick Schermer
noreply at xfce.org
Fri Oct 16 21:38:01 CEST 2009
Updating branch refs/heads/master
to 839e9d1420dc8c916e1a375920853331fb022d83 (commit)
from f07a9c00c7167e66935ec7b58a41b20cae1ca9e7 (commit)
commit 839e9d1420dc8c916e1a375920853331fb022d83
Author: Nick Schermer <nick at xfce.org>
Date: Fri Oct 16 21:35:51 2009 +0200
Add function exo_str_looks_like_an_uri (bug #5710).
docs/reference/exo-sections.txt | 1 +
exo/exo-string.c | 29 +++++++++++++++++++++++++++++
exo/exo-string.h | 3 +++
3 files changed, 33 insertions(+), 0 deletions(-)
diff --git a/docs/reference/exo-sections.txt b/docs/reference/exo-sections.txt
index f2b6602..ab9e96c 100644
--- a/docs/reference/exo-sections.txt
+++ b/docs/reference/exo-sections.txt
@@ -449,6 +449,7 @@ exo_mount_point_list_configured
exo_str_elide_underscores
exo_str_is_equal
exo_str_is_empty
+exo_str_looks_like_an_uri
exo_str_replace
exo_strdup_strftime
exo_strndupv
diff --git a/exo/exo-string.c b/exo/exo-string.c
index 920f26c..d7a6bca 100644
--- a/exo/exo-string.c
+++ b/exo/exo-string.c
@@ -403,5 +403,34 @@ exo_strndupv (gchar **strv,
+/**
+ * exo_str_looks_like_an_uri:
+ * @str : an input string.
+ *
+ * Returns %TRUE if the @string looks like an URI
+ * according to RFC 2396, %FALSE otherwise.
+ *
+ * Since: 0.5.0
+ **/
+gboolean
+exo_str_looks_like_an_uri (const gchar *str)
+{
+ const gchar *s = str;
+
+ /* <scheme> starts with an alpha character */
+ if (g_ascii_isalpha (*s))
+ {
+ /* <scheme> continues with (alpha | digit | "+" | "-" | ".")* */
+ for (++s; g_ascii_isalnum (*s) || *s == '+' || *s == '-' || *s == '.'; ++s);
+
+ /* <scheme> must be followed by ":" */
+ return (*s == ':');
+ }
+
+ return FALSE;
+}
+
+
+
#define __EXO_STRING_C__
#include <exo/exo-aliasdef.c>
diff --git a/exo/exo-string.h b/exo/exo-string.h
index eebd8fa..b29b2ff 100644
--- a/exo/exo-string.h
+++ b/exo/exo-string.h
@@ -46,6 +46,9 @@ gchar *exo_strdup_strftime (const gchar *format,
gchar **exo_strndupv (gchar **strv,
guint num) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
+gboolean exo_str_looks_like_an_uri (const gchar *str);
+
+
/**
* exo_str_is_empty:
More information about the Xfce4-commits
mailing list