@@ -256,12 +256,54 @@ impl<'a> Attributes<'a> {
256
256
}
257
257
}
258
258
259
- /// Creates a new attribute iterator from a buffer.
259
+ /// Creates a new attribute iterator from a buffer, which recognizes only XML-style
260
+ /// attributes, i. e. those which in the form `name = "value"` or `name = 'value'`.
261
+ /// HTML style attributes (i. e. without quotes or only name) will return a error.
262
+ ///
263
+ /// # Parameters
264
+ /// - `buf`: a buffer with a tag name and attributes, usually this is the whole
265
+ /// string between `<` and `>` (or `/>`) of a tag;
266
+ /// - `pos`: a position in the `buf` where tag name is finished and attributes
267
+ /// is started. It is not necessary to point exactly to the end of a tag name,
268
+ /// although that is usually that. If it will be more than the `buf` length,
269
+ /// then the iterator will return `None`` immediately.
270
+ ///
271
+ /// # Example
272
+ /// ```
273
+ /// # use quick_xml::events::attributes::{Attribute, Attributes};
274
+ /// # use pretty_assertions::assert_eq;
275
+ /// #
276
+ /// let mut iter = Attributes::new("tag-name attr1 = 'value1' attr2='value2' ", 9);
277
+ /// // ^0 ^9
278
+ /// assert_eq!(iter.next(), Some(Ok(Attribute::from(("attr1", "value1")))));
279
+ /// assert_eq!(iter.next(), Some(Ok(Attribute::from(("attr2", "value2")))));
280
+ /// assert_eq!(iter.next(), None);
281
+ /// ```
260
282
pub const fn new ( buf : & ' a str , pos : usize ) -> Self {
261
283
Self :: wrap ( buf. as_bytes ( ) , pos, false , Decoder :: utf8 ( ) )
262
284
}
263
285
264
286
/// Creates a new attribute iterator from a buffer, allowing HTML attribute syntax.
287
+ ///
288
+ /// # Parameters
289
+ /// - `buf`: a buffer with a tag name and attributes, usually this is the whole
290
+ /// string between `<` and `>` (or `/>`) of a tag;
291
+ /// - `pos`: a position in the `buf` where tag name is finished and attributes
292
+ /// is started. It is not necessary to point exactly to the end of a tag name,
293
+ /// although that is usually that. If it will be more than the `buf` length,
294
+ /// then the iterator will return `None`` immediately.
295
+ ///
296
+ /// # Example
297
+ /// ```
298
+ /// # use quick_xml::events::attributes::{Attribute, Attributes};
299
+ /// # use pretty_assertions::assert_eq;
300
+ /// #
301
+ /// let mut iter = Attributes::html("tag-name attr1 = value1 attr2 ", 9);
302
+ /// // ^0 ^9
303
+ /// assert_eq!(iter.next(), Some(Ok(Attribute::from(("attr1", "value1")))));
304
+ /// assert_eq!(iter.next(), Some(Ok(Attribute::from(("attr2", "")))));
305
+ /// assert_eq!(iter.next(), None);
306
+ /// ```
265
307
pub const fn html ( buf : & ' a str , pos : usize ) -> Self {
266
308
Self :: wrap ( buf. as_bytes ( ) , pos, true , Decoder :: utf8 ( ) )
267
309
}
0 commit comments