boost::urls::static_url::set_path :: Boost Libraries Documentation

# boost::urls::static_url::set_path

Set the path.

## Synopsis

Declared in `<boost/url/static_url.hpp>`

    static_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.

| The library may adjust the final result to ensure that no other parts of the URL are semantically affected.

| This function does not encode '/' chars, which are unreserved for paths but reserved for path segments. If a path segment should include encoded '/'s to differentiate it from path separators, the functions `set_encoded_path` or `segments` should be used instead.

## Example

    url u( "http://www.example.com" );

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

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

## Complexity

Linear in `this‐>size() + s.size()`.

## Exception Safety

Strong guarantee. Calls to allocate may throw.

## BNF

    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

- 3.3. Path (rfc3986)

## Return Value

`*this`

## Parameters

Name | Description
s | The string to set.

## See Also

`encoded_segments`, `segments`, `set_encoded_path`, `set_path_absolute`.

Created with MrDocs