From b5db18e72322862883e6d0695e3e0cc5826f39c9 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 24 Feb 2009 15:43:49 -0500 Subject: ENH: Added cmXMLParser::FindAttribute method This method will help subclasses look for element attributes in their StartElement methods. --- Source/cmXMLParser.cxx | 17 +++++++++++++++++ Source/cmXMLParser.h | 3 +++ 2 files changed, 20 insertions(+) diff --git a/Source/cmXMLParser.cxx b/Source/cmXMLParser.cxx index 09cc384..0f68cb6 100644 --- a/Source/cmXMLParser.cxx +++ b/Source/cmXMLParser.cxx @@ -181,6 +181,23 @@ int cmXMLParser::IsSpace(char c) } //---------------------------------------------------------------------------- +const char* cmXMLParser::FindAttribute(const char** atts, + const char* attribute) +{ + if(atts && attribute) + { + for(const char** a = atts; *a && *(a+1); a += 2) + { + if(strcmp(*a, attribute) == 0) + { + return *(a+1); + } + } + } + return 0; +} + +//---------------------------------------------------------------------------- void cmXMLParserStartElement(void* parser, const char *name, const char **atts) { diff --git a/Source/cmXMLParser.h b/Source/cmXMLParser.h index 68def9e..80b0503 100644 --- a/Source/cmXMLParser.h +++ b/Source/cmXMLParser.h @@ -105,6 +105,9 @@ protected: //! Send the given c-style string to the XML parser. int ParseBuffer(const char* buffer); + /** Helps subclasses search for attributes on elements. */ + static const char* FindAttribute(const char** atts, const char* attribute); + //! Callbacks for the expat friend void cmXMLParserStartElement(void*, const char*, const char**); friend void cmXMLParserEndElement(void*, const char*); -- cgit v0.12