Skip to content
Myr

globset: add `Candidate::from_bytes` constructor

Before adoption: this commit came in with the history the project adopted, so no landing records it.

This is already technically possible to do on Unix by going through `OsStr` and `&[u8]` conversions. This just makes it easier to do in all circumstances and is reasonable to intentionally support. Closes #2954, Closes #2955

authored by Alexander Weiss · committed by Andrew Gallant · parent 4ab1862 · Browse files · 1 file+17 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+17 added−1 removed

  • other:+17 added−1 removed

1 file+17 added−1 removed

modified:crates/globset/src/lib.rs+17 added-1 removed
596 unmodified lines
597598impl<'a> Candidate<'a> {599 /// Create a new candidate for matching from the given path.600 pub fn new<P: AsRef<Path> + ?Sized>(path: &'a P) -> Candidate<'a> {601 let path = normalize_path(Vec::from_path_lossy(path.as_ref()));601 Self::from_cow(Vec::from_path_lossy(path.as_ref()))602 }603604 /// Create a new candidate for matching from the given path as a sequence605 /// of bytes.606 ///607 /// Generally speaking, this routine expects the bytes to be608 /// _conventionally_ UTF-8. It is legal for the byte sequence to contain609 /// invalid UTF-8. However, if the bytes are in some other encoding that610 /// isn't ASCII compatible (for example, UTF-16), then the results of611 /// matching are unspecified.612 pub fn from_bytes<P: AsRef<[u8]> + ?Sized>(path: &'a P) -> Candidate<'a> {613 Self::from_cow(Cow::Borrowed(path.as_ref()))614 }615616 fn from_cow(path: Cow<'a, [u8]>) -> Candidate<'a> {617 let path = normalize_path(path);618 let basename = file_name(&path).unwrap_or(Cow::Borrowed(B("")));619 let ext = file_name_ext(&basename).unwrap_or(Cow::Borrowed(B("")));620 Candidate { path, basename, ext }621 }
505 unmodified lines