Inkscape
Vector Graphics Editor
|
Represents an URI as per RFC 2396. More...
#include <uri.h>
Public Member Functions | |
URI () | |
URI (char const *preformed, char const *baseuri=nullptr) | |
Constructor from a C-style ASCII string. | |
URI (char const *preformed, URI const &baseuri) | |
bool | isOpaque () const |
Determines if the URI represented is an 'opaque' URI. | |
bool | isRelative () const |
Determines if the URI represented is 'relative' as per RFC 2396. | |
bool | isNetPath () const |
Determines if the relative URI represented is a 'net-path' as per RFC 2396. | |
bool | isRelativePath () const |
Determines if the relative URI represented is a 'relative-path' as per RFC 2396. | |
bool | isAbsolutePath () const |
Determines if the relative URI represented is a 'absolute-path' as per RFC 2396. | |
const char * | getScheme () const |
Return the scheme, e.g. "http", or NULL if this is not an absolute URI. | |
const char * | getPath () const |
Return the path. | |
const char * | getQuery () const |
Return the query, which is the part between "?" and the optional fragment hash ("#") | |
const char * | getFragment () const |
Return the fragment, which is everything after "#". | |
const char * | getOpaque () const |
For an opaque URI, return everything between the scheme colon (":") and the optional fragment hash ("#"). | |
std::string | toNativeFilename () const |
Convert this URI to a native filename. | |
std::string | str (char const *baseuri=nullptr) const |
Return the string representation of this URI. | |
std::string | getMimeType () const |
Get the MIME type (e.g. "image/png") | |
std::string | getContents () const |
Return the contents of the file. | |
std::string | cssStr (char const *baseuri=nullptr) const |
Return a CSS formatted url value. | |
bool | hasScheme (const char *scheme) const |
True if the scheme equals the given string (not case sensitive) | |
Static Public Member Functions | |
static URI | from_native_filename (char const *path) |
Construct a "file" URI from an absolute filename. | |
static URI | from_dirname (char const *path) |
URI of a local directory. | |
static URI | from_href_and_basedir (char const *href, char const *basedir) |
Convenience function for the common use case given a xlink:href attribute and a local directory as the document base. | |
Private Member Functions | |
void | init (xmlURI *ptr) |
xmlURI * | _xmlURIPtr () const |
Private Attributes | |
std::shared_ptr< xmlURI > | m_shared |
Represents an URI as per RFC 2396.
Typical use-cases of this class:
Wraps libxml2's URI functions. Direct usage of libxml2's C-API is discouraged if favor of Inkscape::URI. (At the time of writing this, no de-factor standard C++ URI library exists, so wrapping libxml2 seems like a good solution)
Implementation detail: Immutable type, copies share a ref-counted data pointer.
Inkscape::URI::URI | ( | ) |
Definition at line 45 of file uri.cpp.
References init().
Referenced by from_dirname(), and from_href_and_basedir().
|
explicit |
Constructor from a C-style ASCII string.
preformed | Properly quoted C-style string to be represented. |
baseuri | If preformed is a relative URI, use baseuri to make it absolute |
MalformedURIException |
|
explicit |
|
inlineprivate |
Definition at line 190 of file uri.h.
References m_shared.
Referenced by getFragment(), getOpaque(), getPath(), getQuery(), getScheme(), isAbsolutePath(), isNetPath(), isRelative(), isRelativePath(), and str().
|
inline |
Return a CSS formatted url value.
baseuri | Return a relative path if this URI shares protocol and host with baseuri |
Definition at line 176 of file uri.h.
References str().
Referenced by SPIFilter::get_value(), and SPItem::write().
|
static |
URI of a local directory.
The URI path will end with a slash.
Definition at line 197 of file uri.cpp.
References URI().
Referenced by from_href_and_basedir(), and Inkscape::Extension::Internal::OdfOutput::save().
|
static |
Convenience function for the common use case given a xlink:href attribute and a local directory as the document base.
Returns an empty URI on failure.
Definition at line 214 of file uri.cpp.
References from_dirname(), and URI().
Referenced by Inkscape::URIReference::attach(), SPImage::getURI(), and SPImage::readImage().
|
static |
Construct a "file" URI from an absolute filename.
Definition at line 190 of file uri.cpp.
References result.
Referenced by Inkscape::ColorProfile::createFromProfile().
std::string Inkscape::URI::getContents | ( | ) | const |
Return the contents of the file.
Glib::Error | If the URL can't be read |
Definition at line 318 of file uri.cpp.
References getPath(), hasScheme(), and str().
const gchar * Inkscape::URI::getFragment | ( | ) | const |
Return the fragment, which is everything after "#".
Definition at line 163 of file uri.cpp.
References _xmlURIPtr().
Referenced by Inkscape::URIReference::attach(), and toNativeFilename().
std::string Inkscape::URI::getMimeType | ( | ) | const |
Get the MIME type (e.g. "image/png")
Definition at line 297 of file uri.cpp.
References getPath(), and hasScheme().
const gchar * Inkscape::URI::getOpaque | ( | ) | const |
For an opaque URI, return everything between the scheme colon (":") and the optional fragment hash ("#").
For non-opaque URIs, return NULL.
Definition at line 167 of file uri.cpp.
References _xmlURIPtr(), getPath(), and isRelative().
Referenced by isOpaque().
const gchar * Inkscape::URI::getPath | ( | ) | const |
Return the path.
Example: "http://host/foo/bar?query#frag" -> "/foo/bar"
For an opaque URI, this is identical to getOpaque()
Definition at line 155 of file uri.cpp.
References _xmlURIPtr().
Referenced by Inkscape::URIReference::attach(), getContents(), getMimeType(), getOpaque(), isAbsolutePath(), and isRelativePath().
const gchar * Inkscape::URI::getQuery | ( | ) | const |
Return the query, which is the part between "?" and the optional fragment hash ("#")
Definition at line 159 of file uri.cpp.
References _xmlURIPtr().
Referenced by Inkscape::URIReference::attach().
const gchar * Inkscape::URI::getScheme | ( | ) | const |
Return the scheme, e.g. "http", or NULL
if this is not an absolute URI.
Definition at line 151 of file uri.cpp.
References _xmlURIPtr().
Referenced by hasScheme().
bool Inkscape::URI::hasScheme | ( | const char * | scheme | ) | const |
True if the scheme equals the given string (not case sensitive)
Definition at line 362 of file uri.cpp.
References getScheme().
Referenced by getContents(), and getMimeType().
|
inlineprivate |
bool Inkscape::URI::isAbsolutePath | ( | ) | const |
Determines if the relative URI represented is a 'absolute-path' as per RFC 2396.
An absolute-path is one that starts with a single "/".
true
if the URI is relative and an absolute-path, false
otherwise. Definition at line 143 of file uri.cpp.
References _xmlURIPtr(), getPath(), and isRelative().
bool Inkscape::URI::isNetPath | ( | ) | const |
Determines if the relative URI represented is a 'net-path' as per RFC 2396.
A net-path is one that starts with "//".
true
if the URI is relative and a net-path, false
otherwise. Definition at line 131 of file uri.cpp.
References _xmlURIPtr(), and isRelative().
bool Inkscape::URI::isOpaque | ( | ) | const |
bool Inkscape::URI::isRelative | ( | ) | const |
Determines if the URI represented is 'relative' as per RFC 2396.
Relative URI references are distinguished by not beginning with a scheme name.
true
if the URI is relative, false
if it is absolute. Definition at line 127 of file uri.cpp.
References _xmlURIPtr().
Referenced by getOpaque(), isAbsolutePath(), isNetPath(), and isRelativePath().
bool Inkscape::URI::isRelativePath | ( | ) | const |
Determines if the relative URI represented is a 'relative-path' as per RFC 2396.
A relative-path is one that starts with no slashes.
true
if the URI is relative and a relative-path, false
otherwise. Definition at line 135 of file uri.cpp.
References _xmlURIPtr(), getPath(), and isRelative().
std::string Inkscape::URI::str | ( | char const * | baseuri = nullptr | ) | const |
Return the string representation of this URI.
baseuri | Return a relative path if this URI shares protocol and host with baseuri |
Definition at line 281 of file uri.cpp.
References _xmlURIPtr(), and Inkscape::build_relative_uri().
Referenced by Inkscape::URIReference::attach(), cssStr(), getContents(), Inkscape::XML::rebase_hrefs(), Inkscape::Extension::Internal::OdfOutput::save(), toNativeFilename(), SPTRef::write(), SPBox3D::write(), SPGradient::write(), SPUse::write(), and SPConnEndPair::writeRepr().
std::string Inkscape::URI::toNativeFilename | ( | ) | const |
|
private |
Definition at line 186 of file uri.h.
Referenced by _xmlURIPtr(), and init().