@@ -50,69 +50,6 @@ use crate::name::{LocalName, QName};
5050use crate :: utils:: write_cow_string;
5151use attributes:: { Attribute , Attributes } ;
5252
53- /// Text that appeared before an XML declaration, a start element or a comment.
54- ///
55- /// In well-formed XML it could contain a Byte-Order-Mark (BOM). If this event
56- /// contains something else except BOM, the XML should be considered ill-formed.
57- ///
58- /// This is a reader-only event. If you need to write a text before the first tag,
59- /// use the [`BytesText`] event.
60- #[ derive( Debug , Clone , Eq , PartialEq ) ]
61- pub struct BytesStartText < ' a > {
62- content : BytesText < ' a > ,
63- }
64-
65- impl < ' a > BytesStartText < ' a > {
66- /// Converts the event into an owned event.
67- pub fn into_owned ( self ) -> BytesStartText < ' static > {
68- BytesStartText {
69- content : self . content . into_owned ( ) ,
70- }
71- }
72-
73- /// Extracts the inner `Cow` from the `BytesStartText` event container.
74- #[ inline]
75- pub fn into_inner ( self ) -> Cow < ' a , [ u8 ] > {
76- self . content . into_inner ( )
77- }
78-
79- /// Converts the event into a borrowed event.
80- #[ inline]
81- pub fn borrow ( & self ) -> BytesStartText {
82- BytesStartText {
83- content : self . content . borrow ( ) ,
84- }
85- }
86-
87- /// Decodes bytes of event, stripping byte order mark (BOM) if it is presented
88- /// in the event.
89- ///
90- /// This method does not unescapes content, because no escape sequences can
91- /// appeared in the BOM or in the text before the first tag.
92- pub fn decode_with_bom_removal ( & self ) -> Result < String > {
93- //TODO: Fix lifetime issue - it should be possible to borrow string
94- let decoded = self . content . decoder . decode_with_bom_removal ( & * self ) ?;
95-
96- Ok ( decoded. to_string ( ) )
97- }
98- }
99-
100- impl < ' a > Deref for BytesStartText < ' a > {
101- type Target = BytesText < ' a > ;
102-
103- fn deref ( & self ) -> & Self :: Target {
104- & self . content
105- }
106- }
107-
108- impl < ' a > From < BytesText < ' a > > for BytesStartText < ' a > {
109- fn from ( content : BytesText < ' a > ) -> Self {
110- Self { content }
111- }
112- }
113-
114- ////////////////////////////////////////////////////////////////////////////////////////////////////
115-
11653/// Opening tag data (`Event::Start`), with optional attributes.
11754///
11855/// `<name attr="value">`.
@@ -797,12 +734,6 @@ impl<'a> Deref for BytesText<'a> {
797734 }
798735}
799736
800- impl < ' a > From < BytesStartText < ' a > > for BytesText < ' a > {
801- fn from ( content : BytesStartText < ' a > ) -> Self {
802- content. content
803- }
804- }
805-
806737////////////////////////////////////////////////////////////////////////////////////////////////////
807738
808739/// CDATA content contains unescaped data from the reader. If you want to write them as a text,
@@ -941,56 +872,6 @@ impl<'a> Deref for BytesCData<'a> {
941872/// [`Reader::read_event_into`]: crate::reader::Reader::read_event_into
942873#[ derive( Clone , Debug , Eq , PartialEq ) ]
943874pub enum Event < ' a > {
944- /// Text that appeared before the first opening tag or an [XML declaration].
945- /// [According to the XML standard][std], no text allowed before the XML
946- /// declaration. However, if there is a BOM in the stream, some data may be
947- /// present.
948- ///
949- /// When this event is generated, it is the very first event emitted by the
950- /// [`Reader`], and there can be the only one such event.
951- ///
952- /// The [`Writer`] writes content of this event "as is" without encoding or
953- /// escaping. If you write it, it should be written first and only one time
954- /// (but writer does not enforce that).
955- ///
956- /// # Examples
957- ///
958- /// ```
959- /// # use pretty_assertions::assert_eq;
960- /// use std::borrow::Cow;
961- /// use quick_xml::events::Event;
962- /// use quick_xml::reader::Reader;
963- ///
964- /// // XML in UTF-8 with BOM
965- /// let xml = b"\xEF\xBB\xBF<?xml version='1.0'?>".as_ref();
966- /// let mut reader = Reader::from_reader(xml);
967- /// let mut buf = Vec::new();
968- /// let mut events_processed = 0;
969- /// loop {
970- /// match reader.read_event_into(&mut buf) {
971- /// Ok(Event::StartText(e)) => {
972- /// assert_eq!(events_processed, 0);
973- /// // Content contains BOM
974- /// assert_eq!(e.into_inner(), Cow::Borrowed(b"\xEF\xBB\xBF"));
975- /// }
976- /// Ok(Event::Decl(_)) => {
977- /// assert_eq!(events_processed, 1);
978- /// }
979- /// Ok(Event::Eof) => {
980- /// assert_eq!(events_processed, 2);
981- /// break;
982- /// }
983- /// e => panic!("Unexpected event {:?}", e),
984- /// }
985- /// events_processed += 1;
986- /// }
987- /// ```
988- ///
989- /// [XML declaration]: Event::Decl
990- /// [std]: https://www.w3.org/TR/xml11/#NT-document
991- /// [`Reader`]: crate::reader::Reader
992- /// [`Writer`]: crate::writer::Writer
993- StartText ( BytesStartText < ' a > ) ,
994875 /// Start tag (with attributes) `<tag attr="value">`.
995876 Start ( BytesStart < ' a > ) ,
996877 /// End tag `</tag>`.
@@ -1018,7 +899,6 @@ impl<'a> Event<'a> {
1018899 /// buffer used when reading but incurring a new, separate allocation.
1019900 pub fn into_owned ( self ) -> Event < ' static > {
1020901 match self {
1021- Event :: StartText ( e) => Event :: StartText ( e. into_owned ( ) ) ,
1022902 Event :: Start ( e) => Event :: Start ( e. into_owned ( ) ) ,
1023903 Event :: End ( e) => Event :: End ( e. into_owned ( ) ) ,
1024904 Event :: Empty ( e) => Event :: Empty ( e. into_owned ( ) ) ,
@@ -1036,7 +916,6 @@ impl<'a> Event<'a> {
1036916 #[ inline]
1037917 pub fn borrow ( & self ) -> Event {
1038918 match self {
1039- Event :: StartText ( e) => Event :: StartText ( e. borrow ( ) ) ,
1040919 Event :: Start ( e) => Event :: Start ( e. borrow ( ) ) ,
1041920 Event :: End ( e) => Event :: End ( e. borrow ( ) ) ,
1042921 Event :: Empty ( e) => Event :: Empty ( e. borrow ( ) ) ,
@@ -1056,7 +935,6 @@ impl<'a> Deref for Event<'a> {
1056935
1057936 fn deref ( & self ) -> & [ u8 ] {
1058937 match * self {
1059- Event :: StartText ( ref e) => & * e,
1060938 Event :: Start ( ref e) | Event :: Empty ( ref e) => & * e,
1061939 Event :: End ( ref e) => & * e,
1062940 Event :: Text ( ref e) => & * e,
0 commit comments