[#boost-urls-static_url-set_user]
= xref:boost/urls/static_url/set_user.adoc[boost::urls::static&lowbar;url::set&lowbar;user]
:relfileprefix: ../../../
:mrdocs:

Set the user

== Synopsis

Declared in `&lt;https://www.github.com/boostorg/url/blob/develop/include/boost/url/static_url.hpp#L365[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;user(core::string&lowbar;view s);
----

== Description

This function sets the user part of the userinfo to the string&period; Any special or reserved characters in the string are automatically percent&hyphen;encoded&period;

== Example
[,cpp]
----
assert( url().set_user("john doe").encoded_userinfo() == "john%20doe" );
----
== Postconditions
[,cpp]
----
this->has_authority() == true && this->has_userinfo() == true
----
== 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]
----
userinfo      = [ [ user ] [ ':' password ] ]

user          = *( unreserved / pct-encoded / sub-delims )
password      = *( unreserved / pct-encoded / sub-delims / ":" )
----
== Specification
* https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1[]

== Return Value

`&ast;this`

== Parameters

[cols=2]
|===
| Name
| Description
| *s*
| The string to set&period;
|===

== See Also

xref:boost/urls/static_url/remove_password.adoc[`remove&lowbar;password`], xref:boost/urls/static_url/set_encoded_password.adoc[`set&lowbar;encoded&lowbar;password`], xref:boost/urls/static_url/set_encoded_user.adoc[`set&lowbar;encoded&lowbar;user`], xref:boost/urls/static_url/set_password.adoc[`set&lowbar;password`]&period;


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