File tree 2 files changed +28
-15
lines changed
2 files changed +28
-15
lines changed Original file line number Diff line number Diff line change @@ -791,19 +791,12 @@ impl Comment {
791
791
}
792
792
}
793
793
794
- /// Get the number of children this comment node has.
795
- pub fn num_children ( & self ) -> c_uint {
796
- unsafe {
797
- clang_Comment_getNumChildren ( self . x )
798
- }
799
- }
800
-
801
- /// Get this comment's `idx`th child comment
802
- pub fn get_child ( & self , idx : c_uint ) -> Option < Comment > {
803
- if idx >= self . num_children ( ) {
804
- None
805
- } else {
806
- Some ( Comment { x : unsafe { clang_Comment_getChild ( self . x , idx) } } )
794
+ /// Get this comment's children comment
795
+ pub fn get_children ( & self ) -> CommentChildrenIterator {
796
+ CommentChildrenIterator {
797
+ parent : self . x ,
798
+ length : unsafe { clang_Comment_getNumChildren ( self . x ) } ,
799
+ index : 0
807
800
}
808
801
}
809
802
@@ -852,6 +845,26 @@ impl Comment {
852
845
}
853
846
}
854
847
848
+ /// An iterator for a comment's children
849
+ pub struct CommentChildrenIterator {
850
+ parent : CXComment ,
851
+ length : c_uint ,
852
+ index : c_uint
853
+ }
854
+
855
+ impl Iterator for CommentChildrenIterator {
856
+ type Item = Comment ;
857
+ fn next ( & mut self ) -> Option < Comment > {
858
+ if self . index < self . length {
859
+ let idx = self . index ;
860
+ self . index += 1 ;
861
+ Some ( Comment { x : unsafe { clang_Comment_getChild ( self . parent , idx) } } )
862
+ } else {
863
+ None
864
+ }
865
+ }
866
+ }
867
+
855
868
/// A source file.
856
869
pub struct File {
857
870
x : CXFile
Original file line number Diff line number Diff line change @@ -153,8 +153,8 @@ impl Annotations {
153
153
}
154
154
}
155
155
156
- for i in 0 .. comment. num_children ( ) {
157
- self . parse ( & comment . get_child ( i ) . unwrap ( ) , matched) ;
156
+ for child in comment. get_children ( ) {
157
+ self . parse ( & child , matched) ;
158
158
}
159
159
}
160
160
}
You can’t perform that action at this time.
0 commit comments