Line data Source code
1 : /* 2 : * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved. 3 : * Copyright Contributors to the OpenSDN project 4 : */ 5 : #ifndef __PARSER_UTIL__ 6 : #define __PARSER_UTIL__ 7 : #include <string> 8 : #include <set> 9 : #include <map> 10 : #include "base/regex.h" 11 : #include <pugixml/pugixml.hpp> 12 : 13 : class LineParser 14 : { 15 : public: 16 : 17 : typedef std::set<std::string> WordListType; 18 : 19 : static bool Parse(std::string s, WordListType *words); 20 : static bool ParseXML(const pugi::xml_node &node, WordListType *w, 21 : bool check_attr=true); 22 : static std::string GetXmlString(const pugi::xml_node node); 23 : static std::string MakeSane(const std::string &text); 24 : static unsigned int SearchPattern(const contrail::regex &exp, 25 : std::string text); 26 7 : static unsigned int SearchPattern(std::string exp, std::string text) { 27 7 : return SearchPattern(contrail::regex(exp, boost::regex::icase), text); } 28 : private: 29 : template <typename Iterator> 30 : static bool ParseDoc(Iterator start, Iterator end, 31 : LineParser::WordListType *pv); 32 : static bool Traverse(const pugi::xml_node &node, WordListType *words, 33 : bool check_attr=true); 34 : static bool GetAtrributes(const pugi::xml_node &node, WordListType *words); 35 : }; 36 : 37 : #endif //__PARSER_UTIL__