:relfileprefix: ../../../
[#boost-urls-url-set_path]

= xref:boost.adoc[pass:[boost]]::xref:boost/urls.adoc[pass:[urls]]::xref:boost/urls/url.adoc[pass:[url]]::set_path


Set the path.


== Synopsis

Declared in header `<https://www.github.com/boostorg/url/blob/develop/include/boost/url/url.hpp#L465[boost/url/url.hpp,window=blank_]>`

[source,cpp,subs="verbatim,macros,-callouts"]
----
xref:boost/urls/url.adoc[url]&
set_path(core::string_view s);
----

== Description


This function sets the path to the
string, which may be empty.
Reserved characters in the string are
percent-escaped in the result.
[NOTE]

The library may adjust the final result
to ensure that no other parts of the url
is semantically affected.
[NOTE]

This function does not encode '&sol;' chars, which
are unreserved for paths but reserved for
path segments. If a path segment should include
encoded '&sol;'s to differentiate it from path separators,
the functions
xref:boost/urls/url_base/set_encoded_path.adoc[set_encoded_path]
or
xref:boost/urls/url_base/segments-04.adoc[segments]
should be used instead.

=== Example
[,cpp]
----
url u( "http://www.example.com" );

u.set_path( "path/to/file.txt" );

assert( u.path() == "/path/to/file.txt" );
----

=== Complexity

Linear in `this-&gt;size() + s.size()`.

=== Exception Safety

Strong guarantee.
Calls to allocate may throw.

=== BNF
[,cpp]
----
path          = path-abempty    ; begins with "/" or is empty
              / path-absolute   ; begins with "/" but not "//"
              / path-noscheme   ; begins with a non-colon segment
              / path-rootless   ; begins with a segment
              / path-empty      ; zero characters

path-abempty  = *( "/" segment )
path-absolute = "/" [ segment-nz *( "/" segment ) ]
path-noscheme = segment-nz-nc *( "/" segment )
path-rootless = segment-nz *( "/" segment )
path-empty    = 0<pchar>
----

=== Specification

* link:https://datatracker.ietf.org/doc/html/rfc3986#section-3.3[3.3.  Path (rfc3986)]





== Parameters

|===
| Name | Description 

| *s*
| 
The string to set.

|===




== See Also


xref:boost/urls/url_base/encoded_segments-0e5.adoc[encoded_segments]
,
xref:boost/urls/url_base/segments-04.adoc[segments]
,
xref:boost/urls/url_base/set_encoded_path.adoc[set_encoded_path]
,
xref:boost/urls/url_base/set_path_absolute.adoc[set_path_absolute]
.



