[#boost-urls-url_base-set_path]
= xref:boost.adoc[boost]::xref:boost/urls.adoc[urls]::xref:boost/urls/url_base.adoc[url&lowbar;base]::set&lowbar;path
:relfileprefix: ../../../
:mrdocs:

Set the path&period;

== Synopsis

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

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:boost/urls/url_base.adoc[url&lowbar;base]&
set&lowbar;path(core::string&lowbar;view s);
----

== Description

This function sets the path to the string, which may be empty&period; Reserved characters in the string are percent&hyphen;escaped in the result&period;

[NOTE]
====
The library may adjust the final result to ensure that no other parts of the URL are semantically affected&period;

====

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

====

== 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&hyphen;&gt;size() &plus; s&period;size()`&period;

== Exception Safety

Strong guarantee&period; Calls to allocate may throw&period;

== 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

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

== Return Value

`&ast;this`

== Parameters

[cols="1,4"]
|===
| Name| Description
| *s*
| The string to set&period;
|===

== See Also

xref:boost/urls/url_base/encoded_segments-0a.adoc[`encoded&lowbar;segments`], xref:boost/urls/url_base/segments-07.adoc[`segments`], xref:boost/urls/url_base/set_encoded_path.adoc[`set&lowbar;encoded&lowbar;path`], xref:boost/urls/url_base/set_path_absolute.adoc[`set&lowbar;path&lowbar;absolute`]&period;


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