summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2016-10-31 08:38:49 -0500
committerGitHub <noreply@github.com>2016-10-31 08:38:49 -0500
commitebfa0839ede25ed807311033532bdaa8820b3f07 (patch)
tree01ec219e0b3059bfd40b616fa4eab4f70e4137cd
parent850457028a92e73cfecf93996b99a7ee518ec4ef (diff)
parent11f08395072e420bf43fddc5ffc9ce41d1cb1107 (diff)
Auto merge of #158 - ajnirp:143-comment-get-tag-attr, r=emilio
143 comment get tag attr Fixes #143
-rwxr-xr-xsrc/clang.rs24
-rw-r--r--src/ir/annotations.rs17
2 files changed, 27 insertions, 14 deletions
diff --git a/src/clang.rs b/src/clang.rs
index c48b45d5..1bb219b0 100755
--- a/src/clang.rs
+++ b/src/clang.rs
@@ -825,17 +825,29 @@ impl Comment {
/// Given that this comment is an HTML start tag, get the `idx`th
/// attribute's name.
- pub fn get_tag_attr_name(&self, idx: c_uint) -> String {
- unsafe {
- String_ { x: clang_HTMLStartTag_getAttrName(self.x, idx) }.to_string()
+ pub fn get_tag_attr_name(&self, idx: c_uint) -> Option<String> {
+ if idx >= self.get_num_tag_attrs() {
+ None
+ } else {
+ unsafe {
+ Some(String_ {
+ x: clang_HTMLStartTag_getAttrName(self.x, idx)
+ }.to_string())
+ }
}
}
/// Given that this comment is an HTML start tag, get the `idx`th
/// attribute's value.
- pub fn get_tag_attr_value(&self, idx: c_uint) -> String {
- unsafe {
- String_ { x: clang_HTMLStartTag_getAttrValue(self.x, idx) }.to_string()
+ pub fn get_tag_attr_value(&self, idx: c_uint) -> Option<String> {
+ if idx >= self.get_num_tag_attrs() {
+ None
+ } else {
+ unsafe {
+ Some(String_ {
+ x: clang_HTMLStartTag_getAttrValue(self.x, idx)
+ }.to_string())
+ }
}
}
}
diff --git a/src/ir/annotations.rs b/src/ir/annotations.rs
index d276608f..9b141372 100644
--- a/src/ir/annotations.rs
+++ b/src/ir/annotations.rs
@@ -134,19 +134,20 @@ impl Annotations {
if comment.kind() == CXComment_HTMLStartTag &&
comment.get_tag_name() == "div" &&
comment.get_num_tag_attrs() > 1 &&
- comment.get_tag_attr_name(0) == "rustbindgen" {
+ comment.get_tag_attr_name(0).as_ref().map(|s| s.as_str())
+ == Some("rustbindgen") {
*matched = true;
for i in 0..comment.get_num_tag_attrs() {
- let value = comment.get_tag_attr_value(i);
- let name = comment.get_tag_attr_name(i);
- match name.as_str() {
+ let value_opt = comment.get_tag_attr_value(i);
+ match comment.get_tag_attr_name(i).unwrap().as_str() {
"opaque" => self.opaque = true,
"hide" => self.hide = true,
"nocopy" => self.disallow_copy = true,
- "replaces" => self.use_instead_of = Some(value),
- "private" => self.private_fields = Some(value != "false"),
- "accessor"
- => self.accessor_kind = Some(parse_accessor(&value)),
+ "replaces" => self.use_instead_of = value_opt,
+ "private" => self.private_fields = value_opt.map(|v|
+ v != "false"),
+ "accessor" => self.accessor_kind = value_opt.map(|v|
+ parse_accessor(&v)),
_ => {},
}
}