VIPA 0.1.0
Header-only C++23 SIMD-assisted IPv4/IPv6 text parser.
Loading...
Searching...
No Matches
parser.hxx
Go to the documentation of this file.
1#pragma once
2
3#include <optional>
4#include <string_view>
5
6#include "address.hxx"
7#include "ipv4.hxx"
8#include "ipv6.hxx"
9
10namespace llmx::vipa {
11
21[[nodiscard]] inline auto parse_address(std::string_view text) noexcept
22 -> std::optional<ParseResult> {
23 if (auto ipv4 = parse_ipv4(text)) {
24 return ParseResult{.address = *ipv4, .family = AddressFamily::IPv4};
25 }
26 if (auto ipv6 = parse_ipv6(text)) {
27 return ParseResult{.address = *ipv6, .family = AddressFamily::IPv6};
28 }
29 return std::nullopt;
30}
31
32} // namespace llmx::vipa
Definition address.hxx:8
auto parse_ipv4(std::string_view text) noexcept -> std::optional< IPv4Address >
Parse strict dotted-decimal IPv4 text.
Definition ipv4.hxx:129
auto parse_ipv6(std::string_view text) noexcept -> std::optional< IPv6Address >
Parse IPv6 text into sixteen network-order bytes.
Definition ipv6.hxx:283
auto parse_address(std::string_view text) noexcept -> std::optional< ParseResult >
Parse an IPv4 or IPv6 text address.
Definition parser.hxx:21
@ IPv4
Definition address.hxx:11
@ IPv6
Definition address.hxx:11
Address parser result with the concrete address family.
Definition address.hxx:41