Skip to content

Commit

Permalink
refactor (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Apr 7, 2022
1 parent 8a54341 commit dbe7305
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion git-glob/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use crate::pattern::Mode;
use bstr::{BString, ByteSlice};

#[inline]
/// A sloppy parser that performs only the most basic checks, providing additional information
/// using `pattern::Mode` flags.
pub fn parse_line(mut line: &[u8]) -> Option<(BString, pattern::Mode)> {
let mut mode = Mode::empty();
if line.is_empty() {
Expand All @@ -28,12 +30,14 @@ pub fn parse_line(mut line: &[u8]) -> Option<(BString, pattern::Mode)> {
if !line.contains(&b'/') {
mode |= Mode::NO_SUB_DIR;
}
if line.first() == Some(&b'*') && line[1..].find_byteset(br"*?[\").is_none() {
if line.first() == Some(&b'*') && line[1..].find_byteset(GLOB_CHARACTERS).is_none() {
mode |= Mode::ENDS_WITH;
}
Some((line, mode))
}

const GLOB_CHARACTERS: &[u8] = br"*?[\";

/// We always copy just because that's ultimately needed anyway, not because we always have to.
fn truncate_non_escaped_trailing_spaces(buf: &[u8]) -> BString {
match buf.rfind_not_byteset(br"\ ") {
Expand Down
File renamed without changes.

0 comments on commit dbe7305

Please sign in to comment.