Skip to content

(std::net::parser): Fix capitalization of IP version names #82826

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions library/std/src/net/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ macro_rules! impl_helper {
impl_helper! { u8 u16 u32 }

struct Parser<'a> {
// parsing as ASCII, so can use byte array
// Parsing as ASCII, so can use byte array.
state: &'a [u8],
}

Expand All @@ -44,7 +44,7 @@ impl<'a> Parser<'a> {
Parser { state: input.as_bytes() }
}

/// Run a parser, and restore the pre-parse state if it fails
/// Run a parser, and restore the pre-parse state if it fails.
fn read_atomically<T, F>(&mut self, inner: F) -> Option<T>
where
F: FnOnce(&mut Parser<'_>) -> Option<T>,
Expand Down Expand Up @@ -126,7 +126,7 @@ impl<'a> Parser<'a> {
})
}

/// Read an IPv4 address
/// Read an IPv4 address.
fn read_ipv4_addr(&mut self) -> Option<Ipv4Addr> {
self.read_atomically(|p| {
let mut groups = [0; 4];
Expand All @@ -139,18 +139,18 @@ impl<'a> Parser<'a> {
})
}

/// Read an IPV6 Address
/// Read an IPv6 Address.
fn read_ipv6_addr(&mut self) -> Option<Ipv6Addr> {
/// Read a chunk of an ipv6 address into `groups`. Returns the number
/// Read a chunk of an IPv6 address into `groups`. Returns the number
/// of groups read, along with a bool indicating if an embedded
/// trailing ipv4 address was read. Specifically, read a series of
/// colon-separated ipv6 groups (0x0000 - 0xFFFF), with an optional
/// trailing embedded ipv4 address.
/// trailing IPv4 address was read. Specifically, read a series of
/// colon-separated IPv6 groups (0x0000 - 0xFFFF), with an optional
/// trailing embedded IPv4 address.
fn read_groups(p: &mut Parser<'_>, groups: &mut [u16]) -> (usize, bool) {
let limit = groups.len();

for (i, slot) in groups.iter_mut().enumerate() {
// Try to read a trailing embedded ipv4 address. There must be
// Try to read a trailing embedded IPv4 address. There must be
// at least two groups left.
if i < limit - 1 {
let ipv4 = p.read_separator(':', i, |p| p.read_ipv4_addr());
Expand Down Expand Up @@ -188,8 +188,8 @@ impl<'a> Parser<'a> {
return None;
}

// read `::` if previous code parsed less than 8 groups
// `::` indicates one or more groups of 16 bits of zeros
// Read `::` if previous code parsed less than 8 groups.
// `::` indicates one or more groups of 16 bits of zeros.
p.read_given_char(':')?;
p.read_given_char(':')?;

Expand All @@ -206,28 +206,28 @@ impl<'a> Parser<'a> {
})
}

/// Read an IP Address, either IPV4 or IPV6.
/// Read an IP Address, either IPv4 or IPv6.
fn read_ip_addr(&mut self) -> Option<IpAddr> {
self.read_ipv4_addr().map(IpAddr::V4).or_else(move || self.read_ipv6_addr().map(IpAddr::V6))
}

/// Read a : followed by a port in base 10.
/// Read a `:` followed by a port in base 10.
fn read_port(&mut self) -> Option<u16> {
self.read_atomically(|p| {
p.read_given_char(':')?;
p.read_number(10, None)
})
}

/// Read a % followed by a scope id in base 10.
/// Read a `%` followed by a scope ID in base 10.
fn read_scope_id(&mut self) -> Option<u32> {
self.read_atomically(|p| {
p.read_given_char('%')?;
p.read_number(10, None)
})
}

/// Read an IPV4 address with a port
/// Read an IPv4 address with a port.
fn read_socket_addr_v4(&mut self) -> Option<SocketAddrV4> {
self.read_atomically(|p| {
let ip = p.read_ipv4_addr()?;
Expand All @@ -236,7 +236,7 @@ impl<'a> Parser<'a> {
})
}

/// Read an IPV6 address with a port
/// Read an IPv6 address with a port.
fn read_socket_addr_v6(&mut self) -> Option<SocketAddrV6> {
self.read_atomically(|p| {
p.read_given_char('[')?;
Expand Down