Skip to content

Commit

Permalink
Auto merge of #158 - ajnirp:143-comment-get-tag-attr, r=emilio
Browse files Browse the repository at this point in the history
143 comment get tag attr

Fixes #143
  • Loading branch information
bors-servo committed Oct 30, 2016
2 parents 1460787 + 6298736 commit 9db4d1f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
24 changes: 18 additions & 6 deletions src/clang.rs
Expand Up @@ -822,17 +822,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())
}
}
}
}
Expand Down
17 changes: 9 additions & 8 deletions src/ir/annotations.rs
Expand Up @@ -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)),
_ => {},
}
}
Expand Down

0 comments on commit 9db4d1f

Please sign in to comment.