• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use std::fmt;
2 use std::fmt::Formatter;
3 
4 use crate::RawOsStr;
5 
6 if_not_nightly! {
7     use super::Result;
8 }
9 
10 if_not_nightly! {
11     #[inline(always)]
12     pub(crate) const fn is_continuation(_: u8) -> bool {
13         false
14     }
15 }
16 
17 if_not_nightly! {
18     #[inline(always)]
19     pub(crate) fn validate_bytes(_: &[u8]) -> Result<()> {
20         Ok(())
21     }
22 }
23 
24 if_not_nightly! {
25     #[inline(always)]
26     pub(crate) fn decode_code_point(_: &[u8]) -> u32 {
27         unreachable!();
28     }
29 }
30 
ends_with(string: &[u8], suffix: &[u8]) -> bool31 pub(crate) fn ends_with(string: &[u8], suffix: &[u8]) -> bool {
32     string.ends_with(suffix)
33 }
34 
starts_with(string: &[u8], prefix: &[u8]) -> bool35 pub(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))]
as_inner(string: &RawOsStr) -> &[u8]41 fn as_inner(string: &RawOsStr) -> &[u8] {
42     if_nightly_return! {{
43         string.as_encoded_bytes()
44     }}
45     string.as_raw_bytes()
46 }
47 
debug(string: &RawOsStr, f: &mut Formatter<'_>) -> fmt::Result48 pub(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")]
56 pub(crate) mod uniquote {
57     use uniquote::Formatter;
58     use uniquote::Quote;
59     use uniquote::Result;
60 
61     use crate::RawOsStr;
62 
escape(string: &RawOsStr, f: &mut Formatter<'_>) -> Result63     pub(crate) fn escape(string: &RawOsStr, f: &mut Formatter<'_>) -> Result {
64         super::as_inner(string).escape(f)
65     }
66 }
67