summaryrefslogtreecommitdiffstats
path: root/src/object
diff options
context:
space:
mode:
authorThomas Holder <thomas@thomas-holder.de>2018-12-09 14:45:59 +0000
committerThomas Holder <thomas@thomas-holder.de>2018-12-09 14:45:59 +0000
commitd1d8708fb64eab13695177aab5214e1db4564b24 (patch)
tree17b0fdeaa7568509f7b8ede606be25cf3746014c /src/object
parentfix poppler 0.72.0 build (diff)
downloadinkscape-d1d8708fb64eab13695177aab5214e1db4564b24.tar.gz
inkscape-d1d8708fb64eab13695177aab5214e1db4564b24.zip
fix, test, and document more Inkscape::URI methods
Diffstat (limited to 'src/object')
-rw-r--r--src/object/uri.cpp56
-rw-r--r--src/object/uri.h33
2 files changed, 69 insertions, 20 deletions
diff --git a/src/object/uri.cpp b/src/object/uri.cpp
index 94546aec7..5f9a38c5f 100644
--- a/src/object/uri.cpp
+++ b/src/object/uri.cpp
@@ -141,9 +141,29 @@ void URI::Impl::unreference() {
}
}
+// From RFC 2396:
+//
+// URI-reference = [ absoluteURI | relativeURI ] [ "#" fragment ]
+// absoluteURI = scheme ":" ( hier_part | opaque_part )
+// relativeURI = ( net_path | abs_path | rel_path ) [ "?" query ]
+//
+// hier_part = ( net_path | abs_path ) [ "?" query ]
+// opaque_part = uric_no_slash *uric
+//
+// uric_no_slash = unreserved | escaped | ";" | "?" | ":" | "@" |
+// "&" | "=" | "+" | "$" | ","
+//
+// net_path = "//" authority [ abs_path ]
+// abs_path = "/" path_segments
+// rel_path = rel_segment [ abs_path ]
+//
+// rel_segment = 1*( unreserved | escaped |
+// ";" | "@" | "&" | "=" | "+" | "$" | "," )
+//
+// authority = server | reg_name
+
bool URI::Impl::isOpaque() const {
- bool opq = !isRelative() && (getOpaque() != nullptr);
- return opq;
+ return getOpaque() != nullptr;
}
bool URI::Impl::isRelative() const {
@@ -151,33 +171,23 @@ bool URI::Impl::isRelative() const {
}
bool URI::Impl::isNetPath() const {
- bool isNet = false;
- if ( isRelative() )
- {
- const gchar *path = getPath();
- isNet = path && path[0] == '\\' && path[1] == '\\';
- }
- return isNet;
+ return isRelative() && _uri->server;
}
bool URI::Impl::isRelativePath() const {
- bool isRel = false;
- if ( isRelative() )
- {
+ if (isRelative() && !_uri->server) {
const gchar *path = getPath();
- isRel = !path || path[0] != '\\';
+ return path && path[0] != '/';
}
- return isRel;
+ return false;
}
bool URI::Impl::isAbsolutePath() const {
- bool isAbs = false;
- if ( isRelative() )
- {
+ if (isRelative() && !_uri->server) {
const gchar *path = getPath();
- isAbs = path && path[0] == '\\'&& path[1] != '\\';
+ return path && path[0] == '/';
}
- return isAbs;
+ return false;
}
const gchar *URI::Impl::getScheme() const {
@@ -197,7 +207,13 @@ const gchar *URI::Impl::getFragment() const {
}
const gchar *URI::Impl::getOpaque() const {
- return (gchar *)_uri->opaque;
+ if (!isRelative() && !_uri->server) {
+ const gchar *path = getPath();
+ if (path && path[0] != '/') {
+ return path;
+ }
+ }
+ return nullptr;
}
/*
diff --git a/src/object/uri.h b/src/object/uri.h
index 98b1a21af..f8a28726b 100644
--- a/src/object/uri.h
+++ b/src/object/uri.h
@@ -103,18 +103,46 @@ public:
*/
bool isAbsolutePath() const { return _impl->isAbsolutePath(); }
+ /**
+ * Return the scheme, e.g.\ "http", or \c NULL if this is not an absolute URI.
+ */
const char *getScheme() const { return _impl->getScheme(); }
+ /**
+ * Return the path.
+ *
+ * Example: "http://host/foo/bar?query#frag" -> "/foo/bar"
+ *
+ * For an opaque URI, this is identical to getOpaque()
+ */
const char *getPath() const { return _impl->getPath(); }
+ /**
+ * Return the query, which is the part between "?" and the optional fragment hash ("#")
+ */
const char *getQuery() const { return _impl->getQuery(); }
+ /**
+ * Return the fragment, which is everything after "#"
+ */
const char *getFragment() const { return _impl->getFragment(); }
+ /**
+ * For an opaque URI, return everything between the scheme colon (":") and the optional
+ * fragment hash ("#"). For non-opaque URIs, return NULL.
+ */
const char *getOpaque() const { return _impl->getOpaque(); }
+ /**
+ * @deprecated The regular constructor auto-detects UTF-8 characters and percent-encodes them.
+ *
+ * @todo remove, it's unused and percent-encodes most reserved characters, including "%", ":", "?", "#".
+ */
static URI fromUtf8( char const* path );
+ /**
+ * Construct a "file" URI from an absolute filename.
+ */
static URI from_native_filename(char const *path);
/**
@@ -128,6 +156,11 @@ public:
*/
static URI from_href_and_basedir(char const *href, char const *basedir);
+ /**
+ * @deprecated Use ::toNativeFilename() instead
+ *
+ * @todo remove
+ */
const std::string getFullPath(std::string const &base) const;
/**