diff --git a/src/file.rs b/src/file.rs index 53be5d6..7b8b87f 100644 --- a/src/file.rs +++ b/src/file.rs @@ -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, GitConfigError<'lookup>> { + ) -> Result, 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`). diff --git a/src/parser.rs b/src/parser.rs index adcf0f4..60d5969 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -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 diff --git a/src/test_util.rs b/src/test_util.rs index 0d8a263..6397f02 100644 --- a/src/test_util.rs +++ b/src/test_util.rs @@ -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, diff --git a/src/values.rs b/src/values.rs index ff2739f..964f700 100644 --- a/src/values.rs +++ b/src/values.rs @@ -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) } }