Commit cd545e97 authored by Ben Boeckel's avatar Ben Boeckel

commit: clean up filename parsing constants

Just use literals. The code is much cleaner.
parent 498a8377
Pipeline #148561 failed with stage
...@@ -195,29 +195,6 @@ impl CommitError { ...@@ -195,29 +195,6 @@ impl CommitError {
} }
} }
macro_rules! char_byte {
($name: ident, $value: expr) => {
const $name: u8 = $value as u8;
};
}
char_byte!(BACKSLASH_ESCAPE, '\\');
char_byte!(BACKSLASH, '\\');
char_byte!(TAB_ESCAPE, 't');
char_byte!(TAB, '\t');
char_byte!(NEWLINE_ESCAPE, 'n');
char_byte!(NEWLINE, '\n');
char_byte!(QUOTE_ESCAPE, '"');
char_byte!(QUOTE, '"');
char_byte!(ZERO, '0');
char_byte!(ONE, '1');
char_byte!(TWO, '2');
char_byte!(THREE, '3');
char_byte!(FOUR, '4');
char_byte!(FIVE, '5');
char_byte!(SIX, '6');
char_byte!(SEVEN, '7');
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
/// Ways a file can be changed in a commit. /// Ways a file can be changed in a commit.
pub enum StatusChange { pub enum StatusChange {
...@@ -307,18 +284,18 @@ impl FileName { ...@@ -307,18 +284,18 @@ impl FileName {
// Parse escaped characters. // Parse escaped characters.
.batching(|iter| { .batching(|iter| {
let n = iter.next(); let n = iter.next();
if let Some(BACKSLASH) = n { if let Some(b'\\') = n {
match iter.next() { match iter.next() {
Some(BACKSLASH_ESCAPE) => Some(Ok(BACKSLASH)), Some(b'\\') => Some(Ok(b'\\')),
Some(TAB_ESCAPE) => Some(Ok(TAB)), Some(b't') => Some(Ok(b'\t')),
Some(NEWLINE_ESCAPE) => Some(Ok(NEWLINE)), Some(b'n') => Some(Ok(b'\n')),
Some(QUOTE_ESCAPE) => Some(Ok(QUOTE)), Some(b'"') => Some(Ok(b'"')),
// The first character in an octal sequence cannot have its // The first character in an octal sequence cannot have its
// high-order bit set. // high-order bit set.
Some(sfd @ ZERO) | Some(sfd @ ONE) | Some(sfd @ TWO) Some(sfd @ b'0') | Some(sfd @ b'1') | Some(sfd @ b'2')
| Some(sfd @ THREE) => Some(Self::parse_octal(iter, sfd)), | Some(sfd @ b'3') => Some(Self::parse_octal(iter, sfd)),
Some(sfd @ FOUR) | Some(sfd @ FIVE) | Some(sfd @ SIX) Some(sfd @ b'4') | Some(sfd @ b'5') | Some(sfd @ b'6')
| Some(sfd @ SEVEN) => { | Some(sfd @ b'7') => {
Some(Err(FileNameError::InvalidLeadingOctalDigit(sfd))) Some(Err(FileNameError::InvalidLeadingOctalDigit(sfd)))
}, },
Some(c) => Some(Err(FileNameError::InvalidEscape(c))), Some(c) => Some(Err(FileNameError::InvalidEscape(c))),
...@@ -340,10 +317,10 @@ impl FileName { ...@@ -340,10 +317,10 @@ impl FileName {
/// Parse the octal digit from an ASCII value. /// Parse the octal digit from an ASCII value.
fn parse_octal_digit(ch_digit: u8) -> Result<u8, FileNameError> { fn parse_octal_digit(ch_digit: u8) -> Result<u8, FileNameError> {
if ch_digit < ZERO || SEVEN < ch_digit { if ch_digit < b'0' || b'7' < ch_digit {
Err(FileNameError::InvalidOctalDigit(ch_digit)) Err(FileNameError::InvalidOctalDigit(ch_digit))
} else { } else {
Ok(ch_digit - ZERO) Ok(ch_digit - b'0')
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment