Home | History | Annotate | Download | only in test
      1 /*
      2  * Copyright 2011 Google Inc. All Rights Reserved.
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #include <map>
     18 #include <string>
     19 #include "test/test_xml_utils.h"
     20 #include "test/tinyxml/tinyxml.h"
     21 
     22 namespace sfntly {
     23 void InternalGetNodesWithName(const TiXmlNode* node, const std::string& name,
     24                               TiXmlNodeVector* wanted_nodes) {
     25   if (node->ValueStr() == name)
     26     wanted_nodes->push_back(node);
     27   for (const TiXmlNode* child = node->FirstChild();
     28        child != NULL; child = child->NextSibling()) {
     29     InternalGetNodesWithName(child, name, wanted_nodes);
     30   }
     31 }
     32 
     33 TiXmlNodeVector* GetNodesWithName(const TiXmlNode* node,
     34                                   const std::string& name) {
     35   TiXmlNodeVector* wanted_nodes = new TiXmlNodeVector;
     36   InternalGetNodesWithName(node, name, wanted_nodes);
     37   return wanted_nodes;
     38 }
     39 
     40 const TiXmlAttribute* GetAttribute(const TiXmlNode* node,
     41                                    const std::string& name) {
     42   for (const TiXmlAttribute* attribute = node->ToElement()->FirstAttribute();
     43        attribute != NULL; attribute = attribute->Next()) {
     44     if (attribute->Name() == name) {
     45       return attribute;
     46     }
     47   }
     48   return NULL;
     49 }
     50 }
     51