misc improvements
This commit is contained in:
parent
8778d42e78
commit
0905642feb
4 changed files with 10 additions and 9 deletions
|
@ -237,11 +237,11 @@ impl<'event> GitConfig<'event> {
|
||||||
/// This function will return an error if the key is not in the requested
|
/// This function will return an error if the key is not in the requested
|
||||||
/// section and subsection, or if the section and subsection do not exist.
|
/// section and subsection, or if the section and subsection do not exist.
|
||||||
pub fn get_raw_value<'lookup>(
|
pub fn get_raw_value<'lookup>(
|
||||||
&'event self,
|
&self,
|
||||||
section_name: &'lookup str,
|
section_name: &'lookup str,
|
||||||
subsection_name: Option<&'lookup str>,
|
subsection_name: Option<&'lookup str>,
|
||||||
key: &'lookup str,
|
key: &'lookup str,
|
||||||
) -> Result<Cow<'event, [u8]>, GitConfigError<'lookup>> {
|
) -> Result<Cow<'_, [u8]>, GitConfigError<'lookup>> {
|
||||||
// Note: cannot wrap around the raw_multi_value method because we need
|
// Note: cannot wrap around the raw_multi_value method because we need
|
||||||
// to guarantee that the highest section id is used (so that we follow
|
// to guarantee that the highest section id is used (so that we follow
|
||||||
// the "last one wins" resolution strategy by `git-config`).
|
// the "last one wins" resolution strategy by `git-config`).
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
//! This module handles parsing a `git-config` file. Generally speaking, you
|
//! This module handles parsing a `git-config` file. Generally speaking, you
|
||||||
//! want to use a higher a[u8]action such as [`GitConfig`] unless you have some
|
//! want to use a higher abstraction such as [`GitConfig`] unless you have some
|
||||||
//! explicit reason to work with events instead.
|
//! explicit reason to work with events instead.
|
||||||
//!
|
//!
|
||||||
//! The general workflow for interacting with this is to use one of the
|
//! The general workflow for interacting with this is to use one of the
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
use std::borrow::Cow;
|
//! This module is only included for tests, and contains common unit test helper
|
||||||
|
//! functions.
|
||||||
|
|
||||||
use crate::parser::{Event, ParsedComment, ParsedSectionHeader};
|
use crate::parser::{Event, ParsedComment, ParsedSectionHeader};
|
||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
pub fn section_header_event(
|
pub fn section_header_event(
|
||||||
name: &str,
|
name: &str,
|
||||||
|
|
|
@ -60,9 +60,6 @@ use std::str::FromStr;
|
||||||
///
|
///
|
||||||
/// [`parser`]: crate::parser::Parser
|
/// [`parser`]: crate::parser::Parser
|
||||||
pub fn normalize_cow(input: Cow<'_, [u8]>) -> Cow<'_, [u8]> {
|
pub fn normalize_cow(input: Cow<'_, [u8]>) -> Cow<'_, [u8]> {
|
||||||
let mut first_index = 0;
|
|
||||||
let mut last_index = 0;
|
|
||||||
|
|
||||||
let size = input.len();
|
let size = input.len();
|
||||||
if &*input == b"\"\"" {
|
if &*input == b"\"\"" {
|
||||||
return Cow::Borrowed(&[]);
|
return Cow::Borrowed(&[]);
|
||||||
|
@ -81,6 +78,8 @@ pub fn normalize_cow(input: Cow<'_, [u8]>) -> Cow<'_, [u8]> {
|
||||||
|
|
||||||
let mut owned = vec![];
|
let mut owned = vec![];
|
||||||
|
|
||||||
|
let mut first_index = 0;
|
||||||
|
let mut last_index = 0;
|
||||||
let mut was_escaped = false;
|
let mut was_escaped = false;
|
||||||
for (i, c) in input.iter().enumerate() {
|
for (i, c) in input.iter().enumerate() {
|
||||||
if was_escaped {
|
if was_escaped {
|
||||||
|
@ -111,10 +110,10 @@ pub fn normalize_cow(input: Cow<'_, [u8]>) -> Cow<'_, [u8]> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
owned.extend(&input[last_index..]);
|
if last_index == 0 {
|
||||||
if owned.is_empty() {
|
|
||||||
input
|
input
|
||||||
} else {
|
} else {
|
||||||
|
owned.extend(&input[last_index..]);
|
||||||
Cow::Owned(owned)
|
Cow::Owned(owned)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue