os_str_bytes/common/
raw.rs

1use std::fmt;
2use std::fmt::Formatter;
3
4use crate::RawOsStr;
5
6if_not_nightly! {
7    use super::Result;
8}
9
10if_not_nightly! {
11    #[inline(always)]
12    pub(crate) const fn is_continuation(_: u8) -> bool {
13        false
14    }
15}
16
17if_not_nightly! {
18    #[inline(always)]
19    pub(crate) fn validate_bytes(_: &[u8]) -> Result<()> {
20        Ok(())
21    }
22}
23
24if_not_nightly! {
25    #[inline(always)]
26    pub(crate) fn decode_code_point(_: &[u8]) -> u32 {
27        unreachable!();
28    }
29}
30
31pub(crate) fn ends_with(string: &[u8], suffix: &[u8]) -> bool {
32    string.ends_with(suffix)
33}
34
35pub(crate) fn starts_with(string: &[u8], prefix: &[u8]) -> bool {
36    string.starts_with(prefix)
37}
38
39#[allow(deprecated)]
40#[cfg_attr(feature = "nightly", allow(unreachable_code))]
41fn as_inner(string: &RawOsStr) -> &[u8] {
42    if_nightly_return! {{
43        string.as_encoded_bytes()
44    }}
45    string.as_raw_bytes()
46}
47
48pub(crate) fn debug(string: &RawOsStr, f: &mut Formatter<'_>) -> fmt::Result {
49    for byte in as_inner(string) {
50        write!(f, "\\x{:02X}", byte)?;
51    }
52    Ok(())
53}
54
55#[cfg(feature = "uniquote")]
56pub(crate) mod uniquote {
57    use uniquote::Formatter;
58    use uniquote::Quote;
59    use uniquote::Result;
60
61    use crate::RawOsStr;
62
63    pub(crate) fn escape(string: &RawOsStr, f: &mut Formatter<'_>) -> Result {
64        super::as_inner(string).escape(f)
65    }
66}