Skip to content

Commit

Permalink
Merge pull request leethomason#643 from leethomason/querystring
Browse files Browse the repository at this point in the history
QueryStringAttribute
  • Loading branch information
leethomason authored Jan 5, 2018
2 parents c859373 + 28f9a48 commit 703f91e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tinyxml2.h
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,17 @@ class TINYXML2_LIB XMLElement : public XMLNode
return a->QueryFloatValue( value );
}

/// See QueryIntAttribute()
XMLError QueryStringAttribute(const char* name, const char** value) const {
const XMLAttribute* a = FindAttribute(name);
if (!a) {
return XML_NO_ATTRIBUTE;
}
*value = a->Value();
return XML_SUCCESS;
}



/** Given an attribute name, QueryAttribute() returns
XML_SUCCESS, XML_WRONG_ATTRIBUTE_TYPE if the conversion
Expand Down
8 changes: 8 additions & 0 deletions xmltest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,14 @@ int main( int argc, const char ** argv )
XMLTest("Attribute: unsigned", (int)XML_SUCCESS, queryResult, true);
XMLTest("Attribute: unsigned", unsigned(100), v, true);
}
{
const char* v = "failed";
int queryResult = element->QueryStringAttribute("not-attrib", &v);
XMLTest("Attribute: string default", false, queryResult == XML_SUCCESS);
queryResult = element->QueryStringAttribute("attrib", &v);
XMLTest("Attribute: string", (int)XML_SUCCESS, queryResult, true);
XMLTest("Attribute: string", "100", v);
}
XMLTest("Attribute: unsigned", unsigned(100), element->UnsignedAttribute("attrib"), true);
}
{
Expand Down

0 comments on commit 703f91e

Please sign in to comment.