Inkscape
Vector Graphics Editor
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages Concepts
uri.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Authors:
4 * MenTaLguY <mental@rydia.net>
5 * Jon A. Cruz <jon@joncruz.org>
6 *
7 * Copyright (C) 2003 MenTaLguY
8 *
9 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
10 */
11
12#ifndef INKSCAPE_URI_H
13#define INKSCAPE_URI_H
14
15#include <libxml/uri.h>
16#include <libxml/xmlmemory.h>
17#include <memory>
18#include <string>
19
20namespace Inkscape {
21
36class URI {
37public:
38
39 /* Blank constructor */
40 URI();
41
50 explicit URI(char const *preformed, char const *baseuri = nullptr);
51 explicit URI(char const *preformed, URI const &baseuri);
52
58 bool isOpaque() const;
59
68 bool isRelative() const;
69
77 bool isNetPath() const;
78
86 bool isRelativePath() const;
87
95 bool isAbsolutePath() const;
96
100 const char *getScheme() const;
101
109 const char *getPath() const;
110
114 const char *getQuery() const;
115
119 const char *getFragment() const;
120
125 const char *getOpaque() const;
126
130 static URI from_native_filename(char const *path);
131
135 static URI from_dirname(char const *path);
136
141 static URI from_href_and_basedir(char const *href, char const *basedir);
142
150 std::string toNativeFilename() const;
151
157 std::string str(char const *baseuri = nullptr) const;
158
162 std::string getMimeType() const;
163
169 std::string getContents() const;
170
176 std::string cssStr(char const *baseuri = nullptr) const {
177 return "url(" + str(baseuri) + ")";
178 }
179
183 bool hasScheme(const char *scheme) const;
184
185private:
186 std::shared_ptr<xmlURI> m_shared;
187
188 void init(xmlURI *ptr) { m_shared.reset(ptr, xmlFreeURI); }
189
190 xmlURI *_xmlURIPtr() const { return m_shared.get(); }
191};
192
202std::string uri_to_iri(const char *uri);
203
204} /* namespace Inkscape */
205
206#endif
207
208/*
209 Local Variables:
210 mode:c++
211 c-file-style:"stroustrup"
212 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
213 indent-tabs-mode:nil
214 fill-column:99
215 End:
216*/
217// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
Represents an URI as per RFC 2396.
Definition uri.h:36
bool isOpaque() const
Determines if the URI represented is an 'opaque' URI.
Definition uri.cpp:123
const char * getQuery() const
Return the query, which is the part between "?" and the optional fragment hash ("#")
Definition uri.cpp:159
bool isRelative() const
Determines if the URI represented is 'relative' as per RFC 2396.
Definition uri.cpp:127
const char * getScheme() const
Return the scheme, e.g. "http", or NULL if this is not an absolute URI.
Definition uri.cpp:151
bool hasScheme(const char *scheme) const
True if the scheme equals the given string (not case sensitive)
Definition uri.cpp:362
std::string cssStr(char const *baseuri=nullptr) const
Return a CSS formatted url value.
Definition uri.h:176
xmlURI * _xmlURIPtr() const
Definition uri.h:190
URI(char const *preformed, char const *baseuri=nullptr)
Constructor from a C-style ASCII string.
static URI from_dirname(char const *path)
URI of a local directory.
Definition uri.cpp:197
std::shared_ptr< xmlURI > m_shared
Definition uri.h:186
std::string getMimeType() const
Get the MIME type (e.g. "image/png")
Definition uri.cpp:297
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 th...
Definition uri.cpp:214
std::string str(char const *baseuri=nullptr) const
Return the string representation of this URI.
Definition uri.cpp:281
const char * getPath() const
Return the path.
Definition uri.cpp:155
std::string toNativeFilename() const
Convert this URI to a native filename.
Definition uri.cpp:177
bool isNetPath() const
Determines if the relative URI represented is a 'net-path' as per RFC 2396.
Definition uri.cpp:131
const char * getOpaque() const
For an opaque URI, return everything between the scheme colon (":") and the optional fragment hash ("...
Definition uri.cpp:167
bool isAbsolutePath() const
Determines if the relative URI represented is a 'absolute-path' as per RFC 2396.
Definition uri.cpp:143
static URI from_native_filename(char const *path)
Construct a "file" URI from an absolute filename.
Definition uri.cpp:190
void init(xmlURI *ptr)
Definition uri.h:188
const char * getFragment() const
Return the fragment, which is everything after "#".
Definition uri.cpp:163
std::string getContents() const
Return the contents of the file.
Definition uri.cpp:318
bool isRelativePath() const
Determines if the relative URI represented is a 'relative-path' as per RFC 2396.
Definition uri.cpp:135
Helper class to stream background task notifications as a series of messages.
std::string uri_to_iri(const char *uri)
Unescape the UTF-8 parts of the given URI.
Definition uri.cpp:427