@@ -352,6 +352,53 @@ pub struct BytesDecl<'a> {
352352}
353353
354354impl < ' a > BytesDecl < ' a > {
355+ /// Constructs a new `XmlDecl` from the (mandatory) _version_ (should be `1.0` or `1.1`),
356+ /// the optional _encoding_ (e.g., `UTF-8`) and the optional _standalone_ (`yes` or `no`)
357+ /// attribute.
358+ ///
359+ /// Does not escape any of its inputs. Always uses double quotes to wrap the attribute values.
360+ /// The caller is responsible for escaping attribute values. Shouldn't usually be relevant since
361+ /// the double quote character is not allowed in any of the attribute values.
362+ pub fn new (
363+ version : & str ,
364+ encoding : Option < & str > ,
365+ standalone : Option < & str > ,
366+ ) -> BytesDecl < ' static > {
367+ // Compute length of the buffer based on supplied attributes
368+ // ' encoding=""' => 12
369+ let encoding_attr_len = if let Some ( xs) = encoding {
370+ 12 + xs. len ( )
371+ } else {
372+ 0
373+ } ;
374+ // ' standalone=""' => 14
375+ let standalone_attr_len = if let Some ( xs) = standalone {
376+ 14 + xs. len ( )
377+ } else {
378+ 0
379+ } ;
380+ // 'xml version=""' => 14
381+ let mut buf = String :: with_capacity ( 14 + encoding_attr_len + standalone_attr_len) ;
382+
383+ buf. push_str ( "xml version=\" " ) ;
384+ buf. push_str ( version) ;
385+
386+ if let Some ( encoding_val) = encoding {
387+ buf. push_str ( "\" encoding=\" " ) ;
388+ buf. push_str ( encoding_val) ;
389+ }
390+
391+ if let Some ( standalone_val) = standalone {
392+ buf. push_str ( "\" standalone=\" " ) ;
393+ buf. push_str ( standalone_val) ;
394+ }
395+ buf. push ( '"' ) ;
396+
397+ BytesDecl {
398+ content : BytesStart :: from_content ( buf, 3 ) ,
399+ }
400+ }
401+
355402 /// Creates a `BytesDecl` from a `BytesStart`
356403 pub fn from_start ( start : BytesStart < ' a > ) -> Self {
357404 Self { content : start }
@@ -510,53 +557,6 @@ impl<'a> BytesDecl<'a> {
510557 . transpose ( )
511558 }
512559
513- /// Constructs a new `XmlDecl` from the (mandatory) _version_ (should be `1.0` or `1.1`),
514- /// the optional _encoding_ (e.g., `UTF-8`) and the optional _standalone_ (`yes` or `no`)
515- /// attribute.
516- ///
517- /// Does not escape any of its inputs. Always uses double quotes to wrap the attribute values.
518- /// The caller is responsible for escaping attribute values. Shouldn't usually be relevant since
519- /// the double quote character is not allowed in any of the attribute values.
520- pub fn new (
521- version : & str ,
522- encoding : Option < & str > ,
523- standalone : Option < & str > ,
524- ) -> BytesDecl < ' static > {
525- // Compute length of the buffer based on supplied attributes
526- // ' encoding=""' => 12
527- let encoding_attr_len = if let Some ( xs) = encoding {
528- 12 + xs. len ( )
529- } else {
530- 0
531- } ;
532- // ' standalone=""' => 14
533- let standalone_attr_len = if let Some ( xs) = standalone {
534- 14 + xs. len ( )
535- } else {
536- 0
537- } ;
538- // 'xml version=""' => 14
539- let mut buf = String :: with_capacity ( 14 + encoding_attr_len + standalone_attr_len) ;
540-
541- buf. push_str ( "xml version=\" " ) ;
542- buf. push_str ( version) ;
543-
544- if let Some ( encoding_val) = encoding {
545- buf. push_str ( "\" encoding=\" " ) ;
546- buf. push_str ( encoding_val) ;
547- }
548-
549- if let Some ( standalone_val) = standalone {
550- buf. push_str ( "\" standalone=\" " ) ;
551- buf. push_str ( standalone_val) ;
552- }
553- buf. push ( '"' ) ;
554-
555- BytesDecl {
556- content : BytesStart :: from_content ( buf, 3 ) ,
557- }
558- }
559-
560560 /// Gets the decoder struct
561561 #[ cfg( feature = "encoding" ) ]
562562 pub fn encoder ( & self ) -> Option < & ' static Encoding > {
0 commit comments