[#boost-urls-static_url-set_encoded_fragment-09]
= xref:boost.adoc[boost]::xref:boost/urls.adoc[urls]::xref:boost/urls/static_url.adoc[static&lowbar;url]::set&lowbar;encoded&lowbar;fragment
:relfileprefix: ../../../
:mrdocs:


Set the fragment&period;

== Synopsis


Declared in `&lt;https://www.github.com/boostorg/url/blob/develop/include/boost/url/static_url.hpp#L419[boost&sol;url&sol;static&lowbar;url&period;hpp]&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:boost/urls/static_url.adoc[static&lowbar;url]&
set&lowbar;encoded&lowbar;fragment(xref:boost/urls/pct_string_view.adoc[pct&lowbar;string&lowbar;view] s);
----

== Description


This function sets the fragment to the        specified string, which may contain        percent&hyphen;escapes and which may be empty&period;        An empty fragment is distinct from        having no fragment&period;        Escapes in the string are preserved,        and reserved characters in the string        are percent&hyphen;escaped in the result&period;


=== Example

[,cpp]
----
assert( url("?first=john&last=doe" ).set_encoded_fragment( "john%2Ddoe" ).fragment() == "john-doe" );
----

=== Postconditions

[,cpp]
----
this->has_fragment() == true && this->fragment() == decode_view( s )
----

=== Complexity

Linear in `this&hyphen;&gt;size() &plus; s&period;size()`&period;


=== Exception Safety

Strong guarantee&period;        Calls to allocate may throw&period;        Exceptions thrown on invalid input&period;


=== BNF

[,cpp]
----
fragment    = *( pchar / "/" / "?" )
----

=== Specification

* link:https://datatracker.ietf.org/doc/html/rfc3986#section-3.5[3&period;5&period;  Fragment]



== Exceptions


|===
| Name | Thrown on

| `system&lowbar;error`
| `s` contains an invalid percent&hyphen;encoding&period;


|===

== Parameters


|===
| Name | Description

| *s*
| The string to set&period;


|===

== See Also


xref:boost/urls/url_base/remove_fragment.adoc[remove&lowbar;fragment],            xref:boost/urls/url_base/set_fragment.adoc[set&lowbar;fragment]&period;






[.small]#Created with https://www.mrdocs.com[MrDocs]#
