summaryrefslogtreecommitdiffstats
path: root/third_party/rust/os_str_bytes/src/common
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /third_party/rust/os_str_bytes/src/common
parentInitial commit. (diff)
downloadthunderbird-upstream.tar.xz
thunderbird-upstream.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/os_str_bytes/src/common')
-rw-r--r--third_party/rust/os_str_bytes/src/common/mod.rs43
-rw-r--r--third_party/rust/os_str_bytes/src/common/raw.rs45
2 files changed, 88 insertions, 0 deletions
diff --git a/third_party/rust/os_str_bytes/src/common/mod.rs b/third_party/rust/os_str_bytes/src/common/mod.rs
new file mode 100644
index 0000000000..e28aba6696
--- /dev/null
+++ b/third_party/rust/os_str_bytes/src/common/mod.rs
@@ -0,0 +1,43 @@
+use std::borrow::Cow;
+use std::convert::Infallible;
+use std::ffi::OsStr;
+use std::ffi::OsString;
+use std::result;
+
+#[cfg(all(target_vendor = "fortanix", target_env = "sgx"))]
+use std::os::fortanix_sgx as os;
+#[cfg(target_os = "solid_asp3")]
+use std::os::solid as os;
+#[cfg(any(target_os = "hermit", unix))]
+use std::os::unix as os;
+#[cfg(target_os = "wasi")]
+use std::os::wasi as os;
+#[cfg(target_os = "xous")]
+use std::os::xous as os;
+
+use os::ffi::OsStrExt;
+use os::ffi::OsStringExt;
+
+if_raw_str! {
+ pub(super) mod raw;
+}
+
+pub(super) type EncodingError = Infallible;
+
+type Result<T> = result::Result<T, EncodingError>;
+
+pub(super) fn os_str_from_bytes(string: &[u8]) -> Result<Cow<'_, OsStr>> {
+ Ok(Cow::Borrowed(OsStrExt::from_bytes(string)))
+}
+
+pub(super) fn os_str_to_bytes(os_string: &OsStr) -> Cow<'_, [u8]> {
+ Cow::Borrowed(OsStrExt::as_bytes(os_string))
+}
+
+pub(super) fn os_string_from_vec(string: Vec<u8>) -> Result<OsString> {
+ Ok(OsStringExt::from_vec(string))
+}
+
+pub(super) fn os_string_into_vec(os_string: OsString) -> Vec<u8> {
+ OsStringExt::into_vec(os_string)
+}
diff --git a/third_party/rust/os_str_bytes/src/common/raw.rs b/third_party/rust/os_str_bytes/src/common/raw.rs
new file mode 100644
index 0000000000..97d0353d7e
--- /dev/null
+++ b/third_party/rust/os_str_bytes/src/common/raw.rs
@@ -0,0 +1,45 @@
+use std::fmt;
+use std::fmt::Formatter;
+
+use super::Result;
+
+#[inline(always)]
+pub(crate) const fn is_continuation(_: u8) -> bool {
+ false
+}
+
+#[inline(always)]
+pub(crate) fn validate_bytes(_: &[u8]) -> Result<()> {
+ Ok(())
+}
+
+#[inline(always)]
+pub(crate) fn decode_code_point(_: &[u8]) -> u32 {
+ unreachable!();
+}
+
+pub(crate) fn ends_with(string: &[u8], suffix: &[u8]) -> bool {
+ string.ends_with(suffix)
+}
+
+pub(crate) fn starts_with(string: &[u8], prefix: &[u8]) -> bool {
+ string.starts_with(prefix)
+}
+
+pub(crate) fn debug(string: &[u8], f: &mut Formatter<'_>) -> fmt::Result {
+ for byte in string {
+ write!(f, "\\x{:02X}", byte)?;
+ }
+ Ok(())
+}
+
+#[cfg(feature = "uniquote")]
+pub(crate) mod uniquote {
+ use uniquote::Formatter;
+ use uniquote::Quote;
+ use uniquote::Result;
+
+ pub(crate) fn escape(string: &[u8], f: &mut Formatter<'_>) -> Result {
+ string.escape(f)
+ }
+}