diff options
Diffstat (limited to 'src/object')
| -rw-r--r-- | src/object/uri.cpp | 60 | ||||
| -rw-r--r-- | src/object/uri.h | 34 |
2 files changed, 37 insertions, 57 deletions
diff --git a/src/object/uri.cpp b/src/object/uri.cpp index 52fc9dc44..2604ee640 100644 --- a/src/object/uri.cpp +++ b/src/object/uri.cpp @@ -43,8 +43,7 @@ static bool uri_needs_escaping(char const *uri) } URI::URI() { - const gchar *in = ""; - _impl = Impl::create(xmlParseURI(in)); + _impl = Impl::create(xmlCreateURI()); } URI::URI(const URI &uri) { @@ -162,52 +161,52 @@ void URI::Impl::unreference() { // // authority = server | reg_name -bool URI::Impl::isOpaque() const { +bool URI::isOpaque() const { return getOpaque() != nullptr; } -bool URI::Impl::isRelative() const { - return !_uri->scheme; +bool URI::isRelative() const { + return !_xmlURIPtr()->scheme; } -bool URI::Impl::isNetPath() const { - return isRelative() && _uri->server; +bool URI::isNetPath() const { + return isRelative() && _xmlURIPtr()->server; } -bool URI::Impl::isRelativePath() const { - if (isRelative() && !_uri->server) { +bool URI::isRelativePath() const { + if (isRelative() && !_xmlURIPtr()->server) { const gchar *path = getPath(); return path && path[0] != '/'; } return false; } -bool URI::Impl::isAbsolutePath() const { - if (isRelative() && !_uri->server) { +bool URI::isAbsolutePath() const { + if (isRelative() && !_xmlURIPtr()->server) { const gchar *path = getPath(); return path && path[0] == '/'; } return false; } -const gchar *URI::Impl::getScheme() const { - return (gchar *)_uri->scheme; +const gchar *URI::getScheme() const { + return (gchar *)_xmlURIPtr()->scheme; } -const gchar *URI::Impl::getPath() const { - return (gchar *)_uri->path; +const gchar *URI::getPath() const { + return (gchar *)_xmlURIPtr()->path; } -const gchar *URI::Impl::getQuery() const { - return (gchar *)_uri->query; +const gchar *URI::getQuery() const { + return (gchar *)_xmlURIPtr()->query; } -const gchar *URI::Impl::getFragment() const { - return (gchar *)_uri->fragment; +const gchar *URI::getFragment() const { + return (gchar *)_xmlURIPtr()->fragment; } -const gchar *URI::Impl::getOpaque() const { - if (!isRelative() && !_uri->server) { +const gchar *URI::getOpaque() const { + if (!isRelative() && !_xmlURIPtr()->server) { const gchar *path = getPath(); if (path && path[0] != '/') { return path; @@ -262,18 +261,6 @@ URI URI::from_href_and_basedir(char const *href, char const *basedir) } } -gchar *URI::Impl::toString() const { - xmlChar *string = xmlSaveUri(_uri); - if (string) { - /* hand the string off to glib memory management */ - gchar *glib_string = g_strdup((gchar *)string); - xmlFree(string); - return glib_string; - } else { - return nullptr; - } -} - /** * Replacement for buggy xmlBuildRelativeURI * https://gitlab.gnome.org/GNOME/libxml2/merge_requests/12 @@ -335,14 +322,15 @@ static std::string build_relative_uri(char const *uri, char const *base) std::string URI::str(char const *baseuri) const { std::string s; - gchar *save = _impl->toString(); - if (save) { + auto saveuri = xmlSaveUri(_xmlURIPtr()); + if (saveuri) { + auto save = (const char *)saveuri; if (baseuri && baseuri[0]) { s = build_relative_uri(save, baseuri); } else { s = save; } - g_free(save); + xmlFree(saveuri); } return s; } diff --git a/src/object/uri.h b/src/object/uri.h index d3cbae596..ba9ee72b4 100644 --- a/src/object/uri.h +++ b/src/object/uri.h @@ -64,7 +64,7 @@ public: * * @return \c true if the URI is opaque, \c false if hierarchial. */ - bool isOpaque() const { return _impl->isOpaque(); } + bool isOpaque() const; /** * Determines if the URI represented is 'relative' as per RFC 2396. @@ -74,7 +74,7 @@ public: * * @return \c true if the URI is relative, \c false if it is absolute. */ - bool isRelative() const { return _impl->isRelative(); } + bool isRelative() const; /** * Determines if the relative URI represented is a 'net-path' as per RFC 2396. @@ -83,7 +83,7 @@ public: * * @return \c true if the URI is relative and a net-path, \c false otherwise. */ - bool isNetPath() const { return _impl->isNetPath(); } + bool isNetPath() const; /** * Determines if the relative URI represented is a 'relative-path' as per RFC 2396. @@ -92,7 +92,7 @@ public: * * @return \c true if the URI is relative and a relative-path, \c false otherwise. */ - bool isRelativePath() const { return _impl->isRelativePath(); } + bool isRelativePath() const; /** * Determines if the relative URI represented is a 'absolute-path' as per RFC 2396. @@ -101,12 +101,12 @@ public: * * @return \c true if the URI is relative and an absolute-path, \c false otherwise. */ - bool isAbsolutePath() const { return _impl->isAbsolutePath(); } + bool isAbsolutePath() const; /** * Return the scheme, e.g.\ "http", or \c NULL if this is not an absolute URI. */ - const char *getScheme() const { return _impl->getScheme(); } + const char *getScheme() const; /** * Return the path. @@ -115,23 +115,23 @@ public: * * For an opaque URI, this is identical to getOpaque() */ - const char *getPath() const { return _impl->getPath(); } + const char *getPath() const; /** * Return the query, which is the part between "?" and the optional fragment hash ("#") */ - const char *getQuery() const { return _impl->getQuery(); } + const char *getQuery() const; /** * Return the fragment, which is everything after "#" */ - const char *getFragment() const { return _impl->getFragment(); } + const char *getFragment() const; /** * 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(); } + const char *getOpaque() const; /** * Construct a "file" URI from an absolute filename. @@ -201,24 +201,16 @@ private: void reference(); void unreference(); - bool isOpaque() const; - bool isRelative() const; - bool isNetPath() const; - bool isRelativePath() const; - bool isAbsolutePath() const; - const char *getScheme() const; - const char *getPath() const; - const char *getQuery() const; - const char *getFragment() const; - const char *getOpaque() const; - char *toString() const; private: Impl(xmlURIPtr uri); ~Impl(); int _refcount; + public: xmlURIPtr _uri; }; Impl *_impl; + + xmlURIPtr _xmlURIPtr() const { return _impl->_uri; } }; } /* namespace Inkscape */ |
