File tree 2 files changed +27
-14
lines changed
2 files changed +27
-14
lines changed Original file line number Diff line number Diff line change @@ -817,17 +817,29 @@ impl Comment {
817
817
818
818
/// Given that this comment is an HTML start tag, get the `idx`th
819
819
/// attribute's name.
820
- pub fn get_tag_attr_name ( & self , idx : c_uint ) -> String {
821
- unsafe {
822
- String_ { x : clang_HTMLStartTag_getAttrName ( self . x , idx) } . to_string ( )
820
+ pub fn get_tag_attr_name ( & self , idx : c_uint ) -> Option < String > {
821
+ if idx >= self . get_num_tag_attrs ( ) {
822
+ None
823
+ } else {
824
+ unsafe {
825
+ Some ( String_ {
826
+ x : clang_HTMLStartTag_getAttrName ( self . x , idx)
827
+ } . to_string ( ) )
828
+ }
823
829
}
824
830
}
825
831
826
832
/// Given that this comment is an HTML start tag, get the `idx`th
827
833
/// attribute's value.
828
- pub fn get_tag_attr_value ( & self , idx : c_uint ) -> String {
829
- unsafe {
830
- String_ { x : clang_HTMLStartTag_getAttrValue ( self . x , idx) } . to_string ( )
834
+ pub fn get_tag_attr_value ( & self , idx : c_uint ) -> Option < String > {
835
+ if idx >= self . get_num_tag_attrs ( ) {
836
+ None
837
+ } else {
838
+ unsafe {
839
+ Some ( String_ {
840
+ x : clang_HTMLStartTag_getAttrValue ( self . x , idx)
841
+ } . to_string ( ) )
842
+ }
831
843
}
832
844
}
833
845
}
Original file line number Diff line number Diff line change @@ -134,19 +134,20 @@ impl Annotations {
134
134
if comment. kind ( ) == CXComment_HTMLStartTag &&
135
135
comment. get_tag_name ( ) == "div" &&
136
136
comment. get_num_tag_attrs ( ) > 1 &&
137
- comment. get_tag_attr_name ( 0 ) == "rustbindgen" {
137
+ comment. get_tag_attr_name ( 0 ) . as_ref ( ) . map ( |s| s. as_str ( ) )
138
+ == Some ( "rustbindgen" ) {
138
139
* matched = true ;
139
140
for i in 0 ..comment. get_num_tag_attrs ( ) {
140
- let value = comment. get_tag_attr_value ( i) ;
141
- let name = comment. get_tag_attr_name ( i) ;
142
- match name. as_str ( ) {
141
+ let value_opt = comment. get_tag_attr_value ( i) ;
142
+ match comment. get_tag_attr_name ( i) . unwrap ( ) . as_str ( ) {
143
143
"opaque" => self . opaque = true ,
144
144
"hide" => self . hide = true ,
145
145
"nocopy" => self . disallow_copy = true ,
146
- "replaces" => self . use_instead_of = Some ( value) ,
147
- "private" => self . private_fields = Some ( value != "false" ) ,
148
- "accessor"
149
- => self . accessor_kind = Some ( parse_accessor ( & value) ) ,
146
+ "replaces" => self . use_instead_of = value_opt,
147
+ "private" => self . private_fields = value_opt. map ( |v|
148
+ v != "false" ) ,
149
+ "accessor" => self . accessor_kind = value_opt. map ( |v|
150
+ parse_accessor ( & v) ) ,
150
151
_ => { } ,
151
152
}
152
153
}
You can’t perform that action at this time.
0 commit comments