Parse a parameter from a byte slice that contains exactly one parameter. This is an internal method that assumes the input has already been split into a single parameter (e.g., by CmdlineIterBytes).
(input: &'a [u8])
| 484 | /// This is an internal method that assumes the input has already been |
| 485 | /// split into a single parameter (e.g., by CmdlineIterBytes). |
| 486 | fn parse_internal(input: &'a [u8]) -> Option<Self> { |
| 487 | // *Only* the first and last double quotes are stripped |
| 488 | let dequoted_input = input.strip_prefix(b"\"").unwrap_or(input); |
| 489 | let dequoted_input = dequoted_input.strip_suffix(b"\"").unwrap_or(dequoted_input); |
| 490 | |
| 491 | let equals = dequoted_input.iter().position(|b| *b == b'='); |
| 492 | |
| 493 | match equals { |
| 494 | None => Some(Self { |
| 495 | parameter: input, |
| 496 | key: ParameterKey(dequoted_input), |
| 497 | value: None, |
| 498 | }), |
| 499 | Some(i) => { |
| 500 | let (key, mut value) = dequoted_input.split_at(i); |
| 501 | let key = ParameterKey(key); |
| 502 | |
| 503 | // skip `=`, we know it's the first byte because we |
| 504 | // found it above |
| 505 | value = &value[1..]; |
| 506 | |
| 507 | // If there is a quote after the equals, skip it. If |
| 508 | // there was a closing quote at the end of the value, |
| 509 | // we would have already removed it in |
| 510 | // `dequoted_input` above |
| 511 | value = value.strip_prefix(b"\"").unwrap_or(value); |
| 512 | |
| 513 | Some(Self { |
| 514 | parameter: input, |
| 515 | key, |
| 516 | value: Some(value), |
| 517 | }) |
| 518 | } |
| 519 | } |
| 520 | } |
| 521 | |
| 522 | /// Returns the key part of the parameter |
| 523 | pub fn key(&self) -> ParameterKey<'a> { |
nothing calls this directly
no test coverage detected