summaryrefslogtreecommitdiffstats
path: root/vendor/percent-encoding/src
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
commitdc0db358abe19481e475e10c32149b53370f1a1c (patch)
treeab8ce99c4b255ce46f99ef402c27916055b899ee /vendor/percent-encoding/src
parentReleasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff)
downloadrustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz
rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/percent-encoding/src')
-rw-r--r--vendor/percent-encoding/src/lib.rs17
1 files changed, 13 insertions, 4 deletions
diff --git a/vendor/percent-encoding/src/lib.rs b/vendor/percent-encoding/src/lib.rs
index 46a5d747c..e02a43949 100644
--- a/vendor/percent-encoding/src/lib.rs
+++ b/vendor/percent-encoding/src/lib.rs
@@ -36,8 +36,12 @@
//!
//! assert_eq!(utf8_percent_encode("foo <bar>", FRAGMENT).to_string(), "foo%20%3Cbar%3E");
//! ```
-
#![no_std]
+
+// For forwards compatibility
+#[cfg(feature = "std")]
+extern crate std as _;
+
#[cfg(feature = "alloc")]
extern crate alloc;
@@ -180,9 +184,9 @@ pub const NON_ALPHANUMERIC: &AsciiSet = &CONTROLS
/// assert_eq!("foo bar".bytes().map(percent_encode_byte).collect::<String>(),
/// "%66%6F%6F%20%62%61%72");
/// ```
+#[inline]
pub fn percent_encode_byte(byte: u8) -> &'static str {
- let index = usize::from(byte) * 3;
- &"\
+ static ENC_TABLE: &[u8; 768] = b"\
%00%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F\
%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F\
%20%21%22%23%24%25%26%27%28%29%2A%2B%2C%2D%2E%2F\
@@ -199,7 +203,12 @@ pub fn percent_encode_byte(byte: u8) -> &'static str {
%D0%D1%D2%D3%D4%D5%D6%D7%D8%D9%DA%DB%DC%DD%DE%DF\
%E0%E1%E2%E3%E4%E5%E6%E7%E8%E9%EA%EB%EC%ED%EE%EF\
%F0%F1%F2%F3%F4%F5%F6%F7%F8%F9%FA%FB%FC%FD%FE%FF\
- "[index..index + 3]
+ ";
+
+ let index = usize::from(byte) * 3;
+ // SAFETY: ENC_TABLE is ascii-only, so any subset if it should be
+ // ascii-only too, which is valid utf8.
+ unsafe { str::from_utf8_unchecked(&ENC_TABLE[index..index + 3]) }
}
/// Percent-encode the given bytes with the given set.