-
Notifications
You must be signed in to change notification settings - Fork 44
Make utf8parse dependency optional
#219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,18 +25,19 @@ pre-release-replacements = [ | |
| ] | ||
|
|
||
| [features] | ||
| default = ["auto", "wincon"] | ||
| default = ["auto", "wincon", "utf8"] | ||
| auto = ["dep:anstyle-query"] | ||
| wincon = ["dep:anstyle-wincon"] | ||
| utf8 = ["dep:utf8parse", "anstyle-parse/utf8"] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general, I worry that this is an implementation detail and could change and you could lose the benefit |
||
| # Enable in `dev-dependencies` to make sure output is captured for tests | ||
| test = [] | ||
|
|
||
| [dependencies] | ||
| anstyle = { version = "1.0.0", path = "../anstyle" } | ||
| anstyle-parse = { version = "0.2.0", path = "../anstyle-parse" } | ||
| anstyle-parse = { version = "0.2.0", path = "../anstyle-parse", default-features = false } | ||
| colorchoice = { version = "1.0.0", path = "../colorchoice" } | ||
| anstyle-query = { version = "1.0.0", path = "../anstyle-query", optional = true } | ||
| utf8parse = "0.2.1" | ||
| utf8parse = { version = "0.2.1", optional = true } | ||
| is_terminal_polyfill = "1.48" | ||
|
|
||
| [target.'cfg(windows)'.dependencies] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -174,19 +174,22 @@ fn is_utf8_continuation(b: u8) -> bool { | |
| /// let plain_str = anstream::adapter::strip_bytes(styled_text.as_bytes()).into_vec(); | ||
| /// assert_eq!(plain_str.as_slice(), &b"foo bar"[..]); | ||
| /// ``` | ||
| #[cfg(feature = "utf8")] | ||
| #[inline] | ||
| pub fn strip_bytes(data: &[u8]) -> StrippedBytes<'_> { | ||
|
Comment on lines
+177
to
179
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Taking built-in functionality and putting it behind a feature is a breaking change as it may break people who use |
||
| StrippedBytes::new(data) | ||
| } | ||
|
|
||
| /// See [`strip_bytes`] | ||
| #[cfg(feature = "utf8")] | ||
| #[derive(Default, Clone, Debug, PartialEq, Eq)] | ||
| pub struct StrippedBytes<'s> { | ||
| bytes: &'s [u8], | ||
| state: State, | ||
| utf8parser: Utf8Parser, | ||
| } | ||
|
|
||
| #[cfg(feature = "utf8")] | ||
| impl<'s> StrippedBytes<'s> { | ||
| /// See [`strip_bytes`] | ||
| #[inline] | ||
|
|
@@ -231,6 +234,7 @@ impl<'s> StrippedBytes<'s> { | |
| } | ||
| } | ||
|
|
||
| #[cfg(feature = "utf8")] | ||
| impl<'s> Iterator for StrippedBytes<'s> { | ||
| type Item = &'s [u8]; | ||
|
|
||
|
|
@@ -240,13 +244,15 @@ impl<'s> Iterator for StrippedBytes<'s> { | |
| } | ||
| } | ||
|
|
||
| #[cfg(feature = "utf8")] | ||
| /// Incrementally strip non-contiguous data | ||
| #[derive(Default, Clone, Debug, PartialEq, Eq)] | ||
| pub struct StripBytes { | ||
| state: State, | ||
| utf8parser: Utf8Parser, | ||
| } | ||
|
|
||
| #[cfg(feature = "utf8")] | ||
| impl StripBytes { | ||
| /// Initial state | ||
| pub fn new() -> Self { | ||
|
|
@@ -263,6 +269,7 @@ impl StripBytes { | |
| } | ||
| } | ||
|
|
||
| #[cfg(feature = "utf8")] | ||
| /// See [`StripBytes`] | ||
| #[derive(Debug, PartialEq, Eq)] | ||
| pub struct StripBytesIter<'s> { | ||
|
|
@@ -271,6 +278,7 @@ pub struct StripBytesIter<'s> { | |
| utf8parser: &'s mut Utf8Parser, | ||
| } | ||
|
|
||
| #[cfg(feature = "utf8")] | ||
| impl<'s> Iterator for StripBytesIter<'s> { | ||
| type Item = &'s [u8]; | ||
|
|
||
|
|
@@ -280,6 +288,7 @@ impl<'s> Iterator for StripBytesIter<'s> { | |
| } | ||
| } | ||
|
|
||
| #[cfg(feature = "utf8")] | ||
| #[inline] | ||
| fn next_bytes<'s>( | ||
| bytes: &mut &'s [u8], | ||
|
|
@@ -328,11 +337,13 @@ fn next_bytes<'s>( | |
| } | ||
| } | ||
|
|
||
| #[cfg(feature = "utf8")] | ||
| #[derive(Default, Clone, Debug, PartialEq, Eq)] | ||
| pub(crate) struct Utf8Parser { | ||
| utf8_parser: utf8parse::Parser, | ||
| } | ||
|
|
||
| #[cfg(feature = "utf8")] | ||
| impl Utf8Parser { | ||
| fn add(&mut self, byte: u8) -> bool { | ||
| let mut b = false; | ||
|
|
@@ -342,8 +353,10 @@ impl Utf8Parser { | |
| } | ||
| } | ||
|
|
||
| #[cfg(feature = "utf8")] | ||
| struct VtUtf8Receiver<'a>(&'a mut bool); | ||
|
|
||
| #[cfg(feature = "utf8")] | ||
| impl<'a> utf8parse::Receiver for VtUtf8Receiver<'a> { | ||
| fn codepoint(&mut self, _: char) { | ||
| *self.0 = true; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feature name doesn't do a good job of describing what you are getting / losing imo