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