Function git_config::values::normalize_cow[][src]

#[must_use]pub fn normalize_cow(input: Cow<'_, [u8]>) -> Cow<'_, [u8]>

Removes quotes, if any, from the provided inputs. This assumes the input contains a even number of unescaped quotes, and will unescape escaped quotes. The return values should be safe for value interpretation.

This has optimizations for fully-quoted values, where the returned value will be a borrowed reference if the only mutation necessary is to unquote the value.

This is the function used to normalize raw values from higher level abstractions over the parser implementation. Generally speaking these high level abstractions will handle normalization for you, and you do not need to call this yourself. However, if you’re directly handling events from the parser, you may want to use this to help with value interpretation.

Generally speaking, you’ll want to use one of the variants of this function, such as normalize_str or normalize_vec.

Examples

Values don’t need modification are returned borrowed, without allocation.

assert_eq!(normalize_str("hello world"), Cow::Borrowed(b"hello world".into()));

Fully quoted values are optimized to not need allocations.

assert_eq!(normalize_str("\"hello world\""), Cow::Borrowed(b"hello world".into()));

Quoted values are unwrapped as an owned variant.

assert_eq!(normalize_str("hello \"world\""), Cow::<[u8]>::Owned(b"hello world".to_vec()));

Escaped quotes are unescaped.

assert_eq!(normalize_str(r#"hello "world\"""#), Cow::<[u8]>::Owned(br#"hello world""#.to_vec()));