Loading...
Searching...
No Matches
ada::url_components Struct Reference

Stores byte offsets for URL components within a buffer. More...

`#include <url_components.h>`

## Public Member Functions

| url_components ()=default
| url_components (const url_components &u)=default
| url_components (url_components &&u) noexcept=default
url_components & | operator= (url_components &&u) noexcept=default
url_components & | operator= (const url_components &u)=default
| ~url_components ()=default
constexpr bool | check_offset_consistency () const noexcept
std::string | to_string () const

## Public Attributes

uint32_t | protocol_end {0}
uint32_t | username_end {0}
uint32_t | host_start {0}
uint32_t | host_end {0}
uint32_t | port {omitted}
uint32_t | pathname_start {0}
uint32_t | search_start {omitted}
uint32_t | hash_start {omitted}

## Static Public Attributes

static constexpr uint32_t | omitted = uint32_t(-1)

## Detailed Description

Stores byte offsets for URL components within a buffer.

The url_components struct uses 32-bit offsets to track the boundaries of each URL component within a single string buffer. This enables efficient component extraction without additional memory allocations.

Component layout in a URL:

https://user:pass@example.com:1234/foo/bar?baz#quux
| | | | ^^^^| | |
| | | | | | | `----- hash_start
| | | | | | `--------- search_start
| | | | | `----------------- pathname_start
| | | | `--------------------- port
| | | `----------------------- host_end
| | `---------------------------------- host_start
| `--------------------------------------- username_end
`--------------------------------------------- protocol_end
ada::url_components::pathname_start
uint32_t pathname_start
Definition url_components.h:69
ada::url_components::hash_start
uint32_t hash_start
Definition url_components.h:75
ada::url_components::port
uint32_t port
Definition url_components.h:66
ada::url_components::protocol_end
uint32_t protocol_end
Definition url_components.h:51
ada::url_components::search_start
uint32_t search_start
Definition url_components.h:72
ada::url_components::host_end
uint32_t host_end
Definition url_components.h:63
ada::url_components::username_end
uint32_t username_end
Definition url_components.h:57
ada::url_components::host_start
uint32_t host_start
Definition url_components.h:60

Note
  The 32-bit offsets limit URLs to 4GB in length.
  A value of omitted (UINT32_MAX) indicates the component is not present.

Definition at line 39 of file url_components.h.

## Constructor & Destructor Documentation

## url_components() [1/3]

ada::url_components::url_components | ( |  | ) |

default

Referenced by operator=(), operator=(), url_components(), and url_components().

## url_components() [2/3]

ada::url_components::url_components | ( | const url_components & | u | ) |

default

References url_components().

## url_components() [3/3]

ada::url_components::url_components | ( | url_components && | u | ) |

default noexcept

References url_components().

## ~url_components()

ada::url_components::~url_components | ( |  | ) |

default

## Member Function Documentation

## check_offset_consistency()

bool ada::url_components::check_offset_consistency | ( |  | ) | const

nodiscard constexpr noexcept

Validates that offsets are in ascending order and consistent. Useful for debugging to detect internal corruption.

Returns
  true if offsets are consistent, false otherwise.

https://user:pass@example.com:1234/foo/bar?baz#quux | | | | ^^^^| | | | | | | | | | ----- hash_start | | | | | | ------— search_start | | | | | ----------------- pathname_start | | | | ------------------— port | | | ----------------------- host_end | | -------------------------------— host_start | --------------------------------------- username_end ------------------------------------------— protocol_end

Definition at line 12 of file url_components-inl.h.

References hash_start, host_start, omitted, pathname_start, port, protocol_end, search_start, and username_end.

## operator=() [1/2]

url_components & ada::url_components::operator= | ( | const url_components & | u | ) |

default

References url_components().

## operator=() [2/2]

url_components & ada::url_components::operator= | ( | url_components && | u | ) |

default noexcept

References url_components().

## to_string()

std::string ada::url_components::to_string | ( |  | ) | const

nodiscard

Returns a JSON string representation of the offsets for debugging.

Returns
  A JSON-formatted string with all offset values.

Definition at line 9 of file url_components.cpp.

References hash_start, host_end, host_start, pathname_start, port, protocol_end, search_start, and username_end.

## Member Data Documentation

## hash_start

uint32_t ada::url_components::hash_start {omitted}

Offset of the '#' starting the fragment, or omitted if no fragment.

Definition at line 75 of file url_components.h.

Referenced by check_offset_consistency(), ada::url::get_components(), and to_string().

## host_end

uint32_t ada::url_components::host_end {0}

Offset of the end of the host.

Definition at line 63 of file url_components.h.

Referenced by ada::url::get_components(), and to_string().

## host_start

uint32_t ada::url_components::host_start {0}

Offset of the start of the host.

Definition at line 60 of file url_components.h.

Referenced by check_offset_consistency(), ada::url::get_components(), and to_string().

## omitted

uint32_t ada::url_components::omitted = uint32_t(-1)

static constexpr

Sentinel value indicating a component is not present.

Definition at line 41 of file url_components.h.

Referenced by check_offset_consistency(), ada::url_aggregator::clear_hash(), ada::url_aggregator::clear_port(), ada::url_aggregator::clear_search(), ada::url_aggregator::get_hash(), ada::url_aggregator::get_pathname(), ada::url_aggregator::get_pathname_length(), ada::url_aggregator::get_port(), ada::url_aggregator::get_search(), ada::url_aggregator::has_hash(), ada::url_aggregator::has_search(), ada::url_aggregator::set_hash(), ada::url_aggregator::set_pathname(), ada::url_aggregator::to_diagram(), ada::url_aggregator::to_string(), and ada::url_aggregator::validate().

## pathname_start

uint32_t ada::url_components::pathname_start {0}

Offset of the start of the pathname.

Definition at line 69 of file url_components.h.

Referenced by check_offset_consistency(), ada::url::get_components(), and to_string().

## port

uint32_t ada::url_components::port {omitted}

Port number, or omitted if no port is specified.

Definition at line 66 of file url_components.h.

Referenced by check_offset_consistency(), ada::url::get_components(), and to_string().

## protocol_end

uint32_t ada::url_components::protocol_end {0}

Offset of the end of the protocol/scheme (position of ':').

Definition at line 51 of file url_components.h.

Referenced by check_offset_consistency(), ada::url::get_components(), and to_string().

## search_start

uint32_t ada::url_components::search_start {omitted}

Offset of the '?' starting the query, or omitted if no query.

Definition at line 72 of file url_components.h.

Referenced by check_offset_consistency(), ada::url::get_components(), and to_string().

## username_end

uint32_t ada::url_components::username_end {0}

Offset of the end of the username. Initialized to 0 (not omitted) to simplify username/password getters.

Definition at line 57 of file url_components.h.

Referenced by check_offset_consistency(), ada::url::get_components(), and to_string().

The documentation for this struct was generated from the following files:

- include/ada/url_components.h
- include/ada/url_components-inl.h
- src/url_components.cpp