diff options
author | Marcus Lundblad <ml@update.uu.se> | 2021-11-01 22:42:04 +0100 |
---|---|---|
committer | Marcus Lundblad <ml@update.uu.se> | 2021-11-07 22:29:50 +0100 |
commit | 967dfef2760e7c22e7299bba896c2053ad8db583 (patch) | |
tree | 685a67cc9b56fd25fd841d2dc3e5a8168953d10e /src | |
parent | a3335a650d1ca0e39a6339b29fac79568e7346b1 (diff) | |
download | gnome-maps-967dfef2760e7c22e7299bba896c2053ad8db583.tar.gz |
uris: Add function to parse maps: URIs
Adds a function to parse a search query
from a maps: URI.
See https://www.iana.org/assignments/uri-schemes/prov/maps
Diffstat (limited to 'src')
-rw-r--r-- | src/uris.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/uris.js b/src/uris.js index 96b698f2..97ed4c42 100644 --- a/src/uris.js +++ b/src/uris.js @@ -22,6 +22,9 @@ const _ = imports.gettext.gettext; const GLib = imports.gi.GLib; +const Soup = imports.gi.Soup; + +const Utils = imports.utils; // Matches URLs for OpenStreetMap (for addressing objects or coordinates) const OSM_URL_REGEX = new RegExp(/https?:\/\/(www\.)?openstreetmap\.org./); @@ -102,3 +105,22 @@ function parseAsObjectURL(url) { return []; } + +/** + * For maps: URIs, return the search query string if a valid URI + * otherwise null. + */ +function parseMapsURI(uri) { + let path = uri.substring('maps:'.length); + let [param, value] = Utils.splitAtFirst(path, '='); + + if (param === 'q') { + try { + return Soup.uri_decode(value); + } catch (error) { + return null; + } + } else { + return null; + } +} |