Skip to content

Commit

Permalink
More options.
Browse files Browse the repository at this point in the history
  • Loading branch information
timothee-haudebourg committed Aug 9, 2023
1 parent 1861df7 commit d1d133f
Show file tree
Hide file tree
Showing 10 changed files with 423 additions and 19 deletions.
15 changes: 15 additions & 0 deletions README.md
Expand Up @@ -136,3 +136,18 @@ with the sources, and ship it with your library/application to reduce
compilation time on the user machine.

<!-- cargo-rdme end -->

## License

Licensed under either of

* Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)

at your option.

### Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any
additional terms or conditions.
27 changes: 26 additions & 1 deletion src/attribute.rs
Expand Up @@ -29,6 +29,10 @@ pub struct Attribute {
pub entry_point: Option<String>,
pub sized: Option<SizedTypeAttributes>,
pub cache_path: Option<PathBuf>,
pub no_deref: bool,
pub no_borrow: bool,
pub ascii: bool,
pub disable: bool,
}

impl Attribute {
Expand All @@ -40,7 +44,11 @@ impl Attribute {
self.sized.get_or_insert_with(Default::default).append(a);
}

self.cache_path = other.cache_path.or(self.cache_path.take())
self.cache_path = other.cache_path.or(self.cache_path.take());

Check failure on line 47 in src/attribute.rs

View workflow job for this annotation

GitHub Actions / Warnings

use of `or` followed by a function call
self.no_deref |= other.no_deref;
self.no_borrow |= other.no_borrow;
self.ascii |= other.ascii;
self.disable |= other.disable
}
}

Expand All @@ -49,6 +57,10 @@ enum AttributeItem {
EntryPoint,
SizedType,
CachePath,
NoDeref,
NoBorrow,
Ascii,
Disable,
Separator,
}

Expand All @@ -59,6 +71,10 @@ impl AttributeItem {
TokenTree::Ident(id) if id == "entry_point" => Ok(Self::EntryPoint),
TokenTree::Ident(id) if id == "sized" => Ok(Self::SizedType),
TokenTree::Ident(id) if id == "cache" => Ok(Self::CachePath),
TokenTree::Ident(id) if id == "no_deref" => Ok(Self::NoDeref),
TokenTree::Ident(id) if id == "no_borrow" => Ok(Self::NoBorrow),
TokenTree::Ident(id) if id == "ascii" => Ok(Self::Ascii),
TokenTree::Ident(id) if id == "disable" => Ok(Self::Disable),
TokenTree::Punct(_) => Ok(Self::Separator),
t => {
let span = t.span();
Expand Down Expand Up @@ -158,6 +174,13 @@ impl Attribute {
let inner = expect_group(&mut tokens, span)?;
result.sized = Some(SizedTypeAttributes::parse(inner)?)
}
AttributeItem::NoDeref => result.no_deref = true,
AttributeItem::NoBorrow => {
result.no_borrow = true;
result.no_deref = true
}
AttributeItem::Ascii => result.ascii = true,
AttributeItem::Disable => result.disable = true,
}
}

Expand Down Expand Up @@ -240,6 +263,8 @@ impl SizedTypeAttributes {
}
}
}

result.derives.append(derives)
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions src/byteset.rs
Expand Up @@ -100,6 +100,24 @@ impl ByteSet {
pub fn first(&self) -> Option<u8> {
self.0.iter().next().and_then(|range| range.first())
}

pub fn is_ascii(&self) -> bool {
for range in self.0.iter() {
if let Some(b) = range.first() {
if !b.is_ascii() {
return false;
}
}

if let Some(b) = range.first() {
if !b.is_ascii() {
return false;
}
}
}

true
}
}

pub struct Ranges<'a>(
Expand Down
6 changes: 6 additions & 0 deletions src/charset.rs
Expand Up @@ -80,6 +80,12 @@ impl CharSet {
self.0.len()
}

pub fn is_ascii(&self) -> bool {
self.0
.iter()
.all(|range| range.first().unwrap().is_ascii() && range.last().unwrap().is_ascii())
}

pub fn from_char(c: char, case_sensitive: bool) -> CharSet {
let mut set = CharSet::new();

Expand Down

0 comments on commit d1d133f

Please sign in to comment.