summaryrefslogtreecommitdiff
path: root/glib/src/uriutils.hg
blob: 6ef99d964daf5a3c52ba95a6a1bdd3ceea23a3b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* Copyright (C) 2002 The gtkmm Development Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

_DEFS(glibmm,glib)

#include <string>

namespace Glib
{

/** @defgroup UriUtils URI Utilities
 * Various uri-related functions.
 */

//Note that the illegal_characters and reserved_chars_allowed parameters are bytes and may not be UTF-8 
//so they are not Glib::ustring. See http://bugzilla.gnome.org/show_bug.cgi?id=508773

/** Unescapes a whole escaped string.
 * If any of the characters in @a illegal_characters or the character zero appears
 * as an escaped character in @a escaped_string then that is an error and an empty string 
 * will be returned. This is useful it you want to avoid, for instance, having a
 * slash being expanded in an escaped path element, which might confuse pathname
 * handling.
 *
 * @param escaped_string An escaped string to be unescaped.
 * @param illegal_characters An optional string of illegal characters not to be allowed.
 * @result An unescaped version of @a escaped_string.
 * 
 * @ingroup UriUtils
 * @newin{2,16}
 */
std::string uri_unescape_string(const std::string& escaped_string, const std::string& illegal_characters = std::string());

//TODO: Use iterator? 
//char *   g_uri_unescape_segment      (const char *escaped_string,
//				      const char *escaped_string_end,
//				      const char *illegal_characters);

/** Gets the scheme portion of a URI. RFC 3986 decodes the scheme as:
 * @code
 * URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ] 
 * @endcode
 * Common schemes include "file", "http", "svn+ssh", etc.
 *
 * @param uri
 * @result The "Scheme" component of the URI, or an empty string on error. 
 * 
 * @ingroup UriUtils
 * @newin{2,16}
 */
std::string uri_parse_scheme(const std::string& uri);

/** Escapes a string for use in a URI.
 *
 * Normally all characters that are not "unreserved" (i.e. ASCII alphanumerical
 * characters plus dash, dot, underscore and tilde) are escaped.
 * But if you specify characters in @a reserved_chars_allowed they are not
 * escaped. This is useful for the "reserved" characters in the URI
 * specification, since those are allowed unescaped in some portions of
 * a URI.
 *
 * @param unescaped The unescaped input string.
 * @param reserved_chars_allowed A string of reserved characters that are allowed to be used.
 * @param allow_utf8 true if the result can include UTF-8 characters.
 * @result An escaped version of @a unescaped.
 *
 * @ingroup UriUtils
 * @newin{2,16}
 */
std::string uri_escape_string(const std::string& unescaped, const std::string& reserved_chars_allowed = std::string(), bool allow_utf8 = true);

} // namespace Glib