summaryrefslogtreecommitdiffstats
path: root/vendor/unicode-bom/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/unicode-bom/src/lib.rs')
-rw-r--r--vendor/unicode-bom/src/lib.rs31
1 files changed, 30 insertions, 1 deletions
diff --git a/vendor/unicode-bom/src/lib.rs b/vendor/unicode-bom/src/lib.rs
index eae541106..6c8ba03d7 100644
--- a/vendor/unicode-bom/src/lib.rs
+++ b/vendor/unicode-bom/src/lib.rs
@@ -128,6 +128,35 @@ impl AsRef<str> for Bom {
}
}
+impl AsRef<[u8]> for Bom {
+ /// Returns the BOM byte-array literal.
+ ///
+ /// Note that for UTF-7,
+ /// only the first three bytes of the BOM are returned.
+ /// That's because the last two bits of the fourth byte
+ /// belong to the following character,
+ /// so it's impossible to return the fourth byte
+ /// without further context.
+ /// Possible values for the missing fourth byte
+ /// are `0x38`, `0x39`, `0x2a` and `0x2b`.
+ fn as_ref(&self) -> &[u8] {
+ match *self {
+ Bom::Null => &[],
+ Bom::Bocu1 => &[0xfb, 0xee, 0x28],
+ Bom::Gb18030 => &[0x84, 0x31, 0x95, 0x33],
+ Bom::Scsu => &[0x0e, 0xfe, 0xff],
+ Bom::UtfEbcdic => &[0xdd, 0x73, 0x66, 0x73],
+ Bom::Utf1 => &[0xf7, 0x64, 0x4c],
+ Bom::Utf7 => &[0x2b, 0x2f, 0x76],
+ Bom::Utf8 => &[0xef, 0xbb, 0xbf],
+ Bom::Utf16Be => &[0xfe, 0xff],
+ Bom::Utf16Le => &[0xff, 0xfe],
+ Bom::Utf32Be => &[0, 0, 0xfe, 0xff],
+ Bom::Utf32Le => &[0xff, 0xfe, 0, 0],
+ }
+ }
+}
+
impl Default for Bom {
/// Returns the default/empty BOM type, `Bom::Null`.
fn default() -> Self {
@@ -138,7 +167,7 @@ impl Default for Bom {
impl Display for Bom {
/// Formats the BOM type as a `String`.
fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
- write!(formatter, "{}", self.as_ref())
+ write!(formatter, "{}", AsRef::<str>::as_ref(self))
}
}