@@ -808,27 +808,12 @@ impl Comment {
808
808
}
809
809
}
810
810
811
- /// Given that this comment is an HTML start tag, get the number of HTML
812
- /// attributes it has.
813
- pub fn get_num_tag_attrs ( & self ) -> c_uint {
814
- unsafe {
815
- clang_HTMLStartTag_getNumAttrs ( self . x )
816
- }
817
- }
818
-
819
- /// Given that this comment is an HTML start tag, get the `idx`th
820
- /// attribute's name.
821
- pub fn get_tag_attr_name ( & self , idx : c_uint ) -> String {
822
- unsafe {
823
- String_ { x : clang_HTMLStartTag_getAttrName ( self . x , idx) } . to_string ( )
824
- }
825
- }
826
-
827
- /// Given that this comment is an HTML start tag, get the `idx`th
828
- /// attribute's value.
829
- pub fn get_tag_attr_value ( & self , idx : c_uint ) -> String {
830
- unsafe {
831
- String_ { x : clang_HTMLStartTag_getAttrValue ( self . x , idx) } . to_string ( )
811
+ /// Given that this comment is an HTML start tag, get its attributes.
812
+ pub fn get_tag_attrs ( & self ) -> CommentAttributesIterator {
813
+ CommentAttributesIterator {
814
+ x : self . x ,
815
+ length : unsafe { clang_HTMLStartTag_getNumAttrs ( self . x ) } ,
816
+ index : 0
832
817
}
833
818
}
834
819
}
@@ -853,6 +838,37 @@ impl Iterator for CommentChildrenIterator {
853
838
}
854
839
}
855
840
841
+ /// An HTML start tag comment attribute
842
+ pub struct CommentAttribute {
843
+ /// HTML start tag attribute name
844
+ pub name : String ,
845
+ /// HTML start tag attribute value
846
+ pub value : String
847
+ }
848
+
849
+ /// An iterator for a comment's attributes
850
+ pub struct CommentAttributesIterator {
851
+ x : CXComment ,
852
+ length : c_uint ,
853
+ index : c_uint
854
+ }
855
+
856
+ impl Iterator for CommentAttributesIterator {
857
+ type Item = CommentAttribute ;
858
+ fn next ( & mut self ) -> Option < CommentAttribute > {
859
+ if self . index < self . length {
860
+ let idx = self . index ;
861
+ self . index += 1 ;
862
+ Some ( CommentAttribute {
863
+ name : String_ { x : unsafe { clang_HTMLStartTag_getAttrName ( self . x , idx) } } . to_string ( ) ,
864
+ value : String_ { x : unsafe { clang_HTMLStartTag_getAttrValue ( self . x , idx) } } . to_string ( )
865
+ } )
866
+ } else {
867
+ None
868
+ }
869
+ }
870
+ }
871
+
856
872
/// A source file.
857
873
pub struct File {
858
874
x : CXFile
0 commit comments