浏览代码

Auto merge of #528 - DoumanAsh:ascii_set_remove, r=SimonSapin

percent-encoding: Allow to remove character from AsciiSet

Allow to remove character from AsciiSet

I liked trait approach better, but if you're going with something like AsciiSet it would be better to allow to remove bytes, as sometimes it is easier to take `NON_ALPHANUMERIC` and remove few necessary characters

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-url/528)
<!-- Reviewable:end -->
bors-servo 7 年之前
父节点
当前提交
0e874ddcd6
共有 2 个文件被更改,包括 7 次插入1 次删除
  1. 1 1
      percent_encoding/Cargo.toml
  2. 6 0
      percent_encoding/lib.rs

+ 1 - 1
percent_encoding/Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "percent-encoding"
-version = "2.0.0"
+version = "2.1.0"
 authors = ["The rust-url developers"]
 description = "Percent encoding and decoding"
 repository = "https://github.com/servo/rust-url/"

+ 6 - 0
percent_encoding/lib.rs

@@ -83,6 +83,12 @@ impl AsciiSet {
         mask[byte as usize / BITS_PER_CHUNK] |= 1 << (byte as usize % BITS_PER_CHUNK);
         AsciiSet { mask }
     }
+
+    pub const fn remove(&self, byte: u8) -> Self {
+        let mut mask = self.mask;
+        mask[byte as usize / BITS_PER_CHUNK] &= !(1 << (byte as usize % BITS_PER_CHUNK));
+        AsciiSet { mask }
+    }
 }
 
 /// The set of 0x00 to 0x1F (C0 controls), and 0x7F (DEL).