Skip to content

Instantly share code, notes, and snippets.

@vinniefalco
Created January 22, 2020 03:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vinniefalco/b05b6a21325d761d1960d8d319785483 to your computer and use it in GitHub Desktop.
Save vinniefalco/b05b6a21325d761d1960d8d319785483 to your computer and use it in GitHub Desktop.
//------------------------------------------------------
//
// fragment
//
//------------------------------------------------------
/** Return the fragment.
This function returns the fragment of the URL:
* If a fragment is present, it is returned in
decoded form without a leading hash mark ('#'),
otherwise:
* If there is no fragment, an empty string is
returned.
Note that if the URL contains a hash mark
followed by an empty query string, this
function still returns an empty string.
detect this case, use @ref fragment_part
instead.
@par Exception Safety
Strong guarantee.
Calls to allocate may throw.
@param a An optional allocator the returned
string will use. If this parameter is omitted,
the default allocator is used, and the return
type of the function becomes `std::string`.
@return A `std::basic_string` using the
specified allocator.
@see encoded_fragment, fragment_part
*/
template<
class Allocator =
std::allocator<char>>
string_type<Allocator>
fragment(
Allocator const& a = {}) const
{
return detail::decode(
encoded_fragment(), a);
}
/** Return the fragment.
This function returns the fragment of the URL:
* If a fragment is present, it is returned in
encoded form without a leading hash mark ('#'),
otherwise:
* If there is no fragment, an empty string is
returned.
Note that if the URL contains a hash mark
followed by an empty query string, this
function still returns an empty string.
detect this case, use @ref fragment_part
instead.
@par Exception Safety
No-throw guarantee.
@param a An optional allocator the returned
string will use. If this parameter is omitted,
the default allocator is used, and the return
type of the function becomes `std::string`.
@return A `std::basic_string` using the
specified allocator.
@see fragment, fragment_part
*/
BOOST_URL_DECL
string_view
encoded_fragment() const noexcept;
/** Return the fragment.
This function returns the fragment of the URL:
* If a fragment is present, it is returned
in encoded form including the leading hash
mark ('#'), otherwise:
* If there is no fragment, an empty string is
returned.
Note that if the URL contains a hash mark
followed by an empty query string, this
function returns "#".
@par Exception Safety
No-throw guarantee.
@see fragment, encoded_fragment
*/
BOOST_URL_DECL
string_view
fragment_part() const noexcept;
/** Set the fragment.
Sets the fragment of the URL to the specified
plain string:
@li If the string is empty, the fragment is
cleared including the leading hash mark ('#'),
otherwise:
@li If the string is not empty, the fragment
is set to given string, with a leading hash
mark added.
Any special or reserved characters in the
string are automatically percent-encoded.
@par Exception Safety
Strong guarantee.
Calls to allocate may throw.
@param s The string to set. This string may
contain any characters, including nulls.
*/
BOOST_URL_DECL
basic_value&
set_fragment(
string_view s);
/** Set the fragment.
Sets the fragment of the URL to the specified
encoded string:
@li If the string is empty, the fragment is
cleared including the leading hash mark ('#'),
otherwise:
@li If the string is not empty, the fragment
is set to given string, with a leading hash
mark added.
The string must meet the syntactic requirements
of <em>fragment</em> otherwise an exception is
thrown.
@par ABNF
@code
fragment = *( pchar / "/" / "?" )
@endcode
@par Exception Safety
Strong guarantee.
Calls to allocate may throw.
@param s The string to set.
@throws std::exception invalid string.
*/
BOOST_URL_DECL
basic_value&
set_encoded_fragment(
string_view s);
/** Set the fragment.
Sets the fragment of the URL to the specified
encoded string.
@li If the string is empty, the fragment is
cleared including the leading hash mark ('#'),
otherwise:
@li If the string is not empty, the fragment
is set to given string.
The string must meet the syntactic requirements
of <em>fragment-part</em> otherwise an exception
is thrown.
@par ABNF
@code
fragment-part = "#" *( pchar / "/" / "?" )
@endcode
@par Exception Safety
Strong guarantee.
Calls to allocate may throw.
@param s The string to set.
@throws std::exception invalid string.
*/
BOOST_URL_DECL
basic_value&
set_fragment_part(
string_view s);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment