[gnome-shell] Add function for finding urls in string
- From: Maxim Ermilov <mermilov src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] Add function for finding urls in string
- Date: Tue, 23 Nov 2010 23:41:11 +0000 (UTC)
commit 6a52deec7df0e9e9b8de0cee869bc2047c7c42a8
Author: Maxim Ermilov <zaspire rambler ru>
Date: Sun Oct 3 23:48:56 2010 +0400
Add function for finding urls in string
https://bugzilla.gnome.org/show_bug.cgi?id=610219
js/Makefile.am | 1 +
js/misc/utils.js | 19 +++++++++++++++++++
2 files changed, 20 insertions(+), 0 deletions(-)
---
diff --git a/js/Makefile.am b/js/Makefile.am
index b7632b4..47fac82 100644
--- a/js/Makefile.am
+++ b/js/Makefile.am
@@ -8,6 +8,7 @@ nobase_dist_js_DATA = \
misc/gnomeSession.js \
misc/params.js \
misc/telepathy.js \
+ misc/utils.js \
perf/core.js \
prefs/clockPreferences.js \
ui/altTab.js \
diff --git a/js/misc/utils.js b/js/misc/utils.js
new file mode 100644
index 0000000..0b7d6c0
--- /dev/null
+++ b/js/misc/utils.js
@@ -0,0 +1,19 @@
+/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
+
+/* http://daringfireball.net/2010/07/improved_regex_for_matching_urls */
+const _urlRegexp = /\b(([a-z][\w-]+:(\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)([^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'\".,<>?«»â??â??â??â??]))/gi;
+
+// findUrls:
+// @str: string to find URLs in
+//
+// Searches @str for URLs and returns an array of objects with %url
+// properties showing the matched URL string, and %pos properties indicating
+// the position within @str where the URL was found.
+//
+// Return value: the list of match objects, as described above
+function findUrls(str) {
+ let res = [], match;
+ while ((match = _urlRegexp.exec(str)))
+ res.push({ url: match[0], pos: match.index });
+ return res;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]