misc improvements

This commit is contained in:
Edward Shen 2021-03-01 18:33:26 -05:00
parent 8778d42e78
commit 0905642feb
Signed by: edward
GPG key ID: 19182661E818369F
4 changed files with 10 additions and 9 deletions

View file

@ -237,11 +237,11 @@ impl<'event> GitConfig<'event> {
/// 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.
pub fn get_raw_value<'lookup>(
&'event self,
&self,
section_name: &'lookup str,
subsection_name: Option<&'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
// to guarantee that the highest section id is used (so that we follow
// the "last one wins" resolution strategy by `git-config`).

View file

@ -1,5 +1,5 @@
//! 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.
//!
//! The general workflow for interacting with this is to use one of the

View file

@ -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 std::borrow::Cow;
pub fn section_header_event(
name: &str,

View file

@ -60,9 +60,6 @@ use std::str::FromStr;
///
/// [`parser`]: crate::parser::Parser
pub fn normalize_cow(input: Cow<'_, [u8]>) -> Cow<'_, [u8]> {
let mut first_index = 0;
let mut last_index = 0;
let size = input.len();
if &*input == b"\"\"" {
return Cow::Borrowed(&[]);
@ -81,6 +78,8 @@ pub fn normalize_cow(input: Cow<'_, [u8]>) -> Cow<'_, [u8]> {
let mut owned = vec![];
let mut first_index = 0;
let mut last_index = 0;
let mut was_escaped = false;
for (i, c) in input.iter().enumerate() {
if was_escaped {
@ -111,10 +110,10 @@ pub fn normalize_cow(input: Cow<'_, [u8]>) -> Cow<'_, [u8]> {
}
}
owned.extend(&input[last_index..]);
if owned.is_empty() {
if last_index == 0 {
input
} else {
owned.extend(&input[last_index..]);
Cow::Owned(owned)
}
}