Skip to content

Commit

Permalink
refactor: use SplitCharFromStr
Browse files Browse the repository at this point in the history
  • Loading branch information
KSXGitHub committed Oct 18, 2024
1 parent d862d97 commit 89dcd5a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ std = []
[dependencies]
derive_more = { version = "1.0.0", default-features = false, features = ["display", "error", "into_iterator"] }
pipe-trait = "0.4.0"
split-first-char = "0.0.0"
split-char-from-str = "0.0.0"

[dev-dependencies]
pretty_assertions = "1.4.1"
Expand Down
6 changes: 4 additions & 2 deletions src/enclosed/parser.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{ComponentParserInput, ParserConfig, Segment};
use crate::{IntoSkipOrFatal, Parse};
use derive_more::{Display, Error};
use split_first_char::split_first_char;
use split_char_from_str::SplitCharFromStr;

/// Parse a template string whose queries are placed between an opening bracket character and a closing bracket character,
/// (such as [curly braces](crate::simple_curly_braces)).
Expand Down Expand Up @@ -146,7 +146,9 @@ where
return Ok((Segment::Expression(query), rest));
}

let (head, tail) = split_first_char(input).ok_or(ParseError::UnexpectedEndOfInput)?;
let (head, tail) = input
.split_first_char()
.ok_or(ParseError::UnexpectedEndOfInput)?;

if head == self.config.close_bracket {
return Err(ParseError::UnexpectedChar(head));
Expand Down
9 changes: 5 additions & 4 deletions src/enclosed/simple_escape.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{ComponentParserInput, ParserConfig};
use crate::Parse;
use derive_more::{Display, Error};
use split_first_char::split_first_char;
use split_char_from_str::SplitCharFromStr;

pub type ParserInput<'a> = ComponentParserInput<'a>;

Expand All @@ -25,14 +25,15 @@ impl<'a> Parse<'a, ParserInput<'a>> for Parser {
type Error = Option<ParseError>;

fn parse(&self, input: ParserInput<'a>) -> Result<(Self::Output, &'a str), Self::Error> {
let (head, tail) = split_first_char(input.text).ok_or(None)?;
let (head, tail) = input.text.split_first_char().ok_or(None)?;

if head != '\\' {
return Err(None);
}

let (escape_code, rest) =
split_first_char(tail).ok_or(Some(ParseError::UnexpectedEndOfInput))?;
let (escape_code, rest) = tail
.split_first_char()
.ok_or(Some(ParseError::UnexpectedEndOfInput))?;

let char = escape_bracket(escape_code, input.config)
.or_else(|| make_special_character(escape_code))
Expand Down
4 changes: 2 additions & 2 deletions src/enclosed/simple_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::ComponentParserInput;
use crate::Parse;
use derive_more::{Display, Error};
use pipe_trait::Pipe;
use split_first_char::split_first_char;
use split_char_from_str::SplitCharFromStr;

pub type ParserInput<'a> = ComponentParserInput<'a>;

Expand All @@ -26,7 +26,7 @@ impl<'a> Parse<'a, ParserInput<'a>> for Parser {
type Error = Option<ParseError>;

fn parse(&self, input: ParserInput<'a>) -> Result<(Self::Output, &'a str), Self::Error> {
let (head, tail) = split_first_char(input.text).ok_or(None)?;
let (head, tail) = input.text.split_first_char().ok_or(None)?;

if head == input.config.close_bracket {
return head.pipe(ParseError::UnexpectedChar).pipe(Some).pipe(Err);
Expand Down

0 comments on commit 89dcd5a

Please sign in to comment.